If I remember correctly, this issue stems from subclassing Symbol,
which has empty args and specific eq.

On 28 August 2013 15:13, Gilbert Gede <[email protected]> wrote:
> Prasoon,
> Take a look at these outputs.
>
> In [5]: cs.theta.args
> Out[5]: ()
>
> In [7]: cs.theta._hashable_content()
> Out[7]: ()
>
> cs.theta.__eq__ uses Basic's .__eq__, which in turn compares
> _hashable_content() between the two objects. So, I think you should be using
> .args instead of .coord_sys and .position.
>
>
> On Wed, Aug 28, 2013 at 11:22 AM, Prasoon Shukla <[email protected]>
> wrote:
>>
>> You're right. It seems to be a problem with equality checking. Here's some
>> code that I just ran:
>>
>> In [3]: cs.theta == cs.phi
>> Out[3]: True
>>
>> In [4]: cs.theta
>> Out[4]: cs.theta
>>
>> In [5]: cs.phi
>> Out[5]: cs.phi
>>
>> In [6]: id(cs.theta)
>> Out[6]: 169351684
>>
>> In [7]: id(cs.phi)
>> Out[7]: 169350004
>>
>> How come the == operator returns True even though the ids are different?
>> Also, I didn't implement __eq__ or __hash__ on BaseScalars.
>>
>> Anyway, to reproduce the problem, you can run this (I'm just pasting from
>> my Ipython session):
>>
>> In [1]: from sympy import *;from sympy.vector.vector import *;from
>> sympy.vector.integrate import *;q0, q1, q2 = symbols('q0 q1 q2');from
>> sympy.abc import x, y, z;c0 = CoordSysRect('c0');c1 = CoordSysRect('c1');cs
>> = CoordSysSph('cs')
>>
>> In [2]: cs.theta * cs.phi
>> Out[2]: cs.theta**2
>>
>> Should I implement __eq__ on BaseScalar?
>> (I probably won't be able to respond for 7-8 hours. Going to sleep. Have
>> classes tomorrow morning).
>>
>> On Wednesday, August 28, 2013 10:17:39 PM UTC+5:30, Aaron Meurer wrote:
>>>
>>> On Wed, Aug 28, 2013 at 7:29 AM, Prasoon Shukla
>>> <[email protected]> wrote:
>>> > I have ran into a caching problem while working on my project for the
>>> > vector
>>> > calcculus module. This occurred while I was debugging the express
>>> > method on
>>> > vector (this isn't really relevant though).
>>> >
>>> > So, I have a symbol theta and another symbol phi.
>>> >
>>> >>>> cs.theta
>>> > cs.theta
>>> >
>>> >>>> cs.phi
>>> > cs.phi
>>> >
>>> > cs is an instance of the CoordSysSph class (again, not really relevant
>>> > to
>>> > the problem at hand).
>>> >
>>> > The problem:
>>> >>>> sin(cs.theta) * sin(cs.phi)
>>> > sin(cs.theta) ** 2
>>> >
>>> > Well, in the definition for the cacheit decorator, the dicitionary
>>> > func_cache_it_cache exists. Now, when sin(cs.theta) is called, a key,
>>> > value
>>> > pair gets added to the dictionary:
>>> >
>>> > ((sin, <class 'sympy.core.function.FunctionClass'>), (cs.theta, <class
>>> > 'sympy.vector.vector.BaseScalar'>))  : sin(cs.theta)
>>> >
>>> > Now, when SymPy needs to calculate sin(cs.phi), the cacheit decorator
>>> > is
>>> > called again. The lookup key for sin(cs.phi) is generated as:
>>> > ((sin, <class 'sympy.core.function.FunctionClass'>), (cs.phi, <class
>>> > 'sympy.vector.vector.BaseScalar'>))
>>>
>>> Oh, just noticed this. phi and theta are not Symbols, they are
>>> BaseScalars. So you probably did something wrong implementing equality
>>> comparison on BaseScalars. What does "cs.phi == cs.theta" give?
>>>
>>> Can you give a complete code snipped to reproduce this in your branch?
>>>
>>> Aaron Meurer
>>>
>>> >
>>> > At this point, the func_cache_it_cache does not have the key
>>> > correspondind
>>> > to sin(cs.phi), as it shouldn't. But, here's the catch: running the
>>> > has_key
>>> > method on func_cache_it_cache for this second key (for sin(cs.phi))
>>> > returns
>>> > True. That means, the cache returns sin(cs.theta). And that is what is
>>> > causing the problem.
>>> >
>>> > What can I possibly do here? For the time being, I am going to proceed
>>> > with
>>> > the debugging. When there is a solution for this problem, we can go
>>> > ahead
>>> > and fix this.
>>> >
>>> > --
>>> > 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.
>>> > For more options, visit https://groups.google.com/groups/opt_out.
>>
>> --
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to