inducer / pymbolic

A simple package to do symbolic math (focus on code gen and DSLs)
http://mathema.tician.de/software/pymbolic
Other
106 stars 25 forks source link

EvaluationMapper can't handle math functions #85

Closed avedmala closed 2 years ago

avedmala commented 2 years ago

Currently, the DifferentiationMapper can handle functions like math.cos or math.log.

import pymbolic as pmbl

x = pmbl.var("x")
u = pmbl.parse("math.cos(x)")

pmbl.differentiate(u, x)

The code block above works and it gives me -sin(x) as a result. However, EvaluationMapper cannot handle these functions. Is there a reason for not having this functionality? Would this be easy to extend on my own?

inducer commented 2 years ago

Saw that you closed this right away. I hope the solution you discovered is what I would have recommended: Pass in math (as in, Python's math module) through the context argument in evaluation. The reason why this isn't built in is because you might like to choose other ways of evaluating, such as using numpy (or another numpy-work-alike, like Jax).