The Maxima on-line user's manual

Algebra Calculator

Cf

Function: cf (<expr>) Converts <expr> into a continued fraction. <expr> is an expression comprising continued fractions and square roots of integers. Operands in the expression may be combined with arithmetic operators. Aside from continued fractions and square roots, factors in the expression must be integer or rational numbers. Maxima does not know about operations on continued fractions outside of `cf`.

`cf` evaluates its arguments after binding `listarith` to `false`. `cf` returns a continued fraction, represented as a list.

A continued fraction `a + 1/(b + 1/(c + ...))` is represented by the list `[a, b, c, ...]`. The list elements `a`, `b`, `c`, ... must evaluate to integers. <expr> may also contain `sqrt (n)` where `n` is an integer. In this case `cf` will give as many terms of the continued fraction as the value of the variable `cflength` times the period.

A continued fraction can be evaluated to a number by evaluating the arithmetic representation returned by `cfdisrep`. See also `cfexpand` for another way to evaluate a continued fraction.

See also `cfdisrep`, `cfexpand`, and `cflength`.

Examples:

* <expr> is an expression comprising continued fractions and square roots of integers.

```               (%i1) cf ([5, 3, 1]*[11, 9, 7] + [3, 7]/[4, 3, 2]);
(%o1)               [59, 17, 2, 1, 1, 1, 27]
(%i2) cf ((3/17)*[1, -2, 5]/sqrt(11) + (8/13));
(%o2)        [0, 1, 1, 1, 3, 2, 1, 4, 1, 9, 1, 9, 2]```

* `cflength` controls how many periods of the continued fraction are computed for algebraic, irrational numbers.

```               (%i1) cflength: 1\$
(%i2) cf ((1 + sqrt(5))/2);
(%o2)                    [1, 1, 1, 1, 2]
(%i3) cflength: 2\$
(%i4) cf ((1 + sqrt(5))/2);
(%o4)               [1, 1, 1, 1, 1, 1, 1, 2]
(%i5) cflength: 3\$
(%i6) cf ((1 + sqrt(5))/2);
(%o6)           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]```

* A continued fraction can be evaluated by evaluating the arithmetic representation returned by `cfdisrep`.

```               (%i1) cflength: 3\$
(%i2) cfdisrep (cf (sqrt (3)))\$
(%i3) ev (%, numer);
(%o3)                   1.731707317073171```

* Maxima does not know about operations on continued fractions outside of `cf`.

```               (%i1) cf ([1,1,1,1,1,2] * 3);
(%o1)                     [4, 1, 5, 2]
(%i2) cf ([1,1,1,1,1,2]) * 3;
(%o2)                  [3, 3, 3, 3, 3, 6]```

There are also some inexact matches for `cf`. Try `?? cf` to see them.

```(%o1)                                true
(%i2) ```

Related Examples

cf

cf (11111111113333333...

Calculate

cf-linsolve

eq1:vin*gm1+v1*(1/ro1...

eq2:v1*gm2+v2*(1/ro2+...

eq3:vo*(s*(cf+cnt)+1/...

Calculate

cf-sqrt

cf((1+sqrt(5))/2),cfl...

Calculate

cf

cf ([23,1,1,1,1,1,1,1...

cf ([29,1,1,1,1,1,1,1...

Calculate

cf-combine-linsolve

a:Fp/csp+dp+d4-(dr+dm...

b:Fp/csp+dp+d4-(dr+dm...

c:Fp/csp+dp+d4-(dr+dm...

Calculate

cf(sqrt(2!));

Calculate

cf (1/2);

Calculate

cf

cf([30841900527924414...

Calculate

? cf;

Calculate

cf-length-sqrt

length(cf(sqrt(30!)));

Calculate