#Polynomial Source

newtype Polynomial a

Finite-degree polynomials, with coefficients given by the type argument. So for example, a Polynomial Int is a polynomial with integer coefficients.

The Monoid instance works by considering polynomials as functions, where <> corresponds to function composition and the identity polynomial mempty is nothing more than the identity function P(x) = x.


#fromCoefficients Source

fromCoefficients :: forall a. Eq a => Semiring a => Array a -> Polynomial a

Construct a polynomial from coefficients. The constant coefficient comes first, so for example the polynomial x^4 + 2x^3 + 3x^2 + 4 could be constructed by writing fromCoefficients [4,3,2,1]. Any trailing zeros are ignored.

#coefficients Source

coefficients :: forall a. Polynomial a -> Array a

Inverse of fromCoefficients, up to trailing zeros.

#constant Source

constant :: forall a. Eq a => Semiring a => a -> Polynomial a

Create a polynomial with a single (given) term and no dependence in x: that is, a constant polynomial; one of degree 0.

#identity Source

identity :: forall a. Semiring a => Polynomial a

The identity polynomial; P(x) = x.

#evaluate Source

evaluate :: forall a. Semiring a => Polynomial a -> a -> a

Evaluate a polynomial by supplying a value for x.

#derivative Source

derivative :: Polynomial Number -> Polynomial Number

Gives the derivative of a polynomial. For example, the derivative of x^2 + 3x + 2 is 2x + 3.

antiderivative (fromCoefficients [2.0,3.0,1.0])
  == fromCoefficients [3.0,2.0]

#antiderivative Source

antiderivative :: Polynomial Number -> Polynomial Number

Gives the antiderivative of a particular polynomial having a constant term of 0. For example, an antiderivative of 2x + 3 is x^2 + 3x.

antiderivative (fromCoefficients [3.0,2.0])
  == fromCoefficients [0.0,3.0,1.0]

#innerProduct Source

innerProduct :: Polynomial Number -> Polynomial Number -> Number

We can consider the set of polynomials with real coefficients as a real vector space. In this case, this function defines an inner product given by the integral of the product of the arguments over the interval [0,1].

#norm Source

norm :: Polynomial Number -> Number

The square root of the inner product of a polynomial with itself.

#projection Source

projection :: Polynomial Number -> Polynomial Number -> Polynomial Number

Considering polynomials as vectors, projection p q gives the orthogonal projection of q onto p. If we let r = projection p q, then r satisfies the following properties:

  • innerProduct (q - r) p == 0.0 (approximately)
  • innerProduct p r == norm p * norm r, i.e. p and r are linearly dependent.

#pretty Source

pretty :: forall a. Show a => Semiring a => Eq a => Polynomial a -> String