Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-29 Thread Sergiu Ivanov
Sorry for the delay. On Thu, Jul 26, 2012 at 10:04 PM, Ronan Lamy wrote: > Le mardi 24 juillet 2012 à 18:44 +0300, Sergiu Ivanov a écrit : >> On Mon, Jul 23, 2012 at 9:51 PM, Tom Bachmann wrote: >> > >> > I'm sorry, I know I'm somewhat late to the party, and replying at this >> > position in the

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-26 Thread Ronan Lamy
Le mardi 24 juillet 2012 à 18:37 +0300, Sergiu Ivanov a écrit : > On Mon, Jul 23, 2012 at 9:52 PM, Aaron Meurer wrote: > > On Jul 23, 2012, at 12:33 PM, Sergiu Ivanov > > wrote: > > > >> On Mon, Jul 23, 2012 at 9:17 PM, Aaron Meurer wrote: > >>> On Jul 23, 2012, at 2:20 AM, Sergiu Ivanov > >>

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-26 Thread Ronan Lamy
Le mardi 24 juillet 2012 à 18:44 +0300, Sergiu Ivanov a écrit : > On Mon, Jul 23, 2012 at 9:51 PM, Tom Bachmann wrote: > > > > I'm sorry, I know I'm somewhat late to the party, and replying at this > > position in the thread is rather arbitrary, but how about the following: > > > > 1) don't sort .

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-24 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 9:51 PM, Tom Bachmann wrote: > > I'm sorry, I know I'm somewhat late to the party, and replying at this > position in the thread is rather arbitrary, but how about the following: > > 1) don't sort .args at creation time (ronan has made good arguments for >this, imho) >

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-24 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 9:52 PM, Aaron Meurer wrote: > On Jul 23, 2012, at 12:33 PM, Sergiu Ivanov > wrote: > >> On Mon, Jul 23, 2012 at 9:17 PM, Aaron Meurer wrote: >>> On Jul 23, 2012, at 2:20 AM, Sergiu Ivanov >>> wrote: >>> On Sun, Jul 22, 2012 at 11:44 PM, Aaron Meurer wrote: >

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Aaron Meurer
On Jul 23, 2012, at 12:33 PM, Sergiu Ivanov wrote: > On Mon, Jul 23, 2012 at 9:17 PM, Aaron Meurer wrote: >> On Jul 23, 2012, at 2:20 AM, Sergiu Ivanov >> wrote: >> >>> On Sun, Jul 22, 2012 at 11:44 PM, Aaron Meurer wrote: Can you be more specific? Most likely, one of the results i

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Tom Bachmann
I'm sorry, I know I'm somewhat late to the party, and replying at this position in the thread is rather arbitrary, but how about the following: 1) don't sort .args at creation time (ronan has made good arguments for this, imho) 2) add a property .sorted_args to FiniteSet This could just re

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 9:17 PM, Aaron Meurer wrote: > On Jul 23, 2012, at 2:20 AM, Sergiu Ivanov wrote: > >> On Sun, Jul 22, 2012 at 11:44 PM, Aaron Meurer wrote: >>> >>> Can you be more specific? Most likely, one of the results is "better" >>> than the other, and the algorithm should be fixed

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 9:15 PM, Aaron Meurer wrote: > > Maybe I'm missing something, but wouldn't the laziness only have to > apply to the sort_key, not .args (which probably could be left > unsorted)? Unlike .args, the sort_key doesn't have to be created at > instantiation time (and in fact won'

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 9:10 PM, Joachim Durchholz wrote: > Am 22.07.2012 22:07, schrieb Sergiu Ivanov: > >> Now, I do admit that not every use case of FiniteSet implies storing >> it in a container. Therefore, perhaps, we could go with a lazy >> approach: don't sort .args at FiniteSet creation;

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Aaron Meurer
On Jul 23, 2012, at 2:20 AM, Sergiu Ivanov wrote: > On Sun, Jul 22, 2012 at 11:44 PM, Aaron Meurer wrote: >> On Jul 10, 2012, at 9:39 AM, Sergiu Ivanov >> wrote: >> >>> On Tue, Jul 10, 2012 at 6:10 PM, Chris Smith wrote: Other than printing, what are these situations? Perhaps there

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Aaron Meurer
Maybe I'm missing something, but wouldn't the laziness only have to apply to the sort_key, not .args (which probably could be left unsorted)? Unlike .args, the sort_key doesn't have to be created at instantiation time (and in fact won't be because it's a property, so you'd just have to cache it).

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Joachim Durchholz
Am 22.07.2012 22:07, schrieb Sergiu Ivanov: Now, I do admit that not every use case of FiniteSet implies storing it in a container. Therefore, perhaps, we could go with a lazy approach: don't sort .args at FiniteSet creation; however, whenever a certain order of .args is required, sort it and le

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 6:36 PM, Ronan Lamy wrote: > Le dimanche 22 juillet 2012 à 23:07 +0300, Sergiu Ivanov a écrit : >> >> Currently, FiniteSet stores a non-.args frozenset attribute which is >> used exactly for this purposes. Thus, no matter whether one sorts >> .args or not, membership testi

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Ronan Lamy
Le dimanche 22 juillet 2012 à 23:07 +0300, Sergiu Ivanov a écrit : > On Sun, Jul 22, 2012 at 10:45 PM, Ronan Lamy wrote: > > Le dimanche 22 juillet 2012 à 17:55 +0300, Sergiu Ivanov a écrit : > >> > >> Therefore, there are still only two solutions on the table to have > >> FiniteSet produce consis

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 8:18 AM, Joachim Durchholz wrote: > Am 23.07.2012 01:56, schrieb Matthew Rocklin: > >> I am +1 to sorting args on creation. >> >> This is a simple and exhaustive fix. > > > Sounds good to me if no args can be added after creation anymore. FiniteSet derives from Basic and i

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Mon, Jul 23, 2012 at 2:56 AM, Matthew Rocklin wrote: > > I am +1 to sorting args on creation. > > This is a simple and exhaustive fix. Agreed. > I think that FiniteSet is usually used for small sets and that sorting isn't > that expensive even for large ones. I think that this discussion is >

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-23 Thread Sergiu Ivanov
On Sun, Jul 22, 2012 at 11:44 PM, Aaron Meurer wrote: > On Jul 10, 2012, at 9:39 AM, Sergiu Ivanov wrote: > >> On Tue, Jul 10, 2012 at 6:10 PM, Chris Smith wrote: >>> >>> Other than printing, what are these situations? Perhaps there is a >>> non-sorting way to solve the problem. >> >> Aside from

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Joachim Durchholz
Am 23.07.2012 01:56, schrieb Matthew Rocklin: I am +1 to sorting args on creation. This is a simple and exhaustive fix. Sounds good to me if no args can be added after creation anymore. Beats trying to keep up with changing args, anyway. The ban on arg creation should probably be documented i

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Matthew Rocklin
I am +1 to sorting args on creation. This is a simple and exhaustive fix. I think that FiniteSet is usually used for small sets and that sorting isn't that expensive even for large ones. I think that this discussion is premature optimization. If a use case arises that requires very large FiniteSe

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Aaron Meurer
On Jul 10, 2012, at 9:39 AM, Sergiu Ivanov wrote: > On Tue, Jul 10, 2012 at 6:10 PM, Chris Smith wrote: >> On Tue, Jul 10, 2012 at 9:55 AM, Sergiu Ivanov >> wrote: >>> On Tue, Jul 3, 2012 at 6:32 PM, Sergiu Ivanov >>> wrote: On Tue, Jul 3, 2012 at 4:03 PM, Matthew Rocklin wrote: > I'

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Sergiu Ivanov
On Sun, Jul 22, 2012 at 10:45 PM, Ronan Lamy wrote: > Le dimanche 22 juillet 2012 à 17:55 +0300, Sergiu Ivanov a écrit : >> >> 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.

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Ronan Lamy
Le dimanche 22 juillet 2012 à 17:55 +0300, Sergiu Ivanov a écrit : > 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 it

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-22 Thread Sergiu Ivanov
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-d

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-10 Thread Sergiu Ivanov
On Tue, Jul 10, 2012 at 6:10 PM, Chris Smith wrote: > On Tue, Jul 10, 2012 at 9:55 AM, Sergiu Ivanov > wrote: >> On Tue, Jul 3, 2012 at 6:32 PM, Sergiu Ivanov >> wrote: >>> On Tue, Jul 3, 2012 at 4:03 PM, Matthew Rocklin wrote: I've found that sorting the args at creation time solves lots

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-10 Thread Chris Smith
On Tue, Jul 10, 2012 at 9:55 AM, Sergiu Ivanov wrote: > On Tue, Jul 3, 2012 at 6:32 PM, Sergiu Ivanov > wrote: >> On Tue, Jul 3, 2012 at 4:03 PM, Matthew Rocklin wrote: >>> I've found that sorting the args at creation time solves lots of problems. I >>> have not found that this sorting causes an

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-10 Thread Sergiu Ivanov
On Tue, Jul 3, 2012 at 6:32 PM, Sergiu Ivanov wrote: > On Tue, Jul 3, 2012 at 4:03 PM, Matthew Rocklin wrote: >> I've found that sorting the args at creation time solves lots of problems. I >> have not found that this sorting causes any performance issues in SymPy. >> Sorting is fairly efficient

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-03 Thread Sergiu Ivanov
On Tue, Jul 3, 2012 at 4:03 PM, Matthew Rocklin wrote: > I've found that sorting the args at creation time solves lots of problems. I > have not found that this sorting causes any performance issues in SymPy. > Sorting is fairly efficient and no one uses FiniteSets for huge sets. I will make the

Re: [sympy] FiniteSet.sort_key and the ordering of .args

2012-07-03 Thread Matthew Rocklin
I've found that sorting the args at creation time solves lots of problems. I have not found that this sorting causes any performance issues in SymPy. Sorting is fairly efficient and no one uses FiniteSets for huge sets. On Tue, Jul 3, 2012 at 7:36 AM, Sergiu Ivanov wrote: > Hello, > > FiniteSet c

[sympy] FiniteSet.sort_key and the ordering of .args

2012-07-03 Thread Sergiu Ivanov
Hello, FiniteSet currently relies on Basic.sort_key, which produces the sort key by iterating .args, in the order in which they are stored. Since FiniteSet.args are obtained from an (unordered) frozenset at construction, Basic.sort_key produces different (and hence, hash-dependent) sort keys. Th