Dear Ruby commuity,

this note deals with arbitrary precision arithmetics and Ruby

module BigMath and Ruby class BigDecimal.

So we are dealing with the mind children of Shigeo Kobayashi, and

my first action in promoting my proposed addition to BigMath was

to comunicate it to Shigeo.

His reply ends in the sentences:

'The only advice I can give you at this moment, is to annouce your

excelent work to Ruby community(open to any user).=20

=C2=A0...

I (and any Ruby user ) will be happy if your work is incorporated into

the BigMath library.'=20

This work defines and tests a wrapper class for Shigeo's class BigDecimal.

This wrapper makes the class fit into the framework of the standard Ruby

number classes Fixnum, Bignum, and Float by having

=C2=A0 Numeric

as its base class. The name which I propose for this class is

=C2=A0 R (which is standard mathematical usage),

other names that I considered were=20

=C2=A0 Real, BigReal, BigR.

The next unifying structural property of R ( besides R < Numeric) is that

it implements as member functions all the mathematical functions

=C2=A0 sqrt, hypot, sin, ... atan2, ... , erf, erfc

which module Math implements for class Float.

This is an interesting point:=20

Although in any OO-language terms containing calls of methods (member functi=

ons)

are cleaner and easier to read than calls of non-member functions, actual

language definitions prefer sin(x) to x.sin. Be this as it is, my class=20

R allows to write=20

=C2=A0 diff =3D x.sin**2 + x.cos**2 - 1=20

which is very small20for, say,=20

=C2=A0 x =3D R.new("1.23456789E123")

For this to work, one obviously needs to work with more than=20

the 123 decimals which come in already with the integer part of x.

So, for this computation, the default value of 40 decimals is too small.

We may set a sufficient accuracy by=20

=C2=A0 R.dig =3D 1000

On my system (an off-the shelf laptop) it takes then 6.7 seconds

to find diff.abs.log10.round as -876.

Algorithms for these mathematical functions which are suitable for

arbitrary precision are implemented in BigMath and BigDecimal based on

everywhere convergent power series expansions. Although such expansions -

take the well-knwn one for exp(x) as a prime example - converge by the=20

exponential growth of the denominators of the generic series term,

the growth of x^n may dominate the result for many, many, terms in the

early live of the series. So, such expansions are convergent rapidly only if

|x| < 1. What I did was to figure out the mathematical identities that

allow to reduce computing x.f for arbitrary x to fuction evalutions at

auxiliar arguments y satisfying |y| < 1. What is needed here, hardly

transcends the tricks which people of my generation had to exercise at schoo=

l

when working with logarithmic, exponential, and trigonometric functions

by means of printed tables instead of pocket calclators.

Of course, the question how to implement these functions by means of algorit=

hms

is independent of the question whether to use member functions or non-member

functions in their definition.=20

However, the20member function choice suggests a way of coping with=20

the number of allowed decimal places which is used in class R:=20

R has a class variable @@dig, the value of which (default is 40) controls th=

e actual

execution of any member function. It is not necessary to be aware of the fac=

t that=20

'deep inside' Shigeo's powers series algorithms different numbers of decimal

places may be used, according to the needs of the algorithm.

This may suffice as a first presentation of class R.

A complete package of Ruby code and rdoc-generated documentation can be foun=

d on

(and freely downloaded from)=20

=C2=A0

www.ulrichmutze.de
=C2=A0=20

where the section=20

=C2=A0 Free Ruby code

is the one which matters.

Every comment and suggestion for modification is wellcome!

Especially those that help to relate the present proposal to other projects

that add to he strength of Ruby as a tool in scientific computing.

Presently my idea is to make R a part of BigMath (it is a part of my=20

module AppMath, applied mathematics, in my present implementation) and to=20

become informed about the expectations that users of the BigMath library

may have concerning an arbitrary precision version of Float (which R in effe=

ct is).

Ulrich

__________________________________________________ ______________________

AOL eMail auf Ihrem Handy! Ab sofort k=C3=B6nnen Sie auch unterwegs Ihre AOL=

email abrufen. Registrieren Sie sich jetzt kostenlos.