Re: [sympy] Re: Simplification Not Removing Multiplication by 1.0

2020-06-03 Thread Chris Smith
> it does seem reasonable to me that simplify(1.0*x) Isn't this what `nsimplfy` (especially with rational=True) is for? On Monday, June 1, 2020 at 6:19:46 PM UTC-5, Aaron Meurer wrote: > > There is some discussion about this behavior here and in linked issues >

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread James Bateman
Thank you. This has been extremely helpful. Sorry once again for posting the wrong code initially. On Wed, 3 Jun 2020, 23:57 Aaron Meurer, wrote: > On Wed, Jun 3, 2020 at 4:55 PM Aaron Meurer wrote: > > > > So the issue here is that SymPy uses an internal cache, which means > > that sometimes

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Aaron Meurer
On Wed, Jun 3, 2020 at 4:55 PM Aaron Meurer wrote: > > So the issue here is that SymPy uses an internal cache, which means > that sometimes two equal objects will also be equal in memory. The > second time you called Symbol, the first Symbol('x') was found in the > cache and returned. This keeps

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Aaron Meurer
So the issue here is that SymPy uses an internal cache, which means that sometimes two equal objects will also be equal in memory. The second time you called Symbol, the first Symbol('x') was found in the cache and returned. This keeps only one Symbol('x') object in memory at a time. Jason's

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread James Bateman
Looks like I did indeed miss the deliberate mistake. Sorry for being an idiot and thank you for taking the time. For clarity, here is what I intended to post: import sympy as sp x = sp.Symbol('x') y = sp.Symbol('x') # deliberate mistake here x == y # True x is y # True I'm aware of Python

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Oscar Benjamin
>> >> On Wed, Jun 3, 2020 at 12:53 PM James Bateman 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') >>

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread James Bateman
Please note the deliberate mistake of "y = Symbol('x')", which you may have missed when interpreting my question. You have corrected this deliberate mistake in your answer. My code was valid (it ran and gave the results I quoted) and highlighted what was, to me, a surprising behaviour. As to

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread James Bateman
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

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Aaron Meurer
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

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Jason Moore
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

Re: [sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread Jason Moore
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

[sympy] SymPy and Python names: Symbol('x') is Symbol('x') ?

2020-06-03 Thread James Bateman
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