| Copyright | (c) 2019 Andrew Lelechenko |
|---|---|
| License | BSD3 |
| Maintainer | Andrew Lelechenko <[email protected]> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Poly
Description
Dense polynomials and a Num-based interface.
Since: 0.1.0.0
Synopsis
- data Poly (v :: Type -> Type) a
- type VPoly = Poly Vector
- type UPoly = Poly Vector
- unPoly :: Poly v a -> v a
- leading :: forall (v :: Type -> Type) a. Vector v a => Poly v a -> Maybe (Word, a)
- toPoly :: (Eq a, Num a, Vector v a) => v a -> Poly v a
- monomial :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Word -> a -> Poly v a
- scale :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Word -> a -> Poly v a -> Poly v a
- pattern X :: (Eq a, Num a, Vector v a) => Poly v a
- eval :: forall a (v :: Type -> Type). (Num a, Vector v a) => Poly v a -> a -> a
- subst :: forall a (v :: Type -> Type) (w :: Type -> Type). (Eq a, Num a, Vector v a, Vector w a) => Poly v a -> Poly w a -> Poly w a
- deriv :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Poly v a -> Poly v a
- integral :: forall a (v :: Type -> Type). (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a
- quotRemFractional :: forall a (v :: Type -> Type). (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a -> (Poly v a, Poly v a)
- denseToSparse :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a
- sparseToDense :: forall a (v :: Type -> Type). (Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a
Documentation
data Poly (v :: Type -> Type) a Source #
Polynomials of one variable with coefficients from a,
backed by a Vector v (boxed, unboxed, storable, etc.).
Use the pattern X for construction:
>>>(X + 1) + (X - 1) :: VPoly Integer2 * X + 0>>>(X + 1) * (X - 1) :: UPoly Int1 * X^2 + 0 * X + (-1)
Polynomials are stored normalized, without leading
zero coefficients, so 0 * X + 1 equals to 1.
The Ord instance does not make much sense mathematically,
it is defined only for the sake of Set, Map, etc.
Due to being polymorphic by multiple axis, the performance of Poly crucially
depends on specialisation of instances. Clients are strongly recommended
to compile with ghc-options: -fspecialise-aggressively and suggested to enable -O2.
Since: 0.1.0.0
Instances
| NFData (v a) => NFData (Poly v a) Source # | Since: 0.3.2.0 |
Defined in Data.Poly.Internal.Dense | |
| (Eq a, Semiring a, Vector v a) => IsList (Poly v a) Source # | Since: 0.3.1.0 |
| (Eq a, Num a, Vector v a) => Num (Poly v a) Source # | |
| (Show a, Vector v a) => Show (Poly v a) Source # | |
| Eq (v a) => Eq (Poly v a) Source # | |
| Ord (v a) => Ord (Poly v a) Source # | |
Defined in Data.Poly.Internal.Dense | |
| (Eq a, Field a, Vector v a) => Euclidean (Poly v a) Source # | Note that Since: 0.3.0.0 |
| (Eq a, Ring a, GcdDomain a, Vector v a) => GcdDomain (Poly v a) Source # | Since: 0.3.0.0 |
| (Eq a, Ring a, Vector v a) => Ring (Poly v a) Source # | |
Defined in Data.Poly.Internal.Dense | |
| (Eq a, Semiring a, Vector v a) => Semiring (Poly v a) Source # | Note that |
| type Item (Poly v a) Source # | |
Defined in Data.Poly.Internal.Dense | |
unPoly :: Poly v a -> v a Source #
Convert a Poly to a vector of coefficients
(first element corresponds to the constant term).
Since: 0.1.0.0
leading :: forall (v :: Type -> Type) a. Vector v a => Poly v a -> Maybe (Word, a) Source #
Return the leading power and coefficient of a non-zero polynomial.
>>>leading ((2 * X + 1) * (2 * X^2 - 1) :: UPoly Int)Just (3,4)>>>leading (0 :: UPoly Int)Nothing
Since: 0.3.0.0
toPoly :: (Eq a, Num a, Vector v a) => v a -> Poly v a Source #
Make a Poly from a list of coefficients
(first element corresponds to the constant term).
>>>:set -XOverloadedLists>>>toPoly [1,2,3] :: VPoly Integer3 * X^2 + 2 * X + 1>>>toPoly [0,0,0] :: UPoly Int0
Since: 0.1.0.0
monomial :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Word -> a -> Poly v a Source #
Create a monomial from a power and a coefficient.
Since: 0.3.0.0
scale :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Word -> a -> Poly v a -> Poly v a Source #
Multiply a polynomial by a monomial, expressed as a power and a coefficient.
>>>scale 2 3 (X^2 + 1) :: UPoly Int3 * X^4 + 0 * X^3 + 3 * X^2 + 0 * X + 0
Since: 0.3.0.0
eval :: forall a (v :: Type -> Type). (Num a, Vector v a) => Poly v a -> a -> a Source #
Evaluate the polynomial at a given point.
>>>eval (X^2 + 1 :: UPoly Int) 310
Since: 0.2.0.0
subst :: forall a (v :: Type -> Type) (w :: Type -> Type). (Eq a, Num a, Vector v a, Vector w a) => Poly v a -> Poly w a -> Poly w a Source #
Substitute another polynomial instead of X.
>>>subst (X^2 + 1 :: UPoly Int) (X + 1 :: UPoly Int)1 * X^2 + 2 * X + 2
Since: 0.3.3.0
deriv :: forall a (v :: Type -> Type). (Eq a, Num a, Vector v a) => Poly v a -> Poly v a Source #
Take the derivative of the polynomial.
>>>deriv (X^3 + 3 * X) :: UPoly Int3 * X^2 + 0 * X + 3
Since: 0.2.0.0
integral :: forall a (v :: Type -> Type). (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a Source #
Compute an indefinite integral of the polynomial, setting the constant term to zero.
>>>integral (3 * X^2 + 3) :: UPoly Double1.0 * X^3 + 0.0 * X^2 + 3.0 * X + 0.0
Since: 0.2.0.0
quotRemFractional :: forall a (v :: Type -> Type). (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a -> (Poly v a, Poly v a) Source #
Polynomial division with remainder.
>>>quotRemFractional (X^3 + 2) (X^2 - 1 :: UPoly Double)(1.0 * X + 0.0,1.0 * X + 2.0)
Since: 0.5.0.0