This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: rationals in guile?


On 13 Nov 1998, Valentin Kamyshenko wrote:

> Dirk> Still, there are a couple of possibilities to represent the
> Dirk> different numbers and the types they correspond to: (N: integer,
> Dirk> Q: rational, R: real, C: complex)
> 
> Dirk> immediate (exact) --> NQRC 
> Dirk> bignum (exact) --> NQRC
> Dirk> immediate1/immediate2 (exact) --> N if immediate2 == 1, QRC
> Dirk> bignum/immediate2 (exact) --> N if immediate2 == 1, QRC
> Dirk> immediage1/bignum2 (exact) --> N if bignum2 == 1, QRC
> Dirk> bignum1/bignum2 (exact) --> N if bignum2 == 1, QRC 
> Dirk> float (inexact) --> N if (= x (round x)), QRC

> Could not we exclude many possibilities at once, stating that we
> use 'the most effective representation'?
> I mean, each bignum should be transformed to immediate int. as soon  
> as it becomes possible; rationals with denominator 1 -> integer
> (bignum or immediate); in complex, if Re is inexact, then Im
> is transformed to inexact, and vise-versa. Does not it lead to unique
> representation?  

It makes sense to assume that 'the most effective representation' is used.
This can eliminate special cases like rationals with denominator 1, but it
does not reduce the number of combinations:

1                           -> immediate
(expt 2 100)                -> bignum
1/2                         -> immediate/immediate
(expt 2 100)/3              -> bignum   /immediate
1/(expt 2 100)              -> immediate/bignum
(expt 2 100)+1/(expt 2 100) -> bignum   /bignum
float

Even with the special case re inexact <--> im inexact this leaves us with
36 exact representations and one inexact representation for complex
numbers. If a SCM/SCM pair would be used for exact rationals, the number
of types in guile would not be the problem, but the actual handling of the
numbers would: for a simple addition a large number of cases had to be
checked.

Best regards, 
Dirk Herrmann