Portability | portable |
---|---|

Stability | provisional |

Maintainer | ross@soi.city.ac.uk |

An example instance of the new classes: polynomials. Some of these functions work with infinite polynomials, i.e. formal power series.

- data Polynomial a
- polynomial :: [a] -> Polynomial a
- coefficients :: (Eq a, AbelianGroup a) => Polynomial a -> [a]
- degree :: (Eq a, AbelianGroup a) => Polynomial a -> Int
- evaluate :: Ring a => Polynomial a -> a -> a
- pretty :: (Ord a, Show a, Ring a) => Polynomial a -> String -> String
- approximations :: Ring a => Polynomial a -> a -> [a]
- compose :: Ring a => Polynomial a -> Polynomial a -> Polynomial a
- differentiate :: Ring a => Polynomial a -> Polynomial a
- integrate :: Field a => Polynomial a -> Polynomial a

# Polynomials

data Polynomial a Source

Functor Polynomial | |

(Eq a, AbelianGroup a) => Eq (Polynomial a) | |

(Eq a, Show a, AbelianGroup a) => Show (Polynomial a) | |

(Eq a, Field a) => EuclideanDomain (Polynomial a) | If |

Ring a => Ring (Polynomial a) | |

AbelianGroup a => AbelianGroup (Polynomial a) |

polynomial :: [a] -> Polynomial aSource

Construct a polynomial from a list of coefficients, least significant first.

# Queries

## Finite polynomials

coefficients :: (Eq a, AbelianGroup a) => Polynomial a -> [a]Source

The coefficients of a finite polynomial, least significant first and with no trailing zeroes.

degree :: (Eq a, AbelianGroup a) => Polynomial a -> IntSource

The degree of a finite polynomial.

`degree`

p = length (coefficients p)

evaluate :: Ring a => Polynomial a -> a -> aSource

Evaluate a polynomial for a given value of `x`

.

`evaluate`

a x =`zipWith`

(*) (`coefficients`

a) (`iterate`

(*x) 1)

(The implementation uses Horner's rule.)

pretty :: (Ord a, Show a, Ring a) => Polynomial a -> String -> StringSource

Pretty-print a polynomial, e.g.

pretty (polynomial [3, 4, 0, 1, 5]) "x" = "5x^4 + x^3 + 4x + 3"

## Formal power series

approximations :: Ring a => Polynomial a -> a -> [a]Source

The infinite list of evaluations of truncations of the polynomial or power series.

# Operations

compose :: Ring a => Polynomial a -> Polynomial a -> Polynomial aSource

differentiate :: Ring a => Polynomial a -> Polynomial aSource

Symbolic differentiation of polynomials.

integrate :: Field a => Polynomial a -> Polynomial aSource

Symbolic integration of polynomials.