# big rationals question

Damien R. Sullivan dasulliv@cs.indiana.edu
Sun, 16 Feb 2003 01:50:51 -0500

```So, for my Algorithms class in grad school we have to calculate some number to
as many digits as possible in a minute.  I figured this would be a good
project to try in multiple languages, to see how they compared in ease and
speed.  In particular I've been intrigued by the functionality and strong
typing of Haskell and O'caml for a while, but never had an incentive to really
learn them without a project.

So I tackled ocaml first, looking at their tutorial, and without too much
trouble got a logarithm program working, confirming in the process that (a)
the syntax sucks (I like operator overloading for math) and (b) it seems
pretty fast, although I need to try Java or Perl or some C++ library for
comparison.  Not as fast as 'bc', but it might be using better algorithms.  In
particular I was able to print both the exact form of the big rational and a
decimal form to as many digits as I wanted easily.

Then I moved to Haskell, largely rewriting the ML code.  The result is much
nicer looking, being able to say 'sum + powx' instead of 'Num.add_num sum
powx', or having to define 'num_2' for a bignum version of 2.  It took longer
to actually run properly -- I got bit by laziness, but John Meacham tipped me
off.  And now I have '34283788463231218 % 20536892788086675' being printed
out, although I seem to have a bug since if that's a numerator and denominator
the result is not the natural logarithm of 2.  But my real question is can I
get Haskell to actually do that division itself?  I get complaints about
'Fractional Integer'; I had to use bc to do the division.

-xx- Damien X-)

```