| Copyright | (c) 2020 Andrew Lelechenko |
|---|---|
| License | BSD3 |
| Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Poly.Sparse.Laurent
Description
Sparse Laurent polynomials.
Since: 0.4.0.0
Synopsis
- type Laurent (v :: Type -> Type) a = MultiLaurent v 1 a
- type VLaurent a = Laurent Vector a
- type ULaurent a = Laurent Vector a
- unLaurent :: forall (v :: Type -> Type) a. Laurent v a -> (Int, Poly v a)
- toLaurent :: forall (v :: Type -> Type) a. Vector v (Vector 1 Word, a) => Int -> Poly v a -> Laurent v a
- leading :: forall (v :: Type -> Type) a. Vector v (Vector 1 Word, a) => Laurent v a -> Maybe (Int, a)
- monomial :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a
- scale :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a -> Laurent v a
- pattern X :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Laurent v a
- (^-) :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Laurent v a -> Int -> Laurent v a
- eval :: forall a (v :: Type -> Type). (Field a, Vector v (Vector 1 Word, a)) => Laurent v a -> a -> a
- subst :: forall a (v :: Type -> Type) (w :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a), Vector w (Vector 1 Word, a)) => Poly v a -> Laurent w a -> Laurent w a
- deriv :: forall a (v :: Type -> Type). (Eq a, Ring a, Vector v (Vector 1 Word, a)) => Laurent v a -> Laurent v a
Documentation
type Laurent (v :: Type -> Type) a = MultiLaurent v 1 a Source #
Laurent polynomials
of one variable with coefficients from a,
backed by a Vector v (boxed, unboxed, storable, etc.).
Use the pattern X and the ^- operator for construction:
>>>(X + 1) + (X^-1 - 1) :: VLaurent Integer1 * X + 1 * X^-1>>>(X + 1) * (1 - X^-1) :: ULaurent Int1 * X + (-1) * X^-1
Polynomials are stored normalized, without zero coefficients, so 0 * X + 1 + 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 Laurent crucially
depends on specialisation of instances. Clients are strongly recommended
to compile with ghc-options: -fspecialise-aggressively and suggested to enable -O2.
Since: 0.4.0.0
type VLaurent a = Laurent Vector a Source #
Laurent polynomials backed by boxed vectors.
Since: 0.4.0.0
type ULaurent a = Laurent Vector a Source #
Laurent polynomials backed by unboxed vectors.
Since: 0.4.0.0
unLaurent :: forall (v :: Type -> Type) a. Laurent v a -> (Int, Poly v a) Source #
Deconstruct a Laurent polynomial into an offset (largest possible)
and a regular polynomial.
>>>unLaurent (2 * X + 1 :: ULaurent Int)(0,2 * X + 1)>>>unLaurent (1 + 2 * X^-1 :: ULaurent Int)(-1,1 * X + 2)>>>unLaurent (2 * X^2 + X :: ULaurent Int)(1,2 * X + 1)>>>unLaurent (0 :: ULaurent Int)(0,0)
Since: 0.4.0.0
toLaurent :: forall (v :: Type -> Type) a. Vector v (Vector 1 Word, a) => Int -> Poly v a -> Laurent v a Source #
Construct a Laurent polynomial from an offset and a regular polynomial.
One can imagine it as scale, but allowing negative offsets.
>>>toLaurent 2 (2 * Data.Poly.Sparse.X + 1) :: ULaurent Int2 * X^3 + 1 * X^2>>>toLaurent (-2) (2 * Data.Poly.Sparse.X + 1) :: ULaurent Int2 * X^-1 + 1 * X^-2
Since: 0.4.0.0
leading :: forall (v :: Type -> Type) a. Vector v (Vector 1 Word, a) => Laurent v a -> Maybe (Int, a) Source #
Return the leading power and coefficient of a non-zero polynomial.
>>>leading ((2 * X + 1) * (2 * X^2 - 1) :: ULaurent Int)Just (3,4)>>>leading (0 :: ULaurent Int)Nothing
Since: 0.4.0.0
monomial :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a Source #
Create a monomial from a power and a coefficient.
Since: 0.4.0.0
scale :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a -> Laurent v a Source #
Multiply a polynomial by a monomial, expressed as a power and a coefficient.
>>>scale 2 3 (X^-2 + 1) :: ULaurent Int3 * X^2 + 3
Since: 0.4.0.0
(^-) :: forall a (v :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Laurent v a -> Int -> Laurent v a Source #
Used to construct monomials with negative powers.
This operator can be applied only to monomials with unit coefficients, but is instrumental to express Laurent polynomials in a mathematical fashion:
>>>X^-3 :: ULaurent Int1 * X^-3>>>X + 2 + 3 * (X^2)^-1 :: ULaurent Int1 * X + 2 + 3 * X^-2
Since: 0.4.0.0
eval :: forall a (v :: Type -> Type). (Field a, Vector v (Vector 1 Word, a)) => Laurent v a -> a -> a Source #
Evaluate the polynomial at a given point.
>>>eval (X^-2 + 1 :: ULaurent Double) 21.25
Since: 0.4.0.0
subst :: forall a (v :: Type -> Type) (w :: Type -> Type). (Eq a, Semiring a, Vector v (Vector 1 Word, a), Vector w (Vector 1 Word, a)) => Poly v a -> Laurent w a -> Laurent w a Source #
Substitute another polynomial instead of X.
>>>import Data.Poly.Sparse (UPoly)>>>subst (Data.Poly.Sparse.X^2 + 1 :: UPoly Int) (X^-1 + 1 :: ULaurent Int)2 + 2 * X^-1 + 1 * X^-2
Since: 0.4.0.0