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]> 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]>
> 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].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sympy/f0084d3b-db98-43cb-becd-020a368aec87%40googlegroups.com
>> <https://groups.google.com/d/msgid/sympy/f0084d3b-db98-43cb-becd-020a368aec87%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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/CAP7f1Ag-%3D%2BT2xX1frdphHhe8G6SBcWX1qvje1WVPNDHehU19Eg%40mail.gmail.com.