Comment #16 on issue 1932 by [email protected]: Relationals do not work with any methods of Expr
http://code.google.com/p/sympy/issues/detail?id=1932

Here's a little hack that can be applied to be able to manipulate the sides of a Relational: the `do` method will apply the template given to each side of the expression, so `do(i+3)` will add 3 to each side of the equation. This is in lieu of modifying Relational to respond side-wise (or in a vectorized fashion) to any operation.

def applyfunc(self, f):
...     return self.func(*[f(a) for a in self.args])
...
def do(self, e, i=None):
...     i = S(e).free_symbols - self.free_symbols
...     if len(i) != 1:
...         raise ValueError('expecting a variable to represent a side')
...     i = i.pop()
...     return self.applyfunc(lambda side: e.subs(i, side))
...
from sympy.core.relational import Relational
Relational.applyfunc = applyfunc
Relational.do = do
Lt(x, 2*y - 4)
x < 2*y - 4
_.do(i-_.rhs)
x - 2*y + 4 < 0
_.do(i-4-x)
-2*y < -x - 4
_.do(i/-2)
y < x/2 + 2
_.do(sin(i))
sin(y) < sin(x/2 + 2)

If you want to apply a function to both sides then applyfunc can be used:

Eq(x+3,x*(1+3/x))
x + 3 == x*(1 + 3/x)
_.applyfunc(expand)
True
Eq(x,x*(x+y))
x == x*(x + y)
_.applyfunc(expand)
x == x**2 + x*y


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy-issues.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to