In the next version of SymPy str(Eq(x, y)) will give 'Eq(x, y)'. Aaron Meurer
On Fri, May 29, 2015 at 5:21 AM, Robert <[email protected]> wrote: > I was able to write a LambdaPrinter that does what I want for the time > being: > > > class NonRelationalOpPrinter(lambdarepr.LambdaPrinter): > > ''' > >>> from structures import symbolic > >>> for op in ['Eq', 'Ne', 'Gt', 'Lt', 'Ge', 'Le']: > ... > sympy.sympify((symbolic.NonRelationalOpPrinter().doprint(sympy.sympify('%s(%s(a, > b), c)' % (op, op))))) > (a == b) == c > (a != b) != c > (a > b) > c > (a < b) < c > (a >= b) >= c > (a <= b) <= c > ''' > > def _printRelation(self, expr, name): > return '%s(%s)' % (name, ", ".join(map(self._print, expr.args))) > > def _print_Equality(self, expr): > return self._printRelation(expr, 'Equality') > > def _print_Unequality(self, expr): > return self._printRelation(expr, 'Unequality') > > def _print_GreaterThan(self, expr): > return self._printRelation(expr, 'GreaterThan') > > def _print_LessThan(self, expr): > return self._printRelation(expr, 'LessThan') > > def _print_StrictGreaterThan(self, expr): > return self._printRelation(expr, 'StrictGreaterThan') > > def _print_StrictLessThan(self, expr): > return self._printRelation(expr, 'StrictLessThan') > > > > On Friday, May 29, 2015 at 4:31:59 AM UTC-5, Robert wrote: >> >> Hello, >> >> Thanks for the help previously. I've run into a different issue with >> regards to Eq. >> >> Sympify will automatically convert Eq into == >> >>> sympy.sympify('Eq(a, b)') >> a == b >> >> which if you sympify again will have the behavior you described >> originally. >> >>> sympy.sympify(str(sympy.sympify('Eq(a, b)'))) >> False >> >> Do you know of any way to stop the converion of Eq to ==? >> >> Thanks, >> Rob >> >> >> >> On Friday, April 27, 2012 at 5:29:53 PM UTC-5, Aaron Meurer wrote: >>> >>> Equal is not anything. You've just created an undefined function >>> called Equal (Function('Equal')) with that sympify command. >>> >>> What you are probably looking for is Eq() (or Equality()). This >>> creates a symbolic equality. You can manipulate different sides of >>> the equation using Eq.lhs and Eq.rhs, like >>> >>> In [496]: Eq(x, y) >>> Out[496]: x = y >>> >>> In [497]: Eq(x, y).lhs >>> Out[497]: x >>> >>> In [498]: Eq(x, y).rhs >>> Out[498]: y >>> >>> Eq() will reduce to True when or False when it can see that the >>> expressions are always equal or unequal: >>> >>> In [504]: Eq(x, y).subs({x: 1, y: 1}) >>> Out[504]: True >>> >>> In [505]: Eq(x, y).subs({x: 1, y: 2}) >>> Out[505]: False >>> >>> == is a lot different. This is used to exactly compare expressions. >>> a == b will be a boolean, True if a and be are exactly equal and False >>> otherwise. I say "exactly" equal because == does structural >>> comparison, not mathematical comparison. So we have >>> >>> In [499]: x*(y + z) == x*y + x*z >>> Out[499]: False >>> >>> In [500]: x*(y + z) == x*(y + z) >>> Out[500]: True >>> >>> If you want to do a mathematical comparison, the best way is to >>> subtract one expression from the other and pass it to simplify(), and >>> see if it goes to 0. For example: >>> >>> In [501]: a = x*(y + z) >>> >>> In [502]: b = x*y + x*z >>> >>> In [503]: simplify(a - b) >>> Out[503]: 0 >>> >>> See http://docs.sympy.org/dev/gotchas.html#equals-signs for more >>> discussion on this. >>> >>> Aaron Meurer >>> >>> On Fri, Apr 27, 2012 at 4:16 PM, Robert <[email protected]> wrote: >>> > Hello, >>> > >>> > I have a question about == and Equal in sympy. >>> > >>> > Their behavior is strange to me. >>> > >>> > In [108]: expr = sympy.simplify('Equal(A,B)') >>> > In [111]: expr.subs(dict(A=1, B=1)) >>> > Equal(1, 1) >>> > >>> > In [112]: expr = sympy.simplify('A==B') >>> > In [113]: expr >>> > False >>> > >>> > In [115]: A = sympy.Symbol('A') >>> > In [116]: B = sympy.Symbol('B') >>> > >>> > In [117]: A==B >>> > False >>> > >>> > In [118]: sympy.__version__ >>> > '0.7.1' >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> > Groups "sympy" group. >>> > To post to this group, send email to [email protected]. >>> > To unsubscribe from this group, send email to >>> > [email protected]. >>> > For more options, visit this group at >>> > http://groups.google.com/group/sympy?hl=en. >>> > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/db78709d-2af8-426a-968a-20434f211058%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" 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. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B5guvv3_ptAo_4KNM-oSV0YRTB5NzcRo4bfk8w6Ok5ag%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
