i mentioned that sorting of args will not work here.
Consider below example,
k1=Add([x+y,-z],evaluate=False)
 k2=Add([x-z,y],evaluate=False)

in this case k1.args are (x+y,-z) and k2.args are (x-z,y) .
So sorting here will not improve the result.
also if i use flatten method of this class than it sums up the common
terms(against the evaluate=False)

Is there any way to bypass this issue ?

On Thu, Nov 10, 2011 at 8:16 PM, Chris Smith <[email protected]> wrote:

> 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.
>
>

-- 
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