Thank you, but I don't need help debugging my code; I had a typo which
boiled down to the example I gave. My only question was whether this was
intended behaviour.
Please note the deliberate mistake of "y = Symbol('x')", which you may have
missed when interpreting my question. True is returned for both "x == y"
and "x is y" in SymPy 1.2 (local installation) and SymPy 1.5.1
(http://live.sympy.org).
On Wednesday, June 3, 2020 at 9:55:01 PM UTC+1, Aaron Meurer wrote:
>
> You'll need to give more details on what your code is doing. The code
> you posted works as expected. Both x == y and x is y should be False
> because Symbols compare by name. It is possible the bug is in your own
> code somewhere, as it would be difficult for y to "become" x exactly,
> but it is also possible you stumbled on a bug in SymPy itself. Without
> an example that reproduces the issue, it is impossible to say.
>
> Aaron Meurer
>
> On Wed, Jun 3, 2020 at 2:09 PM Jason Moore <[email protected]
> <javascript:>> wrote:
> >
> > Actually, I don't think your code is valid. You create two distinctly
> different symbols:
> >
> > In [1]: import sympy as sm
> >
> > In [2]: x = sm.Symbol('x')
> >
> > In [3]: y = sm.Symbol('y')
> >
> > In [4]: x == y
> > Out[4]: False
> >
> > In [5]: x is y
> > Out[5]: False
> >
> > In [6]: x + y
> > Out[6]: x + y
> >
> > Jason
> > moorepants.info
> > +01 530-601-9791
> >
> >
> > On Wed, Jun 3, 2020 at 1:06 PM Jason Moore <[email protected]
> <javascript:>> wrote:
> >>
> >> Yes, this is intentional. It is really no different than this:
> >>
> >> In [1]: a = 1
> >>
> >> In [2]: b = 1
> >>
> >> In [3]: type(a)
> >> Out[3]: int
> >>
> >> In [4]: type(b)
> >> Out[4]: int
> >>
> >> In [5]: a == b
> >> Out[5]: True
> >>
> >> In [6]: a is b
> >> Out[6]: True
> >>
> >> Jason
> >> moorepants.info
> >> +01 530-601-9791
> >>
> >>
> >> On Wed, Jun 3, 2020 at 12:53 PM James Bateman <[email protected]
> <javascript:>> wrote:
> >>>
> >>> I've just discovered a bug in my code which boiled down to the
> following, where a symbol "y" was given the same SymPy name as an existing
> symbol.
> >>>
> >>> import sympy as sp
> >>> x = sp.Symbol('x')
> >>> y = sp.Symbol('y')
> >>>
> >>> x == y # True
> >>> x is y # True; expected False
> >>> x + y # 2*x; expected x + x (which would have made the bug in my code
> more apparent)
> >>>
> >>> The behaviour here is very surprising to me. I would have expected x
> and y to be different Python objects with __repr__ methods which just so
> happen to return the same string. Instead, x and y are apparently
> different Python names for the same object (x is y).
> >>>
> >>> Is this intentional? I think I must misunderstand some deep design
> choice in SymPy, and I can't express my confusion well enough to Google it.
> Please help!
> >>>
> >>>
> >>> --
> >>> 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] <javascript:>.
> >>> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/f0084d3b-db98-43cb-becd-020a368aec87%40googlegroups.com.
>
>
> >
> > --
> > 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] <javascript:>.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAP7f1Ag-%3D%2BT2xX1frdphHhe8G6SBcWX1qvje1WVPNDHehU19Eg%40mail.gmail.com.
>
>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/183785ef-68e9-4650-9afd-1af578e4edf3%40googlegroups.com.