pymc-devs / pytensor

PyTensor allows you to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays.
https://pytensor.readthedocs.io
Other
338 stars 100 forks source link

Define database for symbolic simplification #639

Open ricardoV94 opened 7 months ago

ricardoV94 commented 7 months ago

Description

As discussed in https://github.com/pymc-devs/pytensor/discussions/637 PyTensor is geared mostly towards computational efficiency, although the same machinery could be easily tuned for symbolic simplification.

We could create a database of rewrites just for that goal

jessegrabowski commented 7 months ago

This was something on the Theano team's radar, I think at least one of the original devs was interested in piggy-backing on sympy for this purpose. See this blog post, for example.

I also think this is a place where Eggs could really shine. See their symbolic algebra example here, it might be a good place to start?

ricardoV94 commented 7 months ago

I would say easiest place to start is to just curate from the rewrites we already have. After that I'm confident egglog could be nice for better simplifications.

Given how easy it is to write egglog rewrites I would lean to bypass sympy completely.

jessegrabowski commented 7 months ago

Yes, I don't like adding a sympy dependency either. It's non-trivial to switch between representations (sympy and pytensor), mostly because of broadcasting stuff. From my own experience, it would be easier to just start fresh on our side.

This does tie into the discussion we were having on #573 though, because algebraic rewrites might need more information about variables in order to execute. For example, $(x^a)^{\frac{1}{a}}$ can be rewritten to $x$, but only if we know x is non-negative.