Sunday, February 04, 2007

Lisp is my calculator

Today I was trying to calculate e.

I find that when I try to calculate things that involve either large exponents or sums of large series regular calculators just don't seem to cut it.

Today's calculation was for e using the formula given with limit notation:

e = lim x -> infinity (1+1/x)x

To do this I decided to select a value of x that is large enough to give a reasonable approximation for the first few digits... 25000

I don't know about you, but I havn't found many hand calculators that like to do things like raise numbers to high powers. Most graphing calculators can, but I don't always have one of those around.

The other thing I really appreciate is being able to work with rational numbers without introducing rounding error with floating point.

If I divide 3 by 4 in most calcualtors I would get .25. In lisp I get a fractional number of 3/4. In instances where you really care about rounding error this is a great feature.

The only down side is the calculation time. While I know I'm getting a good number, it can take a little longer. I have generated numbers multiple screens long. When you're dealing with these large numbers without loss you can get into trouble where you are maintaining accuracy you don't need.

For instance, in cryptography when you are trying to find C=PE (mod n) you can apply mod n to each step of finding PE. This keeps the number small enough to be operated upon.

Lisp may not be the best calculator around, but it sure helps get the job done when you need to operate on rational numbers.

1 comment:

Kalman said...

What's wrong with (exp 1.0d0) as a way to get e?