I would just pass the object through to the function, like
expr.rewrite(expr2) calls
expr._eval_rewrite(expr2)
except it should still prefer the existing API if a method matches.
This way, the function can do whatever dispatching is necessary.
Another thing to think about for this is that some of the existing
rewrite methods are not as expressive as they could be. Consider for
example trig functions. There are several different ways to rewrite
one trig function in terms of another. For example, sin(x) = cos(pi/2
- x) = sqrt(1 - cos(x)**2) = 2*sin(x/2)*cos(x/2) and so on. Right now
sin(x).rewrite(cos) gives cos(x - pi/2), but the other forms could be
useful depending on the context. Is there some way we could design the
API to make it easy for people to pick which form they want to rewrite
to (without having to explicitly remember the identities, which they
could just do manually with replace()).
Aaron Meurer
> To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/d2661899-3c47-4523-8a58-29bd36048fddn%40googlegroups.com.