But it is better thought of as a tensor library that can:
compile to multiple backends (jax, numba, etc)
convert mathematical expressions into graphs which can be optimised through graph rewrites.
graph rewrites
PyTensor takes a generative graph representation to and compiles to an optimised graph. This allows us to write the maths as we see it, and allow the rewrites to optimise for computational stability and efficiency.
Here is an example with a pointless log-exp statement. The generative graph looks like
When we compile the graph, we get
where the log-exp has been removed and the pow(x, -0.5) has been replaced with a 1/sqrt(x) (probably for stability).
logp PyMC model
A particular case of rewrites are in PyMC in evaluating logp. PyMC distributions are written in a single cannoncial form. For example, regardless of whether the user specifies cov, chol, or tau in pm.Normal(), PyMC will always convert to chol for logp evaluation, before PyTensor optimises the graph.
For an example PyMC model, the generative graph for logp:
And after optimisation
where, amongst other rewrites, the term log(sqrt(c)) has now become a constant throughout all logp evaluations.