Hello,

Sorry for the large delays between my messages in this thread.

I will remind the gist of the problem.  I currently have the need to
have a collection of FiniteSet's.  ~1 month ago, FiniteSet stopped
sorting its elements at creation, which means that the ordering of
FiniteSet.args is hash-dependent.  The structure of the sort key is
dependent on the order of .args, and is thus hash-dependent.  This
means that, if one has a container with FiniteSet's, their order in
the container is _hash-dependent_, even if one tries to explicitly
sort the container according to FiniteSet.sort_key.

On Tue, Jul 10, 2012 at 6:39 PM, Sergiu Ivanov
<unlimitedscol...@gmail.com> wrote:
> On Tue, Jul 10, 2012 at 6:10 PM, Chris Smith <smi...@gmail.com> wrote:
>>
>> I modified pre and post order traversals to use a sort key (so the
>> incoming expression doesn't have to have args presorted). Would this
>> help? I no longer have a pull request with it because I haven't solved
>> the solve and cse randomization failures, but if you want to pull off
>> that single commit it is in my rand branch.
>
> I must confess I don't know what you refer to when you say "pre and
> post order traversals" (I mean, I'm not sure what exactly it's about
> in SymPy), but I'll check out your modifications later today and see
> whether that helps.

Yes, your change would help, but as I can see in
sympy.core.basic.preorder_traversal, the independence of the order of
args is assured by sorting them.  Using preorder_traversal to make the
sort key hash independent is therefore worse than just sorting the
.args of the FiniteSet, because it involves sorting _and_ additional
effort.

Therefore, there are still only two solutions on the table to have
FiniteSet produce consistent sort keys:

1. have FiniteSet sort its .args at creation;

2. sort the FiniteSet every time a sort_key is needed.

I believe that, compared to the other drawbacks of having FiniteSet
not sort its .args at creation, this one is decisive.  Apparently, not
sorting .args with performance in mind impacts performance even worse.

Are there any counter-arguments to making FiniteSet sort its arguments
at creation again?

Sergiu

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

Reply via email to