- data Endianness
- data Poly a
- poly :: Num a => Endianness -> [a] -> Poly a
- polyCoeffs :: Num a => Endianness -> Poly a -> [a]
- polyIsZero :: Num a => Poly a -> Bool
- polyIsOne :: Num a => Poly a -> Bool
- zero :: Num a => Poly a
- one :: Num a => Poly a
- constPoly :: Num a => a -> Poly a
- x :: Num a => Poly a
- scalePoly :: Num a => a -> Poly a -> Poly a
- negatePoly :: Num a => Poly a -> Poly a
- composePoly :: Num a => Poly a -> Poly a -> Poly a
- addPoly :: Num a => Poly a -> Poly a -> Poly a
- sumPolys :: Num a => [Poly a] -> Poly a
- multPoly :: Num a => Poly a -> Poly a -> Poly a
- powPoly :: (Num a, Integral b) => Poly a -> b -> Poly a
- quotRemPoly :: Fractional a => Poly a -> Poly a -> (Poly a, Poly a)
- quotPoly :: Fractional a => Poly a -> Poly a -> Poly a
- remPoly :: Fractional a => Poly a -> Poly a -> Poly a
- evalPoly :: Num a => Poly a -> a -> a
- evalPolyDeriv :: Num a => Poly a -> a -> (a, a)
- evalPolyDerivs :: Num a => Poly a -> a -> [a]
- contractPoly :: Num a => Poly a -> a -> (Poly a, a)
- gcdPoly :: Fractional a => Poly a -> Poly a -> Poly a
- separateRoots :: Fractional a => Poly a -> [Poly a]
- polyDeriv :: Num a => Poly a -> Poly a
- polyIntegral :: Fractional a => Poly a -> Poly a

# Documentation

data Endianness Source

Functor Poly | |

(Num a, Eq a) => Eq (Poly a) | |

Num a => Num (Poly a) | |

Num a => Show (Poly a) | |

NFData a => NFData (Poly a) | |

(Pretty a, Num a, Ord a) => Pretty (Poly a) | |

(RealFloat a, Pretty (Complex a)) => Pretty (Poly (Complex a)) | |

VectorSpace a => VectorSpace (Poly a) | |

AdditiveGroup a => AdditiveGroup (Poly a) |

poly :: Num a => Endianness -> [a] -> Poly aSource

Make a `Poly`

from a list of coefficients using the specified coefficient order.

polyCoeffs :: Num a => Endianness -> Poly a -> [a]Source

Get the coefficients of a a `Poly`

in the specified order.

polyIsZero :: Num a => Poly a -> BoolSource

constPoly :: Num a => a -> Poly aSource

Given some constant `k`

, construct the polynomial whose value is
constantly `k`

.

scalePoly :: Num a => a -> Poly a -> Poly aSource

Given some scalar `s`

and a polynomial `f`

, computes the polynomial `g`

such that:

evalPoly g x = s * evalPoly f x

negatePoly :: Num a => Poly a -> Poly aSource

Given some polynomial `f`

, computes the polynomial `g`

such that:

evalPoly g x = negate (evalPoly f x)

composePoly :: Num a => Poly a -> Poly a -> Poly aSource

`composePoly f g`

constructs the polynomial `h`

such that:

evalPoly h = evalPoly f . evalPoly g

This is a very expensive operation and, in general, returns a polynomial
that is quite a bit more expensive to evaluate than `f`

and `g`

together
(because it is of a much higher order than either). Unless your
polynomials are quite small or you are quite certain you need the
coefficients of the composed polynomial, it is recommended that you
simply evaluate `f`

and `g`

and explicitly compose the resulting
functions. This will usually be much more efficient.

addPoly :: Num a => Poly a -> Poly a -> Poly aSource

Given polynomials `f`

and `g`

, computes the polynomial `h`

such that:

evalPoly h x = evalPoly f x + evalPoly g x

multPoly :: Num a => Poly a -> Poly a -> Poly aSource

Given polynomials `f`

and `g`

, computes the polynomial `h`

such that:

evalPoly h x = evalPoly f x * evalPoly g x

powPoly :: (Num a, Integral b) => Poly a -> b -> Poly aSource

Given a polynomial `f`

and exponent `n`

, computes the polynomial `g`

such that:

evalPoly g x = evalPoly f x ^ n

quotRemPoly :: Fractional a => Poly a -> Poly a -> (Poly a, Poly a)Source

Given polynomials `a`

and `b`

, with `b`

not `zero`

, computes polynomials
`q`

and `r`

such that:

addPoly (multPoly q b) r == a

evalPolyDeriv :: Num a => Poly a -> a -> (a, a)Source

Evaluate a polynomial and its derivative (respectively) at a point.

evalPolyDerivs :: Num a => Poly a -> a -> [a]Source

Evaluate a polynomial and all of its nonzero derivatives at a point. This is roughly equivalent to:

evalPolyDerivs p x = map (`evalPoly` x) (takeWhile (not . polyIsZero) (iterate polyDeriv p))

contractPoly :: Num a => Poly a -> a -> (Poly a, a)Source

"Contract" a polynomial by attempting to divide out a root.

`contractPoly p a`

returns `(q,r)`

such that `q*(x-a) + r == p`

gcdPoly :: Fractional a => Poly a -> Poly a -> Poly aSource

`gcdPoly a b`

computes the highest order monic polynomial that is a
divisor of both `a`

and `b`

. If both `a`

and `b`

are `zero`

, the
result is undefined.

separateRoots :: Fractional a => Poly a -> [Poly a]Source

Separate a nonzero polynomial into a set of factors none of which have multiple roots, and the product of which is the original polynomial. Note that if division is not exact, it may fail to separate roots. Rational coefficients is a good idea.

Useful when applicable as a way to simplify root-finding problems.

polyIntegral :: Fractional a => Poly a -> Poly aSource

Compute the definite integral (from 0 to x) of a polynomial.