On Sat, Jun 23, 2012 at 4:54 PM, [email protected]
<[email protected]> wrote:
>> It is however important that FiniteSet(!,2) == FiniteSet(2,1)
> But this is already implemented in frozenset, so we should not worry about it.

This is partially true.

In this pull request I disable the implicit sorting of FiniteSet's:

https://github.com/sympy/sympy/pull/1380

It turns out that, while FiniteSet(1, 2) == FiniteSet(2, 1) solely
because of the use of frozenset, there are situations where this does
not hold, at it happens, for example, in sympy/stats/tests/test_rv.py,
namely, in:

  X, Y = Normal('X', 0, 1), Normal('Y', 0, 1)
  assert pspace(2*X+Y) == ProductPSpace(Y.pspace, X.pspace)

If special measures are not taken, the two parts of the comparison
generate two FiniteSet's from something1 and something2, with .args of
one FiniteSet being (something1, something2), while .args of the other
FiniteSet being (something2, something1), and the two FiniteSet's are
therefore unequal.  I am not sure this is reproducible on a different
machine, but it did occur all the time for me, without exception.

Further, FiniteSet._complement needs the elements of the FiniteSet to
be sorted, so it has to explicitly sort all the time.

This made me scratch my head performance-wise.  It occurred to me
that, while an implementation of a finite set should not guarantee any
order of its elements, there is nothing wrong with it actually sorting
its content in a way, especially if this allows for better performance
in some cases.

Therefore, I decided to try this:

https://github.com/sympy/sympy/pull/1381

which makes FiniteSet use sympy.utilities.misc.default_sort_key,
removes the unnecessary element_sort_fn and therefore the faulty
doctest.  This pull request also removes the sorting of FiniteSet's
from pretty.py.

I think using default_sort_key was what Matthew mentioned once.  It
was sheer absent-mindedness on my side to have ignored that suggestion
to have kept element_sort_fn, which has created a bit of a mess in the
code.  I am therefore publicly begging my pardon for that.

Please note that the two pull requests I link to in this E-mail are
*mutually exclusive*.  (That's partly obvious, but I guess it's never
a bad idea to state things explicitly.)

Also, both pull request should fix the doctest failures, from what I
understand.  Looking forward to seeing Stefan's automated SymPy-bot
check that.

Sergiu

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