polynomial-0.7.2: Polynomials

Safe HaskellNone
LanguageHaskell98

Math.Polynomial

Synopsis

Documentation

data Endianness Source

Constructors

BE

Big-Endian (head is highest-order term)

LE

Little-Endian (head is const term)

data Poly a Source

Instances

Functor Poly 
(AdditiveGroup 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)) 
(Eq a, VectorSpace a, AdditiveGroup (Scalar a), Eq (Scalar a)) => VectorSpace (Poly a) 
AdditiveGroup a => AdditiveGroup (Poly a) 
type Scalar (Poly a) = Scalar a 

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

Make a Poly from a list of coefficients using the specified coefficient order.

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

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.

polyIsZero :: (Num a, Eq a) => Poly a -> Bool Source

polyIsOne :: (Num a, Eq a) => Poly a -> Bool Source

zero :: Poly a Source

The polynomial "0"

one :: (Num a, Eq a) => Poly a Source

The polynomial "1"

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

Given some constant k, construct the polynomial whose value is constantly k.

x :: (Num a, Eq a) => Poly a Source

The polynomial (in x) "x"

scalePoly :: (Num a, Eq a) => a -> Poly a -> Poly a Source

Given some scalar s and a polynomial f, computes the polynomial g such that:

evalPoly g x = s * evalPoly f x

negatePoly :: (Num a, Eq a) => Poly a -> Poly a Source

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 a Source

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 a Source

Given polynomials f and g, computes the polynomial h such that:

evalPoly h x = evalPoly f x + evalPoly g x

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

multPoly :: (Num a, Eq a) => Poly a -> Poly a -> Poly a Source

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 a Source

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

quotPoly :: (Fractional a, Eq a) => Poly a -> Poly a -> Poly a Source

remPoly :: (Fractional a, Eq a) => Poly a -> Poly a -> Poly a Source

evalPoly :: (Num a, Eq a) => Poly a -> a -> a Source

Evaluate a polynomial at a point or, equivalently, convert a polynomial to the function it represents. For example, evalPoly x = id and evalPoly (constPoly k) = const k.

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 a Source

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

gcdPoly :: (Fractional a, Eq a) => Poly a -> Poly a -> Poly a Source

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.

polyDeriv :: (Num a, Eq a) => Poly a -> Poly a Source

Compute the derivative of a polynomial.

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 a Source

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