1. cfc main features

cfc is a text calculator. It can evaluate the continued fraction expansion of any expression containing arithmetic operations (+, -, *, /), sqrt(), rational, e, pi. It can also evaluate decimal expansion of any expression without any floating point calculus.

The algorithms used were first described by B. Gosper in Hakmem Report : http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html

You can also consult Gosper's Report : http://www.tweedledum.com/rwg/cfup.htm

J. Vuillemin also described these algorithms and wrote a Lisp implementation : http://hal.inria.fr/docs/00/07/57/92/PDF/RR-0760.pdf

There is a beautiful small article http://www.lix.polytechnique.fr/Labo/Ilan.Vardi/pseudo_code.ps by I. Vardi describing continued fractions arithmetic.

Notation : [a b c d e] represent : a+1/(b+1/(c+1/(d+1/e))).

This is an example of a session on unix :

$./cf_arith
>sqrt(2)+sqrt(3)
[3 6 1 5 7 1 1 4 1 38 43 1 3 2 1 1 1 1 2 4 1 4 5 1 5 1 7 22 2 5 1 1 2 1 1 31 2
1 1 3 1 44 1 89 1 8 5 2 5 1 1...]
>pi*sqrt(163)
[40 9 6 4 60 2 1 1 1 1 13 7 5 2 2 1 36 1 3 1 34 2 1 1 39 6 3 1 3 2 4 2 1 1 1 1
8 1 8 1 1 16 4 1 1 8 1 2 6 1 10...]
>[,1]-[,7]
[-6 2 10 1 5 1 3 1 6 2 16 2 21 3 1 1 1 1 4 6 2 3 8 1 2 1 40 1 1 6 1 1 3 3 2 1 1
 1 4 1 11 1 1 1 21 2 1 2 2 7 1...]
^d
$

The comma is used for periodical continued fraction : [1 2,3 4] represent [1 2 3 4 3 4 3 4 3 4…]

For instance, the golden ratio is [,1].

By default, the evaluated number of "digit" is 50 but you can change this number to 100 with :

>scale=100
ok
>pi-[3 7 16]
[-1 1 3748628 10 1 3 1 4 11 2 6 1 13 2 3 56 3 3 2 15 2 2 1 8 3 1 1 19 1 1 110 2
 18 103 1 2 3 1 384 9 7 1 1 2 3 2 1 2 1 1 1 50 1 1 29 1 4 6 2 3 1 1 6 1 1 1 1 1
 1 1 1 28 5 1 1 26 7 6 1 6 2 1 1 3 2 1 4 3 2 4 1 39 4 1 1 2 1 6 2 1 1...]

You can also evaluate decimal expansion:

>scale=50
ok
>output=decimal
ok
>[,1 2]
>[1.36602540378443864676372317075293618347140262690519...]
>-[,1]
>[-2+0.38196601125010515179541316563436188227969082019423...]
>output=contfrac
ok
>sqrt(13/3)
>[2 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4
12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4 12 4...]

cfc is written in C++.

It uses GMP : http://gmplib.org and lex/yacc.

TODO: affection with a lazzy evaluator, a garbage collector, transcendental functions like exp(), atan()…

2. Download cfc

sources : http://fbalsalobre.free.fr/software/cf_arith_v0.7.tar.gz (95 Kb) (Sep 24 2003)

3. Installation

To construct cf_arith on unix :

tar xvzf cf_arith_v0.7.tar.gz
cd cf_arith_v0.7
make

To run cf_arith on unix :

$./cf_arith

4. Contact

If you have any questions, bug reports or comments regarding cfc, please send e-mail to fbalsalobre@free.fr.

5. Copyright

Copyright © 2000, 2001, 2002, 2003 Francois Balsalobre

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA