SymPy expressions reason about mathematics and generate numeric code.
from sympy import *
from sympy.abc import x, y, z
init_printing(use_latex='mathjax')
x + y
type(x + y)
sympy.core.add.Add
expr = sin(x)**2 + 2*cos(x)
expr
ccode(expr) # C
'pow(sin(x), 2) + 2*cos(x)'
fcode(expr) # Fortran
' sin(x)**2 + 2*cos(x)'
jscode(expr) # JavaScript
'Math.pow(Math.sin(x), 2) + 2*Math.cos(x)'
latex(expr) # Even LaTeX
'\\sin^{2}{\\left (x \\right )} + 2 \\cos{\\left (x \\right )}'
expr
expr.diff(x)
expr.diff(x).diff(x)
ccode(expr.diff(x).diff(x))
'-2*pow(sin(x), 2) + 2*pow(cos(x), 2) - 2*cos(x)'
expr.diff(x).diff(x)
simplify(expr.diff(x).diff(x))
ccode(simplify(expr.diff(x).diff(x))) # Faster code
'-2*cos(x) + 2*cos(2*x)'
We combine high-level reasoning with low-level code generation.
Blaze does the same thing, just swap out calculus and trig with relational and linear algebra.