Comment #23 on issue 2552 by [email protected]: (1/(x*y)).subs(x*y, whatever) doesn't work
http://code.google.com/p/sympy/issues/detail?id=2552

I still do not understand it well with "the concepts are one and the same." (how the simplification, cancelation, hashes and the automatic conversion collaborate each with other in the core

It's because this is how the Mul.flatten routine works. It goes through each argument, and creates a dictionary of base:exp terms. So if you have x*y**2*z**3, it will create, iteratively, {x:1, y:2, z:3}. If it finds the same base, it will just add the exponents in the dictionary, so x*y*x will iteratively create {x:1}, {x:1, y:1}, and {x:2, y:1}. Hashing comes into play here because dictionary keys are compared by hash. If you have x*y/x, it creates first {x:1, y:1}, and then {x:1 - 1, y:1} == {x:0, y:1} (at the end, items with 0 exponent are automatically removed).

Note that this is actually a simplification of what happens in Mul.flatten. What actually happens is that you have base:{term:coeff} items, where {term:coeff} means it is a dictionary of terms and coefficients, like of an Add. But the key point is the same, which is that the base of the power is used as the key, so hash comparison is what allows cancelation to happen.

== equality testing doesn't actually use the hash (as far as I remember), but it compares the exact same things that the hash is built from, so they are essentially the same (with some low probability of being different).

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en.

Reply via email to