continued-fractions-0.9.0.1: Continued fractions.

Math.ContinuedFraction

Synopsis

# Documentation

data CF a Source

A continued fraction. Constructed by `cf` or `gcf`.

Instances

 Functor CF Show a => Show (CF a)

cf :: a -> [a] -> CF aSource

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

Apply an equivalence transformation that sets the partial numerators of a `CF` to the specfied values. If the input list is too short, the rest of the `CF` will be unscaled.

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

Apply an equivalence transformation that sets the partial denominators of a `CF` to the specfied values. If the input list is too short, the rest of the `CF` will be unscaled.

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

Computes the even and odd parts, respectively, of a `CF`. These are new `CF`s that have the even-indexed and odd-indexed convergents of the original, respectively.

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

Computes the even part of a `CF` (that is, a new `CF` whose convergents are the even-indexed convergents of the original).

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

Computes the odd part of a `CF` (that is, a new `CF` whose convergents are the odd-indexed convergents of the original).

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.