- data CF a
- cf :: a -> [a] -> CF a
- gcf :: a -> [(a, a)] -> CF a
- asCF :: Fractional a => CF a -> (a, [a])
- asGCF :: Num a => CF a -> (a, [(a, a)])
- truncateCF :: Int -> CF a -> CF a
- equiv :: Num a => [a] -> CF a -> CF a
- setNumerators :: Fractional a => [a] -> CF a -> CF a
- setDenominators :: Fractional a => [a] -> CF a -> CF a
- partitionCF :: Fractional a => CF a -> (CF a, CF a)
- evenCF :: Fractional a => CF a -> CF a
- oddCF :: Fractional a => CF a -> CF a
- convergents :: Fractional a => CF a -> [a]
- steed :: Fractional a => CF a -> [a]
- lentz :: Fractional a => CF a -> [a]
- modifiedLentz :: Fractional a => a -> CF a -> [[a]]
- sumPartialProducts :: Num a => [a] -> CF a

# Documentation

Construct a continued fraction from its first term and the partial denominators in its canonical form, which is the form where all the partial numerators are 1.

`cf a [b,c,d]`

corresponds to `a + (b / (1 + (c / (1 + d))))`

,
or to `GCF a [(1,b),(1,c),(1,d)]`

.

gcf :: a -> [(a, a)] -> CF aSource

Construct a continued fraction from its first term, its partial numerators and its partial denominators.

`gcf b0 [(a1,b1), (a2,b2), (a3,b3)]`

corresponds to
`b0 + (a1 / (b1 + (a2 / (b2 + (a3 / b3)))))`

asCF :: Fractional a => CF a -> (a, [a])Source

Extract the partial denominators of a `CF`

, normalizing it if necessary so
that all the partial numerators are 1.

asGCF :: Num a => CF a -> (a, [(a, a)])Source

Extract all the partial numerators and partial denominators of a `CF`

.

truncateCF :: Int -> CF a -> CF aSource

Truncate a `CF`

to the specified number of partial numerators and denominators.

equiv :: Num a => [a] -> CF a -> CF aSource

Apply an equivalence transformation, multiplying each partial denominator
with the corresponding element of the supplied list and transforming
subsequent partial numerators and denominators as necessary. If the list
is too short, the rest of the `CF`

will be unscaled.

setNumerators :: Fractional a => [a] -> CF a -> CF aSource

setDenominators :: Fractional a => [a] -> CF a -> CF aSource

partitionCF :: Fractional a => CF a -> (CF a, CF a)Source

evenCF :: Fractional a => CF a -> CF aSource

oddCF :: Fractional a => CF a -> CF aSource

convergents :: Fractional a => CF a -> [a]Source

Evaluate the convergents of a continued fraction using the fundamental recurrence formula:

A0 = b0, B0 = 1

A1 = b1b0 + a1, B1 = b1

A{n+1} = b{n+1}An + a{n+1}A{n-1}

B{n+1} = b{n+1}Bn + a{n+1}B{n-1}

The convergents are then Xn = An/Bn

steed :: Fractional a => CF a -> [a]Source

Evaluate the convergents of a continued fraction using Steed's method.
Only valid if the denominator in the following recurrence for D_i never
goes to zero. If this method blows up, try `modifiedLentz`

.

D1 = 1/b1

D{i} = 1 / (b{i} + a{i} * D{i-1})

dx1 = a1 / b1

dx{i} = (b{i} * D{i} - 1) * dx{i-1}

x0 = b0

x{i} = x{i-1} + dx{i}

The convergents are given by `scanl (+) b0 dxs`

lentz :: Fractional a => CF a -> [a]Source

Evaluate the convergents of a continued fraction using Lentz's method.
Only valid if the denominators in the following recurrence never go to
zero. If this method blows up, try `modifiedLentz`

.

C1 = b1 + a1 / b0

D1 = 1/b1

C{n} = b{n} + a{n} / C{n-1}

D{n} = 1 / (b{n} + a{n} * D{n-1})

The convergents are given by `scanl (*) b0 (zipWith (*) cs ds)`

modifiedLentz :: Fractional a => a -> CF a -> [[a]]Source

Evaluate the convergents of a continued fraction using Lentz's method,
(see `lentz`

) with the additional rule that if a denominator ever goes
to zero, it will be replaced by a (very small) number of your choosing,
typically 1e-30 or so (this modification was proposed by Thompson and
Barnett).

Additionally splits the resulting list of convergents into sublists, starting a new list every time the 'modification' is invoked.

sumPartialProducts :: Num a => [a] -> CF aSource

Euler's formula for computing `sum (map product (tail (inits xs)))`

.
Successive convergents of the resulting `CF`

are successive partial sums
in the series.