pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Define database for symbolic simplification

Open ricardoV94 opened this issue 1 year ago • 3 comments

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

ricardoV94 avatar Feb 08 '24 10:02 ricardoV94

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?

jessegrabowski avatar Feb 08 '24 12:02 jessegrabowski

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.

ricardoV94 avatar Feb 08 '24 12:02 ricardoV94

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.

jessegrabowski avatar Feb 08 '24 12:02 jessegrabowski