On 04/06/2020 00:04, James Bateman wrote:
Thank you. This has been extremely helpful. Sorry once again for
posting the wrong code initially.
James,
I found the creation of symbols in SymPy incredibly confusing and
counter-intuitive - it was almost spoiling my enjoyment of using the
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
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
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
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
>> >> 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')
>>
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
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
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
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
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
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
12 matches
Mail list logo