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] <javascript:>>
> 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]
> <javascript:>.
> > To unsubscribe from this group, send email to
> [email protected] <javascript:>.
> > 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/09c3fbc5-1746-4ff3-9f81-0171a65849e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.