Re: Rational sequence
In haskell-cafe, Alastair Reid wrote: > > Jerzy Karczmarczuk <[EMAIL PROTECTED]> writes: > > > Rationals in Hugs were always a bit obscure. What do you think, what > > is the Rational form of 2.3 ? (GHCi says 23/10). > > > The answer is: > > > 2589569785738035 % 1125899906842624 > > > (Old Hugs, Feb. 2001) > > I'm afraid the new release won't fix this. > > Once the release is out the door and things settle down a bit (both in > Hugs and in my personal life), I'd like to cleanup the Hugs' internals > which have gotten quite confused by layer upon layer of backward > compatability code. Practical benefits I hope for are: > > - Make Float mean 'C float' and Double mean 'C double'. > Most of the code is actually in Hugs already but it was disabled > because of some long-irrelevant issue involving the foreign > function interface. So it seems that double-precision can (and should) be re-enabled. Alastair (in another place) counsels caution. But it's my impression that several people are using a version of Hugs with USE_DOUBLE_PRECISION set to 1 (Jerzy clearly is) with no problems, so this should be safe. It also passes the Hugs test suite (modulo the extra precision). Any testimonials? ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
On Tue, Oct 22, 2002 at 01:54:58PM +0100, Simon Peyton-Jones wrote: > You look in the instance declaration for Ratio, which is given in the > Ratio chapter of the Library report. > > | As I told above, I can't see anything to change, except > | implementation. > > As I understand it, GHC conforms to the Report, Not quite: GHC sensibly defines succ and pred in Enum (Ratio a), but the Report doesn't. So officially, succ (3%2) = 2%1. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Frank Atanassow wrote (on 22-10-02 15:08 +0200): > Jerzy Karczmarczuk wrote (on 22-10-02 13:05 +0200): > > What do you think, what > > is the Rational form of 2.3 ? (GHCi says 23/10). > > > > The answer is: > > > > 2589569785738035 % 1125899906842624 > > Er, why? > > Because 2.3 is not representable using a double precision float or something? Oh, sorry. I understand Jerzy to be saying that that big long fraction was the result that he _wanted_, but instead the opposite seems to be true. That explains things. :) -- Frank ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
"Simon Peyton-Jones" <[EMAIL PROTECTED]> writes: > You look in the instance declaration for Ratio, which is > given in the Ratio chapter of the Library report. This is what I ignorantly called implementation. Sorry for the trouble. > As I understand it, GHC conforms to the Report, but Hugs > perhaps does not, yet. OK. I see your point, and also expressed mine. Seems like you won't argue about this, so I give up. I would have been grateful to learn the reasoning behind the current design, though. Feri. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Jerzy Karczmarczuk wrote (on 22-10-02 13:05 +0200): > What do you think, what > is the Rational form of 2.3 ? (GHCi says 23/10). > > The answer is: > > 2589569785738035 % 1125899906842624 Er, why? Because 2.3 is not representable using a double precision float or something? -- Frank ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: Rational sequence
| > The Report says that the Enum instance for Ratio uses the | > same rule as for Float/Double, | | Now I can see that the revised Report contains more about | this than the one on haskell.org. But I still can't see the | statement you cited above. Where should I look? You look in the instance declaration for Ratio, which is given in the Ratio chapter of the Library report. | As I told above, I can't see anything to change, except | implementation. As I understand it, GHC conforms to the Report, but Hugs perhaps does not, yet. Simon ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Jerzy Karczmarczuk <[EMAIL PROTECTED]> writes: > Rationals in Hugs were always a bit obscure. What do you think, what > is the Rational form of 2.3 ? (GHCi says 23/10). > The answer is: > 2589569785738035 % 1125899906842624 > (Old Hugs, Feb. 2001) I'm afraid the new release won't fix this. Once the release is out the door and things settle down a bit (both in Hugs and in my personal life), I'd like to cleanup the Hugs' internals which have gotten quite confused by layer upon layer of backward compatability code. Practical benefits I hope for are: - Make Float mean 'C float' and Double mean 'C double'. Most of the code is actually in Hugs already but it was disabled because of some long-irrelevant issue involving the foreign function interface. - Implement literal constants using Rational (as described by the standard) instead of using Double (which, of course, usually means 'float'). [This is a separate task from the first which I would be delighted to have someone else do.] Along the way, inessential things like compatability with GreenCard 1 (which died about 5 years ago) will die, people using GreenCard 2 (what most people call 'GreenCard') with Hugs will lose the option of generating Hugs-specific code instead of generating portable FFI code, deprecated types (like Addr) will disappear, etc. -- Alastair ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
"Simon Peyton-Jones" <[EMAIL PROTECTED]> writes: > The Report says that the Enum instance for Ratio uses the > same rule as for Float/Double, Now I can see that the revised Report contains more about this than the one on haskell.org. But I still can't see the statement you cited above. Where should I look? On the other hand, I found that 'the instance for Ratio t simply "lifts" the corresponding operations over t.' What does this mean with respect to Enum? > namely that [a..b] means takeWhile (<= (b+1/2)) [a, a+1, > a+2, ...] > > You may say that the "<=" should be "<" but that's what > the Report says. Well, neither makes more sense to me. For an imprecise type I don't expect precise behaviour. > I'm not sure what your rule should be, though. (What > about [2%4, ... 20%4]?) Rationals are represented precisely, so that well defined precise mathematical rules apply to them: [2%4..20%4] == [1%2..10%2] == [1%2,3%2,5%2,7%2,9%2], that's to say [a..b] = takeWhile (<= b) [a, a+1, a+2, ...] Those fuzzy 1/2-s are inserted solely to 'overcome' the imprecise floating point representation, and make 'simple stupid' programs work and programming newbies happy, aren't they? For serious work they don't count, only create one more peculiarity to observe. Please correct me if I'm mistaken. And please don't feel offended, I suppose that our opinions differ on this point, as shown by a previous thread. Still I don't think things like this promote Haskell, or make it more acceptable for anyone. > Anyway, it's a bit late to change the Report As I told above, I can't see anything to change, except implementation. If it's only my stupidity, then sorry for the nitpicking. Feri. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: Rational sequence
The Report says that the Enum instance for Ratio uses the same rule as for Float/Double, namely that [a..b] means takeWhile (<= (b+1/2)) [a, a+1, a+2, ...] You may say that the "<=" should be "<" but that's what the Report says. Certainly if you do [1%3..10%3] you'll get more values than your rule suggests. I'm not sure what your rule should be, though. (What about [2%4, ... 20%4]?) Anyway, it's a bit late to change the Report Simon | -Original Message- | From: Ferenc Wagner [mailto:wferi@;bolyai1.elte.hu] | Sent: 22 October 2002 11:12 | To: [EMAIL PROTECTED] | Subject: Rational sequence | | With GHC-5.02.2, I do | | $ ghci | Prelude> :m Ratio | Ratio> [1%2..10%2] | [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] | | The question is, why is there 11%2 at the end of the list? | It's inconsistent with the (good) rules for Integer, since | | Ratio> [1,3..10] | [1,3,5,7,9] | | Is this intentional? | Feri. | ___ | Haskell-Cafe mailing list | [EMAIL PROTECTED] | http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Alastair Reid: > Ferenc Wagner <[EMAIL PROTECTED]> writes: > H, the CVS copy of Hugs seems to suffer from a different problem: > > Prelude> [0.5,1.5..5.5]::[Rational] > [0 % 1,1 % 1,2 % 1,3 % 1,4 % 1,5 % 1] > > I'm expecting to see: > > [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] Rationals in Hugs were always a bit obscure. What do you think, what is the Rational form of 2.3 ? (GHCi says 23/10). The answer is: 2589569785738035 % 1125899906842624 (Old Hugs, Feb. 2001) If you look at the Prelude, you will see that the algorithms used for rationals are not always a rocket science. I replaced (for myself) that stuff by the continued fraction expansions which are fast and give decent results. The rational arithmetics can also be optimised by using algorithms in the 2nd volume of Knuth (the favourite book of Ralf Hinze...) I found similar bugs in sequences as above already (if I am not mistaken) about 7 - 8 years ago, when we discussed a bit the usage of Haskell to some numerics. But nobody really cared about it, and it seems that some small but nasty insects are still alive. Jerzy Karczmarczuk ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Alastair Reid <[EMAIL PROTECTED]> writes: > H, the CVS copy of Hugs seems to suffer from a different problem: > > Prelude> [0.5,1.5..5.5]::[Rational] > [0 % 1,1 % 1,2 % 1,3 % 1,4 % 1,5 % 1] Yes, the instance declaration misses the numericEnumFrom- ThenTo case, so it defaults to this. Btw, how can one have a look at the GHC Prelude? Feri. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Rational sequence
Ferenc Wagner <[EMAIL PROTECTED]> writes: $ ghci Prelude> :m Ratio Ratio> [1%2..10%2] > [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] H, the CVS copy of Hugs seems to suffer from a different problem: Prelude> [0.5,1.5..5.5]::[Rational] [0 % 1,1 % 1,2 % 1,3 % 1,4 % 1,5 % 1] I'm expecting to see: [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] -- Alastair Reid ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Rational sequence
With GHC-5.02.2, I do $ ghci Prelude> :m Ratio Ratio> [1%2..10%2] [1 % 2,3 % 2,5 % 2,7 % 2,9 % 2,11 % 2] The question is, why is there 11%2 at the end of the list? It's inconsistent with the (good) rules for Integer, since Ratio> [1,3..10] [1,3,5,7,9] Is this intentional? Feri. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe