Thread: Re: [pure-lang-users] Numeric Arguments (Page 2)
Status: Beta
Brought to you by:
agraef
From: John C. <co...@cc...> - 2008-07-08 15:16:49
|
Libor Spacek scripsit: > Also, replace doubles with rationals. (All numbers with limited > precision are de facto rationals anyway). For pragmatic reasons place > some limit on the size of the bigints and raise an exception when it > is reached. You really, really don't want to go there. Operations on machine floats are fast, as fast as integer math for the same word size, usually. Dealing with equivalent rationals is very slow because of all the conditional memory fetches you have to do. In Scheme, the difference between hopelessly slow and acceptably fast is often as simple as adding a judicious decimal point to some constant. -- Where the wombat has walked, John Cowan <co...@cc...> it will inevitably walk again. http://www.ccil.org/~cowan |
From: Albert G. <Dr....@t-...> - 2008-07-09 05:06:56
|
John Cowan wrote: > In Scheme, the difference between hopelessly slow and acceptably fast > is often as simple as adding a judicious decimal point to some constant. Same on my HP 50G calculator. :) Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: Libor S. <li...@gm...> - 2008-07-08 15:31:08
|
Well, yes, Scheme seems to take a step in the right direction. I notice that even Pure already does one of my listed promotions, provided math.pure is used: sqrt(-2); So perhaps there are no objections to this in principle? ;) I don't see the point of having a mixed type (1 1/3), except perhaps for the prettyprinting purposes, if desired. > > (sqrt 1/5) > 0.4472135954999579 > We don't want and exact approximation to an irrational number do we? > Yes, I know that is really a rational number in disguise, but it lets > the user know that it really is an approximation instead of letting > them believe it is exact. This is why I suggested that an exception is thrown at such times. (The bigint in the rational result will reach its preset "warning" limit whenever an irrational is produced. However, the user will mostly wish to continue with the calculation on the rational, not being any worse off than having to switch everything over to a separate "doubles code" at this point. Libor |
From: Albert G. <Dr....@t-...> - 2008-07-09 05:17:18
|
Libor Spacek wrote: >> > (sqrt 1/5) >> 0.4472135954999579 >> We don't want and exact approximation to an irrational number do we? > > This is why I suggested that an exception is thrown at such times. This kind of behaviour may be appropriate for a pocket calculator or an interactive computer algebra system, but not for a general purpose programming language. You basically want your program to run unattended, and only bail out when there's a really serious error condition. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |
From: Eddie R. <er...@bm...> - 2008-07-08 20:22:14
|
On Tue, 2008-07-08 at 16:39 +0100, Libor Spacek wrote: > Better still, as there is an internal structure associated with this extended > number representation, we could include a binary "exact" flag that can be > interrogated by the user at any point to tell them which it is. > In scheme it is (exact? 1/4) #t (exact? 0.2) #f In Pure it is > rationalp 1%4; 1 > rationalp 2.0; 0 > rationalp 1; 0 Oops, Albert 1 is a rational number, so I think rationalp has a bug? e.r. |
From: Eddie R. <er...@bm...> - 2008-07-08 20:54:45
|
On Tue, 2008-07-08 at 15:22 -0500, Eddie Rucker wrote: How about this? If anyone sees a problem let me know. exactp n = not (doublep n || doublep (re n) || doublep (im n)); > exactp (1+:3); 1 > exactp (1%3); 1 > exactp (1.0+:3); 0 > exactp 3L; 1 > exactp 5.6; 0 e.r. > On Tue, 2008-07-08 at 16:39 +0100, Libor Spacek wrote: > > Better still, as there is an internal structure associated with this extended > > number representation, we could include a binary "exact" flag that can be > > interrogated by the user at any point to tell them which it is. > > > > In scheme it is > (exact? 1/4) > #t > (exact? 0.2) > #f > > In Pure it is > > rationalp 1%4; > 1 > > rationalp 2.0; > 0 > > rationalp 1; > 0 > > Oops, Albert 1 is a rational number, so I think rationalp has a bug? > > e.r. > > > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > _______________________________________________ > pure-lang-users mailing list > pur...@li... > https://lists.sourceforge.net/lists/listinfo/pure-lang-users |
From: Libor S. <li...@gm...> - 2008-07-08 22:31:53
|
That looks good to me. I think John Cowan made a good point about the rationals being very slow. As I said, the chip manufacturers should be encouraged to make instructions for them, then it will be a good way to proceed, imho. I find the slowness to be the only really persuasive argument against what I was suggesting. L. On Tue, 08 Jul 2008 21:54:52 +0100, Eddie Rucker <er...@bm...> wrote: > On Tue, 2008-07-08 at 15:22 -0500, Eddie Rucker wrote: > > How about this? If anyone sees a problem let me know. > > exactp n = not (doublep n || doublep (re n) || doublep (im n)); > > > exactp (1+:3); > 1 > > exactp (1%3); > 1 > > exactp (1.0+:3); > 0 > > exactp 3L; > 1 > > exactp 5.6; > 0 > > e.r. > >> On Tue, 2008-07-08 at 16:39 +0100, Libor Spacek wrote: >> > Better still, as there is an internal structure associated with this extended >> > number representation, we could include a binary "exact" flag that can be >> > interrogated by the user at any point to tell them which it is. >> > |