Comment #21 on issue 2440 by smi...@gmail.com: Equal Integrals compare different when using different variables
http://code.google.com/p/sympy/issues/detail?id=2440

This is a repost from PR 3775:

Something that I think would be useful for addressing this issue is a "fold" or "fold_symbols" method that remaps symbols canonically as

```
def fold(i):
  all = list(uniq(i.variables + list(ordered(i.free_symbols))))
  reps = dict(zip(all, [Symbol('_%i' % i) for i in range(len(all))]))
  return i.xreplace(reps)
...
fold(Integral(x+y, (x, 1, 2)))
Integral(_0 + _1, (_0, 1, 2))
fold(Integral(x+y, (y, 1, 2)))
Integral(_0 + _1, (_0, 1, 2))

fold(Integral(x+y/2, (x, 1, 2)))
Integral(_0 + _1/2, (_0, 1, 2))
fold(Integral(x+y/2, (y, 1, 2)))
Integral(_0/2 + _1, (_0, 1, 2))

fold(Integral(x+Symbol('_0'), (x, 1, 2)))  # there will be no clash
Integral(_0 + _1, (_0, 1, 2))
```

So before computing the hashable content, a function could do `expr = self.fold_symbols` and then compute the hash. The Basic.fold_symbols would be

```
@property
def fold_symbols(self):
  all = list(ordered(self.atoms(Symbol)))
  reps = dict(zip(all, [Symbol('_%i' % i) for i in range(len(all))]))
  return self.xreplace(reps)
```

Methods that have their own bound symbols (like Lambda, Integral, Sum, Product, ...) would override this to put the bound symbols first in whatever order made sense.


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy-issues+unsubscr...@googlegroups.com.
To post to this group, send email to sympy-issues@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy-issues?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to