[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-28 Thread Heinrich Apfelmus
Will Ness wrote:
 Heinrich Apfelmus writes:
 
 (Just for historical reference, credit for the data structure that works
 with infinite merges goes to Dave Bayer, I merely contributed the
 mnemonic aid of interpreting it in terms of VIPs.)
 
 yes, yes, my bad. GMANE is very unreliable at presenting the discussion 
 threads 
 in full. :| I saw it first on the Haskellwiki page though, and it was your 
 code 
 there, that's the reason for my mistake. :) 

No worries, doesn't count as mistake for none intended. :) In fact, I'm
flattered. ;)


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-26 Thread Will Ness
Derek Elkins derek.a.elkins at gmail.com writes:

 
 On Wed, Jan 20, 2010 at 9:42 AM, Will Ness will_n48 at yahoo.com wrote:
  Derek Elkins derek.a.elkins at gmail.com writes:
  On Sun, Jan 17, 2010 at 2:22 PM, Will Ness will_n48 at yahoo.com wrote:
   Hello cafe,
  
   I wonder, if we have List.insert and List.union, why 
   no List.merge (:: Ord a = [a] - [a] - [a])
   and no List.minus ? These seem to be pretty general
   operations.
 
  You
  probably also want to look at the package data-ordlist on hackage
  (http://hackage.haskell.org/packages/archive/data-
ordlist/0.0.1/doc/html/Data-
  OrdList.html)
  which represents sets and bags as ordered lists and has all of the
  operations you mention.
 
 
  I did, thanks again! Although, that package deals with non-decreasing lists,
  i.e. lists with multiples possibly. As such, its operations produce non-
  decreasing lists, i.e. possibly having multiples too.
 
 It is clear that some of the operations are guaranteed to produce sets
 given sets.  The documentation could be better in this regard though.
 
 The 'union' and 'minus' functions of ordlist meet this requirement if
 you satisfy the preconditions.


Yes, thanks, it's exactly what I was looking for. I've recognized from the code 
that `minus' was OK, but `merge' was different. As it turns out, OrdList.union 
is exactly what I have under `merge'. Better (or any at all really) 
documentation for Data.OrdList would be a big help. 

I don't know if it's at all easy to separate Sets and Bags, though it may seem 
desirable. I seem to have read something about Circle/Ellipse problem, i.e. the 
Sets/Bags problem which are not easily detachable from one another? Although I 
don't know the details of that. 

The background for this is my attempts to classify the various primes-
generating code variants. Apparently, the essense of sieve is the composites 
removal, and both composites and natural numbers are naturally represented as 
strictly increasing lists. Same with merging the lists of multiples of each 
prime to construct the composites. I had to provide the `minus' and `merge' 
definitions along with the actual code and searched for something standard.

You can check it out on the Haskellwiki Prime Numbers page (work still in 
progress, the comparison tables are missing). We had also a recent thread here 
in cafe under FASTER primes. The original idea of Heinrich Apfelmus of 
treefold merging the composites really panned out. I found a little bit better 
structure for the folding tree, and Daniel Fischer was a great help in fixing 
the space leaks there (two of them) so that now the resulting code, with wheel 
optimization, runs very close to the PQ-based O'Neill's sieve (actually faster 
than it if interpreted in GHCi). More importantly (?) there's a natural 
progression of code now, straight from the classic Turner's sieve, so it's not 
an ad-hoc thing anymore.

It also became apparent that the essence of prime wheels is Euler's sieve. And 
vice versa. :)

Thanks a lot for all the help from all the posters!

Cheers,


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-26 Thread Heinrich Apfelmus
Will Ness wrote:
 You can check it out on the Haskellwiki Prime Numbers page (work still in 
 progress, the comparison tables are missing). We had also a recent thread 
 here 
 in cafe under FASTER primes. The original idea of Heinrich Apfelmus of 
 treefold merging the composites really panned out.

(Just for historical reference, credit for the data structure that works
with infinite merges goes to Dave Bayer, I merely contributed the
mnemonic aid of interpreting it in terms of VIPs.)


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-26 Thread Will Ness
Heinrich Apfelmus apfelmus at quantentunnel.de writes:

 
 Will Ness wrote:
  You can check it out on the Haskellwiki Prime Numbers page (work still in 
  progress, the comparison tables are missing). We had also a recent thread 
here 
  in cafe under FASTER primes. The original idea of Heinrich Apfelmus of 
  treefold merging the composites really panned out.
 
 (Just for historical reference, credit for the data structure that works
 with infinite merges goes to Dave Bayer, I merely contributed the
 mnemonic aid of interpreting it in terms of VIPs.)
 
 Regards,
 Heinrich Apfelmus
 
 --
 http://apfelmus.nfshost.com
 


yes, yes, my bad. GMANE is very unreliable at presenting the discussion threads 
in full. :| I saw it first on the Haskellwiki page though, and it was your code 
there, that's the reason for my mistake. :) 



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-22 Thread Christian Maeder
Will Ness schrieb:
 Christian Maeder Christian.Maeder at dfki.de writes:
 
 Will Ness schrieb:
 I meant strictly increasing ordered lists, without multiples, for which the 
 two 
 operations, 'merge' and 'minus', would also have to produce like lists, i.e 
 strictly increasing, without multiples.
 Why don't you use directly Data.Set?
 
 It says it's based on size balanced Trees? I initially wondered why no such 
 fundamental operations as merge and minus for _lists_, in the stadard 
 libraries?

Yes, balanced trees, which makes insertion and member testing O(log n).

 Also, its to/from list conversions are O(n), so probably won't work for 
 infinite lists. 

One should not convert much from and to list, but always use
operations on sets directly. Sets are finite. I wonder what fundamental
advantage there is for infinite strictly increasing lists.

 
 I was told the trend is to move specifics to hackage packages, but I wonder 
 why 
 shouldn't such fundamental operations be just included in standard Data.List?

Both the current Set operations of Data.List and the (so many)
functions from Data.Ordlist are only useful for short lists (or other
special purposes) because of efficiency.

Furthermore, there is some risk that the invariant of lists being
(strictly) sorted is violated by accident (programming-error).
The ...By-functions allow to further confuse orders.

 There are also bags aka multisets:
 http://hackage.haskell.org/package/multiset
 
 it's too seems to be based on trees.

Yes.

 Data.Ordlist seems to be a good match, except for its conflation of 
 ascending/non-decreasing lists under one ordered category (i.e. sets/bags 
 distinction).

If you say, these should be two separate module, I would agree.

Cheers Christian
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why no merge and listDiff?

2010-01-22 Thread Derek Elkins
On Wed, Jan 20, 2010 at 9:42 AM, Will Ness will_...@yahoo.com wrote:
 Derek Elkins derek.a.elkins at gmail.com writes:
 On Sun, Jan 17, 2010 at 2:22 PM, Will Ness will_n48 at yahoo.com wrote:
  Hello cafe,
 
  I wonder, if we have List.insert and List.union, why no List.merge (:: Ord
 a =
  [a] - [a] - [a]) and no List.minus ? These seem to be pretty general
  operations.

 Presumably by List.minus you mean the (\\) function in Data.List.

 No, it has to search its second list over and over from the start, to be able
 to deal with unordered lists, so its performance can't be good.

Then use the ordlist one.

 You
 probably also want to look at the package data-ordlist on hackage
 (http://hackage.haskell.org/packages/archive/data-ordlist/0.0.1/doc/html/Data-
 OrdList.html)
 which represents sets and bags as ordered lists and has all of the
 operations you mention.


 I did, thanks again! Although, that package deals with non-decreasing lists,
 i.e. lists with multiples possibly. As such, its operations produce non-
 decreasing lists, i.e. possibly having multiples too.

It is clear that some of the operations are guaranteed to produce sets
given sets.  The documentation could be better in this regard though.

 I meant strictly increasing ordered lists, without multiples, for which the 
 two
 operations, 'merge' and 'minus', would also have to produce like lists, i.e
 strictly increasing, without multiples.

The 'union' and 'minus' functions of ordlist meet this requirement if
you satisfy the preconditions.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-20 Thread Will Ness
Derek Elkins derek.a.elkins at gmail.com writes:

 
 On Sun, Jan 17, 2010 at 2:22 PM, Will Ness will_n48 at yahoo.com wrote:
  Hello cafe,
 
  I wonder, if we have List.insert and List.union, why no List.merge (:: Ord 
a =
  [a] - [a] - [a]) and no List.minus ? These seem to be pretty general
  operations.
 
 Presumably by List.minus you mean the (\\) function in Data.List. 

No, it has to search its second list over and over from the start, to be able 
to deal with unordered lists, so its performance can't be good. 


 You
 probably also want to look at the package data-ordlist on hackage
 (http://hackage.haskell.org/packages/archive/data-ordlist/0.0.1/doc/html/Data-
OrdList.html)
 which represents sets and bags as ordered lists and has all of the
 operations you mention.


I did, thanks again! Although, that package deals with non-decreasing lists, 
i.e. lists with multiples possibly. As such, its operations produce non-
decreasing lists, i.e. possibly having multiples too. 

I meant strictly increasing ordered lists, without multiples, for which the two 
operations, 'merge' and 'minus', would also have to produce like lists, i.e 
strictly increasing, without multiples.

I guess the first variety is more appropriate for bags, and the second one - 
for sets. The two would have to be de-conflated for that. (?)



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-20 Thread Christian Maeder
Will Ness schrieb:
 I meant strictly increasing ordered lists, without multiples, for which the 
 two 
 operations, 'merge' and 'minus', would also have to produce like lists, i.e 
 strictly increasing, without multiples.

Why don't you use directly Data.Set?

 I guess the first variety is more appropriate for bags, and the second one - 
 for sets. The two would have to be de-conflated for that. (?)

There are also bags aka multisets:
http://hackage.haskell.org/package/multiset

Cheers Christian
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why no merge and listDiff?

2010-01-20 Thread Will Ness
Christian Maeder Christian.Maeder at dfki.de writes:

 Will Ness schrieb:
  I meant strictly increasing ordered lists, without multiples, for which the 
two 
  operations, 'merge' and 'minus', would also have to produce like lists, i.e 
  strictly increasing, without multiples.
 
 Why don't you use directly Data.Set?

It says it's based on size balanced Trees? I initially wondered why no such 
fundamental operations as merge and minus for _lists_, in the stadard libraries?

Also, its to/from list conversions are O(n), so probably won't work for 
infinite lists. 

I was told the trend is to move specifics to hackage packages, but I wonder why 
shouldn't such fundamental operations be just included in standard Data.List?

 
  I guess the first variety is more appropriate for bags, and the second one
  - for sets. The two would have to be de-conflated for that. (?)
 
 There are also bags aka multisets:
 http://hackage.haskell.org/package/multiset

it's too seems to be based on trees.

Data.Ordlist seems to be a good match, except for its conflation of 
ascending/non-decreasing lists under one ordered category (i.e. sets/bags 
distinction).




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe