Comment #18 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):
if isinstance(e, (FunctionClass, Lambda, type(lambda:1))):
return self.applyfunc(e)
e = S(e)
i = 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)
That last step can be done by simply passing the function, too:
e=Eq(2*x+4, 5)
e.do(sin)
sin(2*x + 4) == sin(5)
--
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.