math-functions-0.3.4.4: Collection of tools for numeric computations

Copyright | (c) 2016 Alexey Khudyakov
License | BSD3
Maintainer | alexey.skladnoy@gmail.com, bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Numeric.Series

Contents

- Data type for infinite sequences.
- Constructors
- Summation of series
- Evaluation of continued fractions

Description

Functions for working with infinite sequences. In particular summation of series and evaluation of continued fractions.

Synopsis

- data Sequence a = Sequence s (s -> (a, s))
- enumSequenceFrom :: Num a => a -> Sequence a
- enumSequenceFromStep :: Num a => a -> a -> Sequence a
- scanSequence :: (b -> a -> b) -> b -> Sequence a -> Sequence b
- sumSeries :: Sequence Double -> Double
- sumPowerSeries :: Double -> Sequence Double -> Double
- sequenceToList :: Sequence a -> [a]
- evalContFractionB :: Sequence (Double, Double) -> Double

# Data type for infinite sequences.

data Sequence a Source #

Infinite series. It's represented as opaque state and step function.

Constructors

Sequence s (s -> (a, s)) |

#### Instances

Instances details

Applicative Sequence Source # |
Instance details Defined in Numeric.Series Methods pure :: a -> Sequence a Source # (<*>) :: Sequence (a -> b) -> Sequence a -> Sequence b Source # liftA2 :: (a -> b -> c) -> Sequence a -> Sequence b -> Sequence c Source # (*>) :: Sequence a -> Sequence b -> Sequence b Source # (<*) :: Sequence a -> Sequence b -> Sequence a Source #
Functor Sequence Source # |
Instance details Defined in Numeric.Series Methods fmap :: (a -> b) -> Sequence a -> Sequence b Source # (<$) :: a -> Sequence b -> Sequence a Source #
Num a => Num (Sequence a) Source # | Elementwise operations with sequences
Instance details Defined in Numeric.Series Methods (+) :: Sequence a -> Sequence a -> Sequence a Source # (-) :: Sequence a -> Sequence a -> Sequence a Source # (*) :: Sequence a -> Sequence a -> Sequence a Source # negate :: Sequence a -> Sequence a Source # abs :: Sequence a -> Sequence a Source # signum :: Sequence a -> Sequence a Source # fromInteger :: Integer -> Sequence a Source #
Fractional a => Fractional (Sequence a) Source # | Elementwise operations with sequences
Instance details Defined in Numeric.Series Methods (/) :: Sequence a -> Sequence a -> Sequence a Source # recip :: Sequence a -> Sequence a Source # fromRational :: Rational -> Sequence a Source #

# Constructors

enumSequenceFrom :: Num a => a -> Sequence a Source #

`enumSequenceFrom x` generate sequence:

\[ a_n = x + n \]

enumSequenceFromStep :: Num a => a -> a -> Sequence a Source #

`enumSequenceFromStep x d` generate sequence:

\[ a_n = x + nd \]

scanSequence :: (b -> a -> b) -> b -> Sequence a -> Sequence b Source #

Analog of `scanl` for sequence.

# Summation of series

sumSeries :: Sequence Double -> Double Source #

Calculate sum of series

\[ \sum_{i=0}^\infty a_i \]

Summation is stopped when

\[ a_{n+1} < \varepsilon\sum_{i=0}^n a_i \]

where ε is machine precision (`m_epsilon`)

sumPowerSeries :: Double -> Sequence Double -> Double Source #

Calculate sum of series

\[ \sum_{i=0}^\infty x^ia_i \]

Calculation is stopped when next value in series is less than ε·sum.

sequenceToList :: Sequence a -> [a] Source #

Convert series to infinite list

# Evaluation of continued fractions

evalContFractionB :: Sequence (Double, Double) -> Double Source #

Evaluate continued fraction using modified Lentz algorithm. Sequence contain pairs (a[i],b[i]) which form following expression:

\[ b_0 + \frac{a_1}{b_1+\frac{a_2}{b_2+\frac{a_3}{b_3 + \cdots}}} \]

Modified Lentz algorithm is described in Numerical recipes 5.2 "Evaluation of Continued Fractions"