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

# Documentation

data Endianness Source

Functor Poly | |

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

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

Show 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, Eq a) => Endianness -> [a] -> Poly aSource

Make a `Poly`

from a list of coefficients using the specified coefficient order.

polyDegree :: (Num a, Eq a) => Poly a -> IntSource

Get the degree of a a `Poly`

(the highest exponent with nonzero coefficient)

polyCoeffs :: (Num a, Eq a) => Endianness -> Poly a -> [a]Source

Get the coefficients of a a `Poly`

in the specified order.

constPoly :: (Num a, Eq a) => a -> Poly aSource

Given some constant `k`

, construct the polynomial whose value is
constantly `k`

.

scalePoly :: (Num a, Eq 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, Eq 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, Eq 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, Eq 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, Eq 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, Eq 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, Eq a) => Poly a -> a -> (a, a)Source

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

evalPolyDerivs :: (Num a, Eq 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, Eq 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`

monicPoly :: (Fractional a, Eq a) => Poly a -> Poly aSource

Normalize a polynomial so that its highest-order coefficient is 1

gcdPoly :: (Fractional a, Eq 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, Eq 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.

polyDerivs :: (Num a, Eq a) => Poly a -> [Poly a]Source

Compute all nonzero derivatives of a polynomial, starting with its "zero'th derivative", the original polynomial itself.

polyIntegral :: (Fractional a, Eq a) => Poly a -> Poly aSource

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