# Free Ruby code

Applied Mathematics coded in Ruby. So far, only very limited
material is presented, all collected in a Ruby module named AppMath.
This is intended as a field of experimentation to find out
and define coding conventions and tools which allow algorithms of
applied mathematics and physics to be written in a manner that the
*precision*, that is the number of digits allowed for the *significand*
of a real number, is completely open.
In the present system, one needs a single statement
R.prec = 100 (for instance) to enforce throughout a floating point
number representation using 100 decimal digits for the significand
of a real number.
A statement
R.prec = 0
lets all real values represented by the standard Ruby type Float.
Notice that this is a fixation that is valid for all floating point calculations,
so that the precision has not to be inputted in each function call.
The user-interface is very much simpler than that of the GMP library.
Efficient arbitrary precision arithmetic is a very special topic.
The deeper functionality of class R (a class, what else?) is implemented on the basis
of class BigDecimal and module BigMath created by Shigeo Kobayashi.
What I added was an implementation of all elementary transcendental functions by rapidly
convergent series and a unification of R and Float (by extending the interface of Float)
so that in designing an algorithm one has not to decide which kind of floating point
machinery (and precision) to use for execution.
Notice that in R (and in the extended Float)the traditional functions are methods,
so that we write x.sin and not sin(x).
It is hard to believe how much this adds to the readability of algorithms!
The easiest way to test the present code system is to download the zip-file
all files zipped
and to unpack it into a directory from which you can access ruby.exe.
For some programs one needs also Tk.
There are presently three applications rnum_app.rb, linalg_app.rb, and kepler_2d_app.rb
which allow several selections.
For a fast and convenient information, visit the auto-generated documentation files
(rdoc files) for the various *.rb files to which the following points refer.
Notice that this kind of documentation allows reading the code for all methods and
other definitions.
That of method step! of class AppMath::Kepler2D is particularly beautyful.
Real number class R for arbitrary precision arithmetic and transcendental functions.
rdoc files
The paragraph 'Motivation and rational' in AppMath::R may be of particular
interest.
Complex number class C for arbitrary precision complex arithmetic and transcendental
functions.
rdoc files
Extending class Float in order to provide all methods of R
rdoc files
Classes Vec and Mat of vectors and matrices which cooperate with R and C.
Includes singular value decomposition (SVD) of real matrices (unfortunately not yet
for complex matrices).
rdoc files
Classes Graph and Graphs for graphical representation of functions via Tk.
It is striking to see the standard functions like sin or erf be
graphically represented
(see the screen shot functions)
when the algorithms for their evaluation are forced to
use only two-digits accuracy!
rdoc files
Class Iv of real intervals
rdoc files
Class Ran of random generators
rdoc files
Classes R2 and Kep2D dealing with the two-dimensional Kepler problem.
Here, the quantities, which for exact dynamics are constant in time
(energy, angular momentum, Runge-Lenz vector) are shown graphically
for a time-discrete simulation by means of the direct midpoint integrator.
See the screen shot Kepler.
It turns out that the non-constancy of the angular momentum in the
simulation is always by numerical noice (and thus becomes arbitrarily small
by working with 100 digits, 200 ditgits, .... For the other quantities
there are deviations from constancy which are due to the integrator mehod.
These become aritrarily small only if the time step of the simulation
becomes aritrarily small.
rdoc files
Last modification: 2014-04-22