From: ·······@noshpam.lbl.government
Subject: rational arithmetic library?
Date: 
Message-ID: <4pkad39us99.fsf@thar.lbl.gov>
I've been looking for a means to implement a numerical linear algebra
algorithm, but without the concomitant round-off error (I'm fortunate
enough that my initial matrices are of integer type). . So, with an
instinctual reaction to check SICP, I remembered the good 'ole days of
implementing rational arithmetic (2.1.1). 

I needed a more general library, though. I had the linear algebra
algorithm all coded up, but I simply wanted to exchange the arithmetic
operators to ones which would understand & simplify both rational
numbers and integers. 

I couldn't find anything online, so I took the basics of SICP 2.1.1,
and made some extensions:

http://thar.lbl.gov/~taltman/rational.scm.html

So, what's my point?

1) The fun of implementing rational arithmetic in Scheme from scratch
   aside, is there a library already implemented?

2) Please reply to me with feedback
   (questions/suggestions/comments/criticism).

3) Are there packages for this kind of symbolic/numerical work in GNU
   Maxima (maxima.sf.net)? Or in other environments?

Many thanks,

~Tomer Altman 


-- 
()

From: Rahul Jain
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <877jyddtsi.fsf@nyct.net>
·······@noshpam.lbl.government writes:

> 1) The fun of implementing rational arithmetic in Scheme from scratch
>    aside, is there a library already implemented?

Most implementations of Scheme already have rationals. From what I
gather, scheme doesn't require rationals, but requires certain
relationships with other numerical types to hold, if those other types
are implemented.

Common Lisp requires support for rationals as well as floats and complex
numbers.

> 3) Are there packages for this kind of symbolic/numerical work in GNU
>    Maxima (maxima.sf.net)? Or in other environments?

Since Maxima is implemented in Common Lisp, and, as far as I know, uses
the arithmetic operators of the host Lisp, it should support your
operations automatically. The algebraic operators are implemented
internally, of course, but fall back to the arithmetic operators when
possible.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pkad382oet.fsf@thar.lbl.gov>
Rahul Jain <·····@nyct.net> writes:

> ·······@noshpam.lbl.government writes:
>
>> 1) The fun of implementing rational arithmetic in Scheme from scratch
>>    aside, is there a library already implemented?
>
> Most implementations of Scheme already have rationals. From what I
> gather, scheme doesn't require rationals, but requires certain
> relationships with other numerical types to hold, if those other types
> are implemented.

I took a second look at R5RS, and I realized my confusion; I guess my
current implementation-of-choice, Guile, doesn't support 'numerator',
'denominator', or 'rationalize'! So I tried some others:

*DrScheme: yes
*Guile: no
*Chicken: no
*Bigloo: yes
*Scheme48/Scsh: yes
*SCM: no

Is there any more definitive information about this kind of "optional
standard" across various Scheme implementations? Specifically, are
there implementations which internally represent the division of
integers as the creation of a rational number, with both the numerator
and the denominator being bignums? If there's a limit to an
implementation's ability to store rationals (due to the numerator
and/or the denominator being fixnums), then they're useless for the
scientific application I had in mind.

So I guess this is standard in CL. Does the HyperSpec mandate this?
And are both the numerator and the denominator required to be
represented as bignums? I read the HyperSpec, and it didn't seem to
mention either way...

Would I be better off just using a CAS like GNU Maxima?

~Tomer
From: Thomas A. Russ
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <ymifzd0t6w1.fsf@sevak.isi.edu>
Groups trimmed.

·······@noshpam.lbl.government writes:

> Is there any more definitive information about this kind of "optional
> standard" across various Scheme implementations? Specifically, are
> there implementations which internally represent the division of
> integers as the creation of a rational number, with both the numerator
> and the denominator being bignums? If there's a limit to an
> implementation's ability to store rationals (due to the numerator
> and/or the denominator being fixnums), then they're useless for the
> scientific application I had in mind.
> 
> So I guess this is standard in CL. Does the HyperSpec mandate this?
> And are both the numerator and the denominator required to be
> represented as bignums? I read the HyperSpec, and it didn't seem to
> mention either way...

Integers in CL are a subtype of Rational, and bignums are a subtype of
Integer, so arbitrary sized rational numbers are, in fact, mandated by
the CL standard.  You are still limited by the size of memory on your
machine, but other than that it should not matter.

Now, some of the other arithmetic functions such as the trig functions
will return floats instead of rationals, but I suspect that may not
matter to you.


> Would I be better off just using a CAS like GNU Maxima?
> 
> ~Tomer



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pk3c8zhfhq.fsf@thar.lbl.gov>
···@sevak.isi.edu (Thomas A. Russ) writes:

> Groups trimmed.

Good idea. Thanks.

> ·······@noshpam.lbl.government writes:

[snip]

>> So I guess this is standard in CL. Does the HyperSpec mandate this?
>> And are both the numerator and the denominator required to be
>> represented as bignums? I read the HyperSpec, and it didn't seem to
>> mention either way...
>
> Integers in CL are a subtype of Rational, and bignums are a subtype of
> Integer, so arbitrary sized rational numbers are, in fact, mandated by
> the CL standard.  You are still limited by the size of memory on your
> machine, but other than that it should not matter.


All I'm looking for is a unrestricted language implementation, on a
very-restricted computer. :-)

>
> Now, some of the other arithmetic functions such as the trig functions
> will return floats instead of rationals, but I suspect that may not
> matter to you.

Rational addition, subtraction, division, and multiplication will do
for now.

All replies appreciated and welcome,

~Tomer
From: Pascal Bourguignon
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <871xoj619y.fsf@thalassa.informatimago.com>
·······@noshpam.lbl.government writes:
> All I'm looking for is a unrestricted language implementation, on a
> very-restricted computer. :-)
> 
> >
> > Now, some of the other arithmetic functions such as the trig functions
> > will return floats instead of rationals, but I suspect that may not
> > matter to you.
> 
> Rational addition, subtraction, division, and multiplication will do
> for now.
> 
> All replies appreciated and welcome,

I don't see what's the problem?


;; Warning: untested code follows.

(defun sign (num)
  (cond ((< num 0) -1)
        ((> num 0) +1)
        (t          0)))

(defstruct (rat (:constructor %make-rat)
                (:print-function (lambda (rat stream level)
                                   (format stream "~D/~D"
                                           (rat-numerator rat)
                                           (rat-denominator rat)))))
  (numerator 0   :type integer)
  (denominator 1 :type (and integer (not (member 0)))))
                                                
(defun make-rat (num denum)
  (assert (and (integerp num) (integerp denum) (/= 0 denum)))
  (let ((g (gcd num denum))
        (ds (sign denum)))
    (%make-rat (/ (* ds num) g) (/ (* ds denum) g))))

(defun rat-to-double-float (r)
  (coerce (/ (rat-numerator r) (rat-denominator r)) 'double-float))

(defun  rat+ (a b)
  (make-rat (+ (* (rat-numerator a) (rat-denominator b))
               (* (rat-numerator b) (rat-denominator a)))
            (*  (rat-denominator a) (rat-denominator b))))

(defun  rat- (a b)
  (make-rat (- (* (rat-numerator a) (rat-denominator b))
               (* (rat-numerator b) (rat-denominator a)))
            (*  (rat-denominator a) (rat-denominator b))))

(defun  rat* (a b)
  (make-rat (* (rat-numerator a)   (rat-numerator b))
            (* (rat-denominator a) (rat-denominator b))))

(defun  rat/ (a b)
  (make-rat (* (rat-numerator a) (rat-denominator b))
            (* (rat-numerator b) (rat-denominator a))))

;; Definition of generic functions allowing free mixing of integers
;; and rationals left to the reader...


Of course, if  you feel that's your integers  that are restricted, you
can implement your unrestricted int type in a similar fashion, and use
it instead of integer...



-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pkwu6avp4j.fsf@thar.lbl.gov>
Pascal Bourguignon <····@thalassa.informatimago.com> writes:

> I don't see what's the problem?

Well, I posted to c.l.l to get the CL response to my problem. I
quickly found out that rational types as bignum tuples is a given via
the CLHS. So, you're right; with CL, I'm set. But I'm still hunting
for a Scheme implementation which will provide exactly that as well,
since my code is in Scheme. :-)

[snip]

> ;; Definition of generic functions allowing free mixing of integers
> ;; and rationals left to the reader...

This reader already concocted something along these lines:
http://thar.lbl.gov/~taltman/rational.scm.html
:-)


> Of course, if  you feel that's your integers  that are restricted, you
> can implement your unrestricted int type in a similar fashion, and use
> it instead of integer...

That's true, but I'd like to save myself the trouble of re-inventing
the wheel if it's avoidable.

Thanks!

~Tomer

-- 
()
From: Marco Antoniotti
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <Tum%b.56$IJ5.18132@typhoon.nyu.edu>
·······@noshpam.lbl.government wrote:

> Pascal Bourguignon <····@thalassa.informatimago.com> writes:
> 
> 
>>I don't see what's the problem?
> 
> 
> Well, I posted to c.l.l to get the CL response to my problem. I
> quickly found out that rational types as bignum tuples is a given via
> the CLHS. So, you're right; with CL, I'm set. But I'm still hunting
> for a Scheme implementation which will provide exactly that as well,
> since my code is in Scheme. :-)
> 
> [snip]
> 
> 
>>;; Definition of generic functions allowing free mixing of integers
>>;; and rationals left to the reader...
> 
> 
> This reader already concocted something along these lines:
> http://thar.lbl.gov/~taltman/rational.scm.html
> :-)
> 
> 
> 
>>Of course, if  you feel that's your integers  that are restricted, you
>>can implement your unrestricted int type in a similar fashion, and use
>>it instead of integer...
> 
> 
> That's true, but I'd like to save myself the trouble of re-inventing
> the wheel if it's avoidable.

A good definition of "re-inventing the wheel" is "use Scheme". :)

Cheers
--
Marco
From: Pascal Bourguignon
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <87ad343kzm.fsf@thalassa.informatimago.com>
Marco Antoniotti <·······@cs.nyu.edu> writes:
> A good definition of "re-inventing the wheel" is "use Scheme". :)

Indeed, that's my conclusion too.
It's by design, for the pedagogical value of it! 
But outside of schools, I doubt its value.

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
From: Ray Dillinger
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4043C1F6.D63B332C@sonic.net>
·······@noshpam.lbl.government wrote:
> 
> Pascal Bourguignon <····@thalassa.informatimago.com> writes:
> 
> > I don't see what's the problem?
> 
> Well, I posted to c.l.l to get the CL response to my problem. I
> quickly found out that rational types as bignum tuples is a given via
> the CLHS. So, you're right; with CL, I'm set. But I'm still hunting
> for a Scheme implementation which will provide exactly that as well,
> since my code is in Scheme. :-)

MIT/Gnu Scheme, DrScheme, Scheme48, Scsh, SISC, and the latest version 
of Guile are all schemes that have arbitrary-precision rationals. 

				Good Luck.

				Bear
From: Christopher C. Stacy
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <ullmrggrt.fsf@news.dtpq.com>
Not being a math person, I must have missed something terribly 
simple and obvious here.  Why would you need to implement the 
RAT type in Common Lisp?  Common Lisp already has a built-in 
infinite precision rational data type with which you can 
perform the arithmatic the OP was requesting?
From: Pascal Bourguignon
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <87ad373s6b.fsf@thalassa.informatimago.com>
······@news.dtpq.com (Christopher C. Stacy) writes:

> Not being a math person, I must have missed something terribly 
> simple and obvious here.  Why would you need to implement the 
> RAT type in Common Lisp?  Common Lisp already has a built-in 
> infinite precision rational data type with which you can 
> perform the arithmatic the OP was requesting?

I don't know.  This sounds silly to me too, but
·······@noshpam.lbl.government asked for it...


-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
From: Joe Marshall
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <vflwi3q5.fsf@ccs.neu.edu>
·······@noshpam.lbl.government writes:

> I took a second look at R5RS, and I realized my confusion; I guess my
> current implementation-of-choice, Guile, doesn't support 'numerator',
> 'denominator', or 'rationalize'! So I tried some others:
>
> *DrScheme: yes
> *Guile: no
> *Chicken: no
> *Bigloo: yes
> *Scheme48/Scsh: yes
> *SCM: no

MIT Scheme: yes
From: Scott G. Miller
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <-e2dnSA6R6RHTqbdRVn-jA@giganews.com>
·······@noshpam.lbl.government wrote:
> Rahul Jain <·····@nyct.net> writes:
> 
> 
>>·······@noshpam.lbl.government writes:
>>
>>
>>>1) The fun of implementing rational arithmetic in Scheme from scratch
>>>   aside, is there a library already implemented?
>>
>>Most implementations of Scheme already have rationals. From what I
>>gather, scheme doesn't require rationals, but requires certain
>>relationships with other numerical types to hold, if those other types
>>are implemented.
> 
> 
> I took a second look at R5RS, and I realized my confusion; I guess my
> current implementation-of-choice, Guile, doesn't support 'numerator',
> 'denominator', or 'rationalize'! So I tried some others:
> 
> *DrScheme: yes
> *Guile: no
> *Chicken: no
> *Bigloo: yes
> *Scheme48/Scsh: yes
> *SCM: no
> 
> Is there any more definitive information about this kind of "optional
> standard" across various Scheme implementations? Specifically, are
> there implementations which internally represent the division of
> integers as the creation of a rational number, with both the numerator
> and the denominator being bignums? If there's a limit to an
> implementation's ability to store rationals (due to the numerator
> and/or the denominator being fixnums), then they're useless for the
> scientific application I had in mind.
> 
SISC does what you say.  Exact division is equivalent to creating a 
rational number and simplifying.  But R5RS doesn't require any specific 
precision, just a vague notion of consistency throughout the 
implementation and respective to its goals.

	Scott
From: Christopher C. Stacy
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <uhdxgm69h.fsf@news.dtpq.com>
>>>>> On Tue, 24 Feb 2004 12:49:46 -0800, taltman  ("taltman") writes:
 taltman> If there's a limit to an implementation's ability to store
 taltman> rationals (due to the numerator and/or the denominator being
 taltman> fixnums), then they're useless for the scientific
 taltman> application I had in mind.

There's always a limit to any implementation's ability to 
store rationals: resources are not infinite.

 taltman> So I guess this is standard in CL. Does the HyperSpec mandate this?

 taltman> And are both the numerator and the denominator required to
 taltman> be represented as bignums? I read the HyperSpec, and it
 taltman> didn't seem to mention either way...

Yes, Common Lisp has rational numbers, no kidding.
What CLHS says is:

  Rational computations cannot overflow in the usual sense
  (though there may not be enough storage to represent a
  result), since integers and ratios may in principle be
  of any magnitude.
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pkbrnnhg49.fsf@thar.lbl.gov>
······@news.dtpq.com (Christopher C. Stacy) writes:

>>>>>> On Tue, 24 Feb 2004 12:49:46 -0800, taltman  ("taltman") writes:
>  taltman> If there's a limit to an implementation's ability to store
>  taltman> rationals (due to the numerator and/or the denominator being
>  taltman> fixnums), then they're useless for the scientific
>  taltman> application I had in mind.
>
> There's always a limit to any implementation's ability to 
> store rationals: resources are not infinite.

Oh, I'm sure. But all I want is something where integer division is
represented as a tuple of bignums "in simplified form", and where it
"promotes" to an integer (fixnum or bignum) when appropriate.

Is there a single Scheme that can do this? I think Scott said that
SISC can do this; am I quoting you correctly?

Thanks,

~Tomer
From: Scott G. Miller
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <rIWdnSiZtdwGIqHdRVn-jg@giganews.com>
·······@noshpam.lbl.government wrote:
> ······@news.dtpq.com (Christopher C. Stacy) writes:
> 
> 
>>>>>>>On Tue, 24 Feb 2004 12:49:46 -0800, taltman  ("taltman") writes:
>>
>> taltman> If there's a limit to an implementation's ability to store
>> taltman> rationals (due to the numerator and/or the denominator being
>> taltman> fixnums), then they're useless for the scientific
>> taltman> application I had in mind.
>>
>>There's always a limit to any implementation's ability to 
>>store rationals: resources are not infinite.
> 
> 
> Oh, I'm sure. But all I want is something where integer division is
> represented as a tuple of bignums "in simplified form", and where it
> "promotes" to an integer (fixnum or bignum) when appropriate.
> 
> Is there a single Scheme that can do this? I think Scott said that
> SISC can do this; am I quoting you correctly?
> 
Yes, thats exactly what SISC does.  The rationals have bignum 
components, which are limited to 2^32 bits (i.e. 2^(2^32) is the largest 
representable number).

You should continue searching though if you're doing high performance
computation.  While SISC's bignum arithmetic is competitive, the rest of 
the Scheme system is not compiled, but rather interprets a high 
performance intermediate form (micro-expressions).  This may not matter 
if bignum arithmetic dominates the time spent.

	Scott
From: Johan Kullstam
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <871xobm1rn.fsf@sysengr.res.ray.com>
"Scott G. Miller" <········@freenetproject.org> writes:

> ·······@noshpam.lbl.government wrote:
> > ······@news.dtpq.com (Christopher C. Stacy) writes:
> >
> >>>>>>>On Tue, 24 Feb 2004 12:49:46 -0800, taltman  ("taltman") writes:
> >>
> >> taltman> If there's a limit to an implementation's ability to store
> >> taltman> rationals (due to the numerator and/or the denominator being
> >> taltman> fixnums), then they're useless for the scientific
> >> taltman> application I had in mind.
> >>
> >> There's always a limit to any implementation's ability to store
> >> rationals: resources are not infinite.
> > Oh, I'm sure. But all I want is something where integer division is
> > represented as a tuple of bignums "in simplified form", and where it
> > "promotes" to an integer (fixnum or bignum) when appropriate.
> > Is there a single Scheme that can do this? I think Scott said that
> > SISC can do this; am I quoting you correctly?
> >
> Yes, thats exactly what SISC does.  The rationals have bignum
> components, which are limited to 2^32 bits (i.e. 2^(2^32) is the
> largest representable number).

I think your definition of "bignum" differs from mine (I am coming
from common-lisp and terminology will not be the same).  I take
"bignum" to mean an arbitrarily large integer (well, there is finite
memory available, but certainly thousands of bits should be viable).

I would assume that an implementation keeps track of how many words
are in the bignum.  To add two bignums, it could apply machine code to
"add" followed by a series "add with carry" operations as needed.

From the CLHS
 The type bignum is defined to be exactly (and integer (not fixnum)).

Where fixnum is some fixed range of integers (range at least as large
as 16 bit signed integers for common-lisp).

Being limited to a certain number of bits, e.g., 32, is what I consider
the definiting atribute of being a fixnum and, hence, specifically
disallowed by the term bignum.

> You should continue searching though if you're doing high performance
> computation.  While SISC's bignum arithmetic is competitive, the rest
> of the Scheme system is not compiled, but rather interprets a high
> performance intermediate form (micro-expressions).  This may not
> matter if bignum arithmetic dominates the time spent.
> 
> 	Scott
> 

-- 
Johan KULLSTAM <··········@comcast.net> sysengr
From: Christophe Rhodes
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <sqad2zge4s.fsf@lambda.dyndns.org>
Johan Kullstam <··········@comcast.net> writes:

> "Scott G. Miller" <········@freenetproject.org> writes:
>
>> Yes, thats exactly what SISC does.  The rationals have bignum
>> components, which are limited to 2^32 bits (i.e. 2^(2^32) is the
>> largest representable number).
>
> Being limited to a certain number of bits, e.g., 32, is what I consider
> the definiting atribute of being a fixnum and, hence, specifically
> disallowed by the term bignum.

A limitation of 32 bits for a bignum might be serious.  (I wouldn't be
happy with it :-).  A limitation of 2^32 bits is significantly less so
in practical terms.

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)
From: Scott G. Miller
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <qc-dnQg-q-p1Zdnd4p2dnA@giganews.com>
Christophe Rhodes wrote:
> Johan Kullstam <··········@comcast.net> writes:
> 
> 
>>"Scott G. Miller" <········@freenetproject.org> writes:
>>
>>
>>>Yes, thats exactly what SISC does.  The rationals have bignum
>>>components, which are limited to 2^32 bits (i.e. 2^(2^32) is the
>>>largest representable number).
>>
>>Being limited to a certain number of bits, e.g., 32, is what I consider
>>the definiting atribute of being a fixnum and, hence, specifically
>>disallowed by the term bignum.
> 
> 
> A limitation of 32 bits for a bignum might be serious.  (I wouldn't be
> happy with it :-).  A limitation of 2^32 bits is significantly less so
> in practical terms.
> 
Yes.  I think he misread.  The maximum bignum in SISC would occupy about 
  270mb of memory (2.1 billion bits) in a single number, which would be 
pretty impractical to use in real computations.  The limitation, fwiw, 
comes out of the Java BigInteger class, which has several methods which 
operate on bits indexed by a Java int, which is a signed 32 bit integer. 
    That means the largest addressable bit by those operators is (- 
(expt 2 31) 1)

	Scott
From: Johan Kullstam
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <87wu62lxh0.fsf@sysengr.res.ray.com>
Christophe Rhodes <·····@cam.ac.uk> writes:

> Johan Kullstam <··········@comcast.net> writes:
> 
> > "Scott G. Miller" <········@freenetproject.org> writes:
> >
> >> Yes, thats exactly what SISC does.  The rationals have bignum
> >> components, which are limited to 2^32 bits (i.e. 2^(2^32) is the
> >> largest representable number).
> >
> > Being limited to a certain number of bits, e.g., 32, is what I consider
> > the definiting atribute of being a fixnum and, hence, specifically
> > disallowed by the term bignum.
> 
> A limitation of 32 bits for a bignum might be serious.  (I wouldn't be
> happy with it :-).  A limitation of 2^32 bits is significantly less so
> in practical terms.

D'oh.  I totally misread that then.  Sorry, my bad.

-- 
Johan KULLSTAM <··········@comcast.net> sysengr
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pk65dux4tw.fsf@thar.lbl.gov>
·······@noshpam.lbl.government writes:

> I took a second look at R5RS, and I realized my confusion; I guess my
> current implementation-of-choice, Guile, doesn't support 'numerator',
> 'denominator', or 'rationalize'! So I tried some others:
>
> *DrScheme: yes
> *Guile: no
> *Chicken: no
> *Bigloo: yes
> *Scheme48/Scsh: yes
> *SCM: no

I made a mistake: Bigloo does not support rationals:

1:=> rationalize

*** ERROR:bigloo:eval:
Unbound variable -- rationalize
#unspecified
1:=> numerator

*** ERROR:bigloo:eval:
Unbound variable -- numerator
#unspecified
1:=> denominator

*** ERROR:bigloo:eval:
Unbound variable -- denominator
#unspecified
1:=> (/ 10 3)
3.3333333333333
1:=> (/ 1111111111111111111 999999999999999999999999)

*** ERROR:bigloo:/:
not a number -- #l1111111111111111111
#unspecified

---

~T
From: Marco Antoniotti
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <9wm%b.57$IJ5.18132@typhoon.nyu.edu>
·······@noshpam.lbl.government wrote:

> ·······@noshpam.lbl.government writes:
> 
> 
>>I took a second look at R5RS, and I realized my confusion; I guess my
>>current implementation-of-choice, Guile, doesn't support 'numerator',
>>'denominator', or 'rationalize'! So I tried some others:
>>
>>*DrScheme: yes
>>*Guile: no
>>*Chicken: no
>>*Bigloo: yes
>>*Scheme48/Scsh: yes
>>*SCM: no
> 
> 
> I made a mistake: Bigloo does not support rationals:

But any CL implementation does.  A piece of advice: bite the bullet! 
Switch to CL :)

Cheers
--
Marco
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pk65dtiqzg.fsf@thar.lbl.gov>
Marco Antoniotti <·······@cs.nyu.edu> writes:

> ·······@noshpam.lbl.government wrote:
>> I made a mistake: Bigloo does not support rationals:
>
> But any CL implementation does.  A piece of advice: bite the bullet!
> Switch to CL :)

You know, I had dinner with two Berkeley Lispniks last night, and I
was expecting them to "let me have it". :-) They let me off easy,
though...

But this incident does strengthen my conviction to become proficient
in Scheme *and* CL. 

~Tomer

>
> Cheers
> --
> Marco
>

-- 
()
From: Carl Devore
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <3a64b911.0402252328.401f8930@posting.google.com>
·······@noshpam.lbl.government wrote:
> I've been looking for a means to implement a numerical linear algebra
> algorithm, but without the concomitant round-off error (I'm fortunate
> enough that my initial matrices are of integer type). 
>
> I needed a more general library, though. I had the linear algebra
> algorithm all coded up, but I simply wanted to exchange the arithmetic
> operators to ones which would understand & simplify both rational
> numbers and integers. 

Check out www.linalg.org.  You can download extensive C++ code there
for the exact solution of matrix problems.  Rational arithmetic is
usually not the best thing to use for integer matrix problems, execpt
perhaps that it may be required in the final steps if the answers
themselves are rational.
From: ·······@noshpam.lbl.government
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <4pk1xohiqtc.fsf@thar.lbl.gov>
······@math.udel.edu (Carl Devore) writes:

> Check out www.linalg.org.  You can download extensive C++ code there
> for the exact solution of matrix problems.  Rational arithmetic is
> usually not the best thing to use for integer matrix problems, execpt
> perhaps that it may be required in the final steps if the answers
> themselves are rational.

Why so? I need the answers to be exact, not approximate. My matrix
starts with positive & negative integers between -2 and 2. In the
worst-case, I can imagine a bignum implementation chewing up a lot of
resources. But I imagine that the average case will be acceptable (I
need accuracy, not speed).

-- 
()
From: Richard Fateman
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <c1lnhj$9ue$1@agate.berkeley.edu>
You don't say what you are doing, or how long you expect
your computation to take.

  There are studies that suggest
doing some exact operations can be done more efficiently
by using finite field arithmetic (perhaps several times)
and sticking the pieces together with the Chinese Remainder
Algorithm. e.g. McClellan's work on exact solution of linear
equations  using modular arithmetic.

You might also look at papers on "Exact Linear Algebra"
by Ashoff
(try google).

·······@noshpam.lbl.government wrote:

> ······@math.udel.edu (Carl Devore) writes:
> 
> 
>>Check out www.linalg.org.  You can download extensive C++ code there
>>for the exact solution of matrix problems.  Rational arithmetic is
>>usually not the best thing to use for integer matrix problems, execpt
>>perhaps that it may be required in the final steps if the answers
>>themselves are rational.
> 
> 
> Why so? I need the answers to be exact, not approximate. My matrix
> starts with positive & negative integers between -2 and 2. In the
> worst-case, I can imagine a bignum implementation chewing up a lot of
> resources. But I imagine that the average case will be acceptable (I
> need accuracy, not speed).
> 
From: David Holland
Subject: Re: rational arithmetic library?
Date: 
Message-ID: <87175f0.0402271238.7ba3556b@posting.google.com>
Perhaps i am way out of league here, if so, tell me.

We developed a library for Windows. That is for use under Visual Basic
and C++.

All functions are for big numbers (theoreticly no limit except RAM)
and
they are all based on rational number calculation.

Functions:http://www.big-numbers.com/forum/viewtopic.php?t=12

Download:http://www.big-numbers.com/forum/viewtopic.php?t=27&sid=b5588871941e2916514af64e861825fb

Site: www.big-numbers.com

David