| Copyright | (c) 2020 Andrew Lelechenko |
|---|---|
| License | BSD3 |
| Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Poly.Multi.Laurent
Description
Sparse multivariate Laurent polynomials.
Synopsis
- data MultiLaurent (v :: Type -> Type) (n :: Nat) a
- type VMultiLaurent (n :: Nat) a = MultiLaurent Vector n a
- type UMultiLaurent (n :: Nat) a = MultiLaurent Vector n a
- unMultiLaurent :: forall (v :: Type -> Type) (n :: Nat) a. MultiLaurent v n a -> (Vector n Int, MultiPoly v n a)
- toMultiLaurent :: forall (n :: Nat) (v :: Type -> Type) a. (KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> MultiPoly v n a -> MultiLaurent v n a
- monomial :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a
- scale :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a -> MultiLaurent v n a
- pattern X :: (Eq a, Semiring a, KnownNat n, 1 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a
- pattern Y :: (Eq a, Semiring a, KnownNat n, 2 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a
- pattern Z :: (Eq a, Semiring a, KnownNat n, 3 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a
- (^-) :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => MultiLaurent v n a -> Int -> MultiLaurent v n a
- eval :: forall a (v :: Type -> Type) (n :: Nat) (u :: Type -> Type). (Field a, Vector v (Vector n Word, a), Vector u a) => MultiLaurent v n a -> Vector u n a -> a
- subst :: forall a (n :: Nat) (v :: Type -> Type) (w :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a), Vector w (Vector n Word, a)) => MultiPoly v n a -> Vector n (MultiLaurent w n a) -> MultiLaurent w n a
- deriv :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Ring a, KnownNat n, Vector v (Vector n Word, a)) => Finite n -> MultiLaurent v n a -> MultiLaurent v n a
- segregate :: forall (m :: Nat) (v :: Type -> Type) a. (KnownNat m, Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => MultiLaurent v (1 + m) a -> VLaurent (MultiLaurent v m a)
- unsegregate :: forall (v :: Type -> Type) (m :: Nat) a. (KnownNat m, KnownNat (1 + m), Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => VLaurent (MultiLaurent v m a) -> MultiLaurent v (1 + m) a
Documentation
data MultiLaurent (v :: Type -> Type) (n :: Nat) a Source #
Sparse
Laurent polynomials
of n variables with coefficients from a,
backed by a Vector v (boxed, unboxed, storable, etc.).
Use the patterns X, Y, Z and the ^- operator for construction:
>>>(X + 1) + (Y^-1 - 1) :: VMultiLaurent 2 Integer1 * X + 1 * Y^-1>>>(X + 1) * (Z - X^-1) :: UMultiLaurent 3 Int1 * X * Z + 1 * Z + (-1) + (-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 MultiLaurent crucially
depends on specialisation of instances. Clients are strongly recommended
to compile with ghc-options: -fspecialise-aggressively and suggested to enable -O2.
Since: 0.5.0.0
Instances
type VMultiLaurent (n :: Nat) a = MultiLaurent Vector n a Source #
Multivariate Laurent polynomials backed by boxed vectors.
Since: 0.5.0.0
type UMultiLaurent (n :: Nat) a = MultiLaurent Vector n a Source #
Multivariate Laurent polynomials backed by unboxed vectors.
Since: 0.5.0.0
unMultiLaurent :: forall (v :: Type -> Type) (n :: Nat) a. MultiLaurent v n a -> (Vector n Int, MultiPoly v n a) Source #
Deconstruct a MultiLaurent polynomial into an offset (largest possible)
and a regular polynomial.
>>>unMultiLaurent (2 * X + 1 :: UMultiLaurent 2 Int)(Vector [0,0],2 * X + 1)>>>unMultiLaurent (1 + 2 * X^-1 :: UMultiLaurent 2 Int)(Vector [-1,0],1 * X + 2)>>>unMultiLaurent (2 * X^2 + X :: UMultiLaurent 2 Int)(Vector [1,0],2 * X + 1)>>>unMultiLaurent (0 :: UMultiLaurent 2 Int)(Vector [0,0],0)
Since: 0.5.0.0
toMultiLaurent :: forall (n :: Nat) (v :: Type -> Type) a. (KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> MultiPoly v n a -> MultiLaurent v n a Source #
Construct a MultiLaurent polynomial from an offset and a regular polynomial.
One can imagine it as scale, but allowing negative offsets.
>>>:set -XDataKinds>>>import Data.Vector.Generic.Sized (fromTuple)>>>toMultiLaurent (fromTuple (2, 0)) (2 * Data.Poly.Multi.X + 1) :: UMultiLaurent 2 Int2 * X^3 + 1 * X^2>>>toMultiLaurent (fromTuple (0, -2)) (2 * Data.Poly.Multi.X + 1) :: UMultiLaurent 2 Int2 * X * Y^-2 + 1 * Y^-2
monomial :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a Source #
Create a monomial from a power and a coefficient.
Since: 0.5.0.0
scale :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a -> MultiLaurent v n a Source #
Multiply a polynomial by a monomial, expressed as a power and a coefficient.
>>>:set -XDataKinds>>>import Data.Vector.Generic.Sized (fromTuple)>>>scale (fromTuple (1, 1)) 3 (X^-2 + Y) :: UMultiLaurent 2 Int3 * X * Y^2 + 3 * X^-1 * Y
Since: 0.5.0.0
pattern X :: (Eq a, Semiring a, KnownNat n, 1 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a Source #
Create a polynomial equal to the first variable.
Since: 0.5.0.0
pattern Y :: (Eq a, Semiring a, KnownNat n, 2 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a Source #
Create a polynomial equal to the second variable.
Since: 0.5.0.0
pattern Z :: (Eq a, Semiring a, KnownNat n, 3 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a Source #
Create a polynomial equal to the third variable.
Since: 0.5.0.0
(^-) :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => MultiLaurent v n a -> Int -> MultiLaurent v n 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 * Y^-1 :: UMultiLaurent 2 Int1 * X^-3 * Y^-1>>>3 * X^-1 + 2 * (Y^2)^-2 :: UMultiLaurent 2 Int2 * Y^-4 + 3 * X^-1
Since: 0.5.0.0
eval :: forall a (v :: Type -> Type) (n :: Nat) (u :: Type -> Type). (Field a, Vector v (Vector n Word, a), Vector u a) => MultiLaurent v n a -> Vector u n a -> a Source #
Evaluate the polynomial at a given point.
>>>:set -XDataKinds>>>import Data.Vector.Generic.Sized (fromTuple)>>>eval (X^2 + Y^-1 :: UMultiLaurent 2 Double) (fromTuple (3, 4) :: Data.Vector.Sized.Vector 2 Double)9.25
Since: 0.5.0.0
subst :: forall a (n :: Nat) (v :: Type -> Type) (w :: Type -> Type). (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a), Vector w (Vector n Word, a)) => MultiPoly v n a -> Vector n (MultiLaurent w n a) -> MultiLaurent w n a Source #
Substitute another polynomial instead of X.
>>>:set -XDataKinds>>>import Data.Vector.Generic.Sized (fromTuple)>>>import Data.Poly.Multi (UMultiPoly)>>>subst (Data.Poly.Multi.X * Data.Poly.Multi.Y :: UMultiPoly 2 Int) (fromTuple (X + Y^-1, Y + X^-1 :: UMultiLaurent 2 Int))1 * X * Y + 2 + 1 * X^-1 * Y^-1
Since: 0.5.0.0
deriv :: forall a (n :: Nat) (v :: Type -> Type). (Eq a, Ring a, KnownNat n, Vector v (Vector n Word, a)) => Finite n -> MultiLaurent v n a -> MultiLaurent v n a Source #
Take the derivative of the polynomial with respect to the i-th variable.
>>>:set -XDataKinds>>>deriv 0 (X^3 + 3 * Y) :: UMultiLaurent 2 Int3 * X^2>>>deriv 1 (X^3 + 3 * Y) :: UMultiLaurent 2 Int3
Since: 0.5.0.0
segregate :: forall (m :: Nat) (v :: Type -> Type) a. (KnownNat m, Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => MultiLaurent v (1 + m) a -> VLaurent (MultiLaurent v m a) Source #
Interpret a multivariate Laurent polynomial over 1+m variables as a univariate Laurent polynomial, whose coefficients are multivariate Laurent polynomials over the last m variables.
Since: 0.5.0.0
unsegregate :: forall (v :: Type -> Type) (m :: Nat) a. (KnownNat m, KnownNat (1 + m), Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => VLaurent (MultiLaurent v m a) -> MultiLaurent v (1 + m) a Source #
Interpret a univariate Laurent polynomials, whose coefficients are multivariate Laurent polynomials over the first m variables, as a multivariate polynomial over 1+m variables.
Since: 0.5.0.0