Mombu the Science Forum sponsored links

Go Back   Mombu the Science Forum > Science > rational arithmetic library?
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 19th December 20:02
External User
 
Posts: 1
Default rational arithmetic library?


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


--
()
  Reply With Quote


  sponsored links


2 19th December 20:03
rahul jain
External User
 
Posts: 1
Default rational arithmetic library?


taltman@noshpam.lbl.government writes:


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.


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
rjain@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
  Reply With Quote
3 20th December 09:00
rlewis
External User
 
Posts: 1
Default rational arithmetic library


Hi,

Look into the computer algebra system Fermat, for Windows, Mac,
Unix, and Linux. It's shareware.

http://www.bway.net/~lewis/

Robert H. Lewis
Department of Mathematics
Fordham University
New York City
  Reply With Quote
4 20th December 09:00
External User
 
Posts: 1
Default rational arithmetic library?


Rahul Jain <rjain@nyct.net> 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

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
  Reply With Quote
5 20th December 09:00
joe marshall
External User
 
Posts: 1
Default rational arithmetic library?


taltman@noshpam.lbl.government writes:


MIT Scheme: yes
  Reply With Quote
6 20th December 09:00
scott g. miller
External User
 
Posts: 1
Default rational arithmetic library?


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
  Reply With Quote
7 20th December 09:00
cstacy
External User
 
Posts: 1
Default rational arithmetic library?


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.
  Reply With Quote
8 20th December 09:00
External User
 
Posts: 1
Default rational arithmetic library?


cstacy@news.dtpq.com (Christopher C. Stacy) writes:


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
  Reply With Quote
9 20th December 09:00
scott g. miller
External User
 
Posts: 1
Default rational arithmetic library?


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
  Reply With Quote
10 20th December 20:20
External User
 
Posts: 1
Default rational arithmetic library?


taltman@noshpam.lbl.government writes:


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
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666