On Thu, Nov 10, 2011 at 6:45 PM, gsagrawal <[email protected]> wrote:
> Hi,
> In my project i have to use evaluate=false at the time when i am creating
> any Add or Mul Class object.In this case i am facing the problem when i
> apply equality check on these object. this issue is because of ordering of
> arguments.
> Please consider below example
>  > k2=Mul(*[x,y,2],evaluate=False)
>   > k1=Mul(*[x,2,y],evaluate=False)
>  >print k1==k2
> result in false
> as k2.args are (x,y,2) and k1.args are (x,2,y)
> so while comparison as  it checks for tuple equality it returns false .
> Is there any way i can get the wanted result ?
> Also ,if i put some operation on tuples (like reversed the order and than
> check ) it fails in the cases when k1 and k2 are formed from different Mul
> Objects (like when k1.args = 2*x,y and k2.args=2*y,x)
> Please suggest some way
> Thanks

Issue 2805 identifies this as a potential change to sympy. In the mean
time, for your own equality testing purposes, consider hash-sorting
your args:

>>> args =  [x,y,2] # must be a list to use sort method
>>> args.sort(key=hash)
>>> Mul(*args, evaluate=False)
2*x*y
>>> _.args
(2, y, x)

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to