-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Polynomials -- -- Polynomials backed by Vector. @package poly @version 0.5.0.0 -- | Dense polynomials and a Num-based interface. module Data.Poly -- | Polynomials of one variable with coefficients from a, backed -- by a Vector v (boxed, unboxed, storable, etc.). -- -- Use pattern X for construction: -- --
--   >>> (X + 1) + (X - 1) :: VPoly Integer
--   2 * X + 0
--   
--   >>> (X + 1) * (X - 1) :: UPoly Int
--   1 * X^2 + 0 * X + (-1)
--   
-- -- Polynomials are stored normalized, without leading zero coefficients, -- so 0 * X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data Poly (v :: Type -> Type) (a :: Type) -- | Polynomials backed by boxed vectors. type VPoly = Poly Vector -- | Polynomials backed by unboxed vectors. type UPoly = Poly Vector -- | Convert Poly to a vector of coefficients (first element -- corresponds to a constant term). unPoly :: Poly v a -> v a -- | Return a 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
--   
leading :: Vector v a => Poly v a -> Maybe (Word, a) -- | Make Poly from a list of coefficients (first element -- corresponds to a constant term). -- --
--   >>> :set -XOverloadedLists
--   
--   >>> toPoly [1,2,3] :: VPoly Integer
--   3 * X^2 + 2 * X + 1
--   
--   >>> toPoly [0,0,0] :: UPoly Int
--   0
--   
toPoly :: (Eq a, Num a, Vector v a) => v a -> Poly v a -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Num a, Vector v a) => Word -> a -> Poly v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^2 + 1) :: UPoly Int
--   3 * X^4 + 0 * X^3 + 3 * X^2 + 0 * X + 0
--   
scale :: (Eq a, Num a, Vector v a) => Word -> a -> Poly v a -> Poly v a -- | Create an identity polynomial. pattern X :: (Eq a, Num a, Vector v a) => Poly v a -- | Evaluate at a given point. -- --
--   >>> eval (X^2 + 1 :: UPoly Int) 3
--   10
--   
eval :: (Num a, Vector v a) => Poly v a -> a -> a -- | Substitute another polynomial instead of X. -- --
--   >>> subst (X^2 + 1 :: UPoly Int) (X + 1 :: UPoly Int)
--   1 * X^2 + 2 * X + 2
--   
subst :: (Eq a, Num a, Vector v a, Vector w a) => Poly v a -> Poly w a -> Poly w a -- | Take a derivative. -- --
--   >>> deriv (X^3 + 3 * X) :: UPoly Int
--   3 * X^2 + 0 * X + 3
--   
deriv :: (Eq a, Num a, Vector v a) => Poly v a -> Poly v a -- | Compute an indefinite integral of a polynomial, setting constant term -- to zero. -- --
--   >>> integral (3 * X^2 + 3) :: UPoly Double
--   1.0 * X^3 + 0.0 * X^2 + 3.0 * X + 0.0
--   
integral :: (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a -- | Polynomial division with remainder. -- --
--   >>> quotRemFractional (X^3 + 2) (X^2 - 1 :: UPoly Double)
--   (1.0 * X + 0.0,1.0 * X + 2.0)
--   
quotRemFractional :: (Eq a, Fractional a, Vector v a) => Poly v a -> Poly v a -> (Poly v a, Poly v a) -- | Convert from dense to sparse polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> denseToSparse (1 + Data.Poly.X^2) :: Data.Poly.Sparse.UPoly Int
--   1 * X^2 + 1
--   
denseToSparse :: (Eq a, Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Convert from sparse to dense polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> sparseToDense (1 + Data.Poly.Sparse.X^2) :: Data.Poly.UPoly Int
--   1 * X^2 + 0 * X + 1
--   
sparseToDense :: (Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Laurent polynomials. module Data.Poly.Laurent -- | Laurent polynomials of one variable with coefficients from -- a, backed by a Vector v (boxed, unboxed, -- storable, etc.). -- -- Use pattern X and operator ^- for construction: -- --
--   >>> (X + 1) + (X^-1 - 1) :: VLaurent Integer
--   1 * X + 0 + 1 * X^-1
--   
--   >>> (X + 1) * (1 - X^-1) :: ULaurent Int
--   1 * X + 0 + (-1) * X^-1
--   
-- -- Polynomials are stored normalized, without leading and trailing zero -- coefficients, so 0 * X + 1 + 0 * X^-1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data Laurent (v :: Type -> Type) (a :: Type) -- | Laurent polynomials backed by boxed vectors. type VLaurent = Laurent Vector -- | Laurent polynomials backed by unboxed vectors. type ULaurent = Laurent Vector -- | 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)
--   
unLaurent :: Laurent v a -> (Int, Poly v a) -- | Construct Laurent polynomial from an offset and a regular -- polynomial. One can imagine it as scale, but allowing negative -- offsets. -- --
--   >>> toLaurent 2 (2 * Data.Poly.X + 1) :: ULaurent Int
--   2 * X^3 + 1 * X^2
--   
--   >>> toLaurent (-2) (2 * Data.Poly.X + 1) :: ULaurent Int
--   2 * X^-1 + 1 * X^-2
--   
toLaurent :: (Eq a, Semiring a, Vector v a) => Int -> Poly v a -> Laurent v a -- | Return a 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
--   
leading :: Vector v a => Laurent v a -> Maybe (Int, a) -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Semiring a, Vector v a) => Int -> a -> Laurent v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^-2 + 1) :: ULaurent Int
--   3 * X^2 + 0 * X + 3
--   
scale :: (Eq a, Semiring a, Vector v a) => Int -> a -> Laurent v a -> Laurent v a -- | Create an identity polynomial. pattern X :: (Eq a, Semiring a, Vector v a) => Laurent v a -- | This operator can be applied only to monomials with unit coefficients, -- but is instrumental to express Laurent polynomials in mathematical -- fashion: -- --
--   >>> X + 2 + 3 * (X^2)^-1 :: ULaurent Int
--   1 * X + 2 + 0 * X^-1 + 3 * X^-2
--   
(^-) :: (Eq a, Num a, Vector v a) => Laurent v a -> Int -> Laurent v a -- | Evaluate at a given point. -- --
--   >>> eval (X^-2 + 1 :: ULaurent Double) 2
--   1.25
--   
eval :: (Field a, Vector v a) => Laurent v a -> a -> a -- | Substitute another polynomial instead of X. -- --
--   >>> import Data.Poly (UPoly)
--   
--   >>> subst (Data.Poly.X^2 + 1 :: UPoly Int) (X^-1 + 1 :: ULaurent Int)
--   2 + 2 * X^-1 + 1 * X^-2
--   
subst :: (Eq a, Semiring a, Vector v a, Vector w a) => Poly v a -> Laurent w a -> Laurent w a -- | Take a derivative. -- --
--   >>> deriv (X^-1 + 3 * X) :: ULaurent Int
--   3 + 0 * X^-1 + (-1) * X^-2
--   
deriv :: (Eq a, Ring a, Vector v a) => Laurent v a -> Laurent v a -- | Sparse multivariate polynomials with Num instance. module Data.Poly.Multi -- | Sparse polynomials of n variables with coefficients from -- a, backed by a Vector v (boxed, unboxed, -- storable, etc.). -- -- Use patterns X, Y and Z for construction: -- --
--   >>> :set -XDataKinds
--   
--   >>> (X + 1) + (Y - 1) + Z :: VMultiPoly 3 Integer
--   1 * X + 1 * Y + 1 * Z
--   
--   >>> (X + 1) * (Y - 1) :: UMultiPoly 2 Int
--   1 * X * Y + (-1) * X + 1 * Y + (-1)
--   
-- -- Polynomials are stored normalized, without zero coefficients, so 0 * -- X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data MultiPoly (v :: Type -> Type) (n :: Nat) (a :: Type) -- | Multivariate polynomials backed by boxed vectors. type VMultiPoly (n :: Nat) (a :: Type) = MultiPoly Vector n a -- | Multivariate polynomials backed by unboxed vectors. type UMultiPoly (n :: Nat) (a :: Type) = MultiPoly Vector n a -- | Convert MultiPoly to a vector of (powers, coefficient) pairs. unMultiPoly :: MultiPoly v n a -> v (Vector n Word, a) -- | Make MultiPoly from a list of (powers, coefficient) pairs. -- --
--   >>> :set -XOverloadedLists -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> toMultiPoly [(fromTuple (0,0),1),(fromTuple (0,1),2),(fromTuple (1,0),3)] :: VMultiPoly 2 Integer
--   3 * X + 2 * Y + 1
--   
--   >>> toMultiPoly [(fromTuple (0,0),0),(fromTuple (0,1),0),(fromTuple (1,0),0)] :: UMultiPoly 2 Int
--   0
--   
toMultiPoly :: (Eq a, Num a, Vector v (Vector n Word, a)) => v (Vector n Word, a) -> MultiPoly v n a -- | Create a monomial from powers and a coefficient. monomial :: (Eq a, Num a, Vector v (Vector n Word, a)) => Vector n Word -> a -> MultiPoly v n a -- | Multiply a polynomial by a monomial, expressed as powers and a -- coefficient. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> scale (fromTuple (1, 1)) 3 (X^2 + Y) :: UMultiPoly 2 Int
--   3 * X^3 * Y + 3 * X * Y^2
--   
scale :: (Eq a, Num a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Word -> a -> MultiPoly v n a -> MultiPoly v n a -- | Create a polynomial equal to the first variable. pattern X :: (Eq a, Num a, KnownNat n, 1 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Create a polynomial equal to the second variable. pattern Y :: (Eq a, Num a, KnownNat n, 2 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Create a polynomial equal to the third variable. pattern Z :: (Eq a, Num a, KnownNat n, 3 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Evaluate at a given point. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> eval (X^2 + Y^2 :: UMultiPoly 2 Int) (fromTuple (3, 4) :: Data.Vector.Sized.Vector 2 Int)
--   25
--   
eval :: (Num a, Vector v (Vector n Word, a), Vector u a) => MultiPoly v n a -> Vector u n a -> a -- | Substitute another polynomials instead of variables. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> subst (X^2 + Y^2 + Z^2 :: UMultiPoly 3 Int) (fromTuple (X + 1, Y + 1, X + Y :: UMultiPoly 2 Int))
--   2 * X^2 + 2 * X * Y + 2 * X + 2 * Y^2 + 2 * Y + 2
--   
subst :: (Eq a, Num a, KnownNat m, Vector v (Vector n Word, a), Vector w (Vector m Word, a)) => MultiPoly v n a -> Vector n (MultiPoly w m a) -> MultiPoly w m a -- | Take a derivative with respect to the i-th variable. -- --
--   >>> :set -XDataKinds
--   
--   >>> deriv 0 (X^3 + 3 * Y) :: UMultiPoly 2 Int
--   3 * X^2
--   
--   >>> deriv 1 (X^3 + 3 * Y) :: UMultiPoly 2 Int
--   3
--   
deriv :: (Eq a, Num a, Vector v (Vector n Word, a)) => Finite n -> MultiPoly v n a -> MultiPoly v n a -- | Compute an indefinite integral of a polynomial by the i-th -- variable, setting constant term to zero. -- --
--   >>> :set -XDataKinds
--   
--   >>> integral 0 (3 * X^2 + 2 * Y) :: UMultiPoly 2 Double
--   1.0 * X^3 + 2.0 * X * Y
--   
--   >>> integral 1 (3 * X^2 + 2 * Y) :: UMultiPoly 2 Double
--   3.0 * X^2 * Y + 1.0 * Y^2
--   
integral :: (Fractional a, Vector v (Vector n Word, a)) => Finite n -> MultiPoly v n a -> MultiPoly v n a -- | Interpret a multivariate polynomial over 1+m variables as a -- univariate polynomial, whose coefficients are multivariate polynomials -- over the last m variables. segregate :: (Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => MultiPoly v (1 + m) a -> VPoly (MultiPoly v m a) -- | Interpret a univariate polynomials, whose coefficients are -- multivariate polynomials over the first m variables, as a -- multivariate polynomial over 1+m variables. unsegregate :: (Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => VPoly (MultiPoly v m a) -> MultiPoly v (1 + m) a -- | Sparse multivariate Laurent polynomials. module Data.Poly.Multi.Laurent -- | Sparse Laurent polynomials of n variables with -- coefficients from a, backed by a Vector v -- (boxed, unboxed, storable, etc.). -- -- Use patterns X, Y, Z and operator ^- for -- construction: -- --
--   >>> (X + 1) + (Y^-1 - 1) :: VMultiLaurent 2 Integer
--   1 * X + 1 * Y^-1
--   
--   >>> (X + 1) * (Z - X^-1) :: UMultiLaurent 3 Int
--   1 * 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. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data MultiLaurent (v :: Type -> Type) (n :: Nat) (a :: Type) -- | Multivariate Laurent polynomials backed by boxed vectors. type VMultiLaurent (n :: Nat) (a :: Type) = MultiLaurent Vector n a -- | Multivariate Laurent polynomials backed by unboxed vectors. type UMultiLaurent (n :: Nat) (a :: Type) = MultiLaurent Vector n a -- | 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)
--   
unMultiLaurent :: MultiLaurent v n a -> (Vector n Int, MultiPoly v n a) -- | Construct 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 Int
--   2 * X^3 + 1 * X^2
--   
--   >>> toMultiLaurent (fromTuple (0, -2)) (2 * Data.Poly.Multi.X + 1) :: UMultiLaurent 2 Int
--   2 * X * Y^-2 + 1 * Y^-2
--   
toMultiLaurent :: (KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> MultiPoly v n a -> MultiLaurent v n a -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a -- | 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 Int
--   3 * X * Y^2 + 3 * X^-1 * Y
--   
scale :: (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Int -> a -> MultiLaurent v n a -> MultiLaurent v n a -- | Create a polynomial equal to the first variable. pattern X :: (Eq a, Semiring a, KnownNat n, 1 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a -- | Create a polynomial equal to the second variable. pattern Y :: (Eq a, Semiring a, KnownNat n, 2 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a -- | Create a polynomial equal to the third variable. pattern Z :: (Eq a, Semiring a, KnownNat n, 3 <= n, Vector v (Vector n Word, a)) => MultiLaurent v n a -- | This operator can be applied only to monomials with unit coefficients, -- but is still instrumental to express Laurent polynomials in -- mathematical fashion: -- --
--   >>> 3 * X^-1 + 2 * (Y^2)^-2 :: UMultiLaurent 2 Int
--   2 * Y^-4 + 3 * X^-1
--   
(^-) :: (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => MultiLaurent v n a -> Int -> MultiLaurent v n a -- | Evaluate 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
--   
eval :: (Field a, Vector v (Vector n Word, a), Vector u a) => MultiLaurent v n a -> Vector u n a -> a -- | 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
--   
subst :: (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 -- | Take a derivative with respect to the i-th variable. -- --
--   >>> :set -XDataKinds
--   
--   >>> deriv 0 (X^3 + 3 * Y) :: UMultiLaurent 2 Int
--   3 * X^2
--   
--   >>> deriv 1 (X^3 + 3 * Y) :: UMultiLaurent 2 Int
--   3
--   
deriv :: (Eq a, Ring a, KnownNat n, Vector v (Vector n Word, a)) => Finite n -> MultiLaurent v n a -> MultiLaurent v n a -- | 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. segregate :: (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) -- | Interpret a univariate Laurent polynomials, whose coefficients are -- multivariate Laurent polynomials over the first m variables, as -- a multivariate polynomial over 1+m variables. unsegregate :: forall v m 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 -- | Sparse multivariate polynomials with Semiring instance. module Data.Poly.Multi.Semiring -- | Sparse polynomials of n variables with coefficients from -- a, backed by a Vector v (boxed, unboxed, -- storable, etc.). -- -- Use patterns X, Y and Z for construction: -- --
--   >>> :set -XDataKinds
--   
--   >>> (X + 1) + (Y - 1) + Z :: VMultiPoly 3 Integer
--   1 * X + 1 * Y + 1 * Z
--   
--   >>> (X + 1) * (Y - 1) :: UMultiPoly 2 Int
--   1 * X * Y + (-1) * X + 1 * Y + (-1)
--   
-- -- Polynomials are stored normalized, without zero coefficients, so 0 * -- X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data MultiPoly (v :: Type -> Type) (n :: Nat) (a :: Type) -- | Multivariate polynomials backed by boxed vectors. type VMultiPoly (n :: Nat) (a :: Type) = MultiPoly Vector n a -- | Multivariate polynomials backed by unboxed vectors. type UMultiPoly (n :: Nat) (a :: Type) = MultiPoly Vector n a -- | Convert MultiPoly to a vector of (powers, coefficient) pairs. unMultiPoly :: MultiPoly v n a -> v (Vector n Word, a) -- | Make MultiPoly from a list of (powers, coefficient) pairs. -- --
--   >>> :set -XOverloadedLists -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> toMultiPoly [(fromTuple (0,0),1),(fromTuple (0,1),2),(fromTuple (1,0),3)] :: VMultiPoly 2 Integer
--   3 * X + 2 * Y + 1
--   
--   >>> toMultiPoly [(fromTuple (0,0),0),(fromTuple (0,1),0),(fromTuple (1,0),0)] :: UMultiPoly 2 Int
--   0
--   
toMultiPoly :: (Eq a, Semiring a, Vector v (Vector n Word, a)) => v (Vector n Word, a) -> MultiPoly v n a -- | Create a monomial from powers and a coefficient. monomial :: (Eq a, Semiring a, Vector v (Vector n Word, a)) => Vector n Word -> a -> MultiPoly v n a -- | Multiply a polynomial by a monomial, expressed as powers and a -- coefficient. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> scale (fromTuple (1, 1)) 3 (X^2 + Y) :: UMultiPoly 2 Int
--   3 * X^3 * Y + 3 * X * Y^2
--   
scale :: (Eq a, Semiring a, KnownNat n, Vector v (Vector n Word, a)) => Vector n Word -> a -> MultiPoly v n a -> MultiPoly v n a -- | Create a polynomial equal to the first variable. pattern X :: (Eq a, Semiring a, KnownNat n, 1 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Create a polynomial equal to the second variable. pattern Y :: (Eq a, Semiring a, KnownNat n, 2 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Create a polynomial equal to the third variable. pattern Z :: (Eq a, Semiring a, KnownNat n, 3 <= n, Vector v (Vector n Word, a)) => MultiPoly v n a -- | Evaluate at a given point. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> eval (X^2 + Y^2 :: UMultiPoly 2 Int) (fromTuple (3, 4) :: Data.Vector.Sized.Vector 2 Int)
--   25
--   
eval :: (Semiring a, Vector v (Vector n Word, a), Vector u a) => MultiPoly v n a -> Vector u n a -> a -- | Substitute another polynomials instead of variables. -- --
--   >>> :set -XDataKinds
--   
--   >>> import Data.Vector.Generic.Sized (fromTuple)
--   
--   >>> subst (X^2 + Y^2 + Z^2 :: UMultiPoly 3 Int) (fromTuple (X + 1, Y + 1, X + Y :: UMultiPoly 2 Int))
--   2 * X^2 + 2 * X * Y + 2 * X + 2 * Y^2 + 2 * Y + 2
--   
subst :: (Eq a, Semiring a, KnownNat m, Vector v (Vector n Word, a), Vector w (Vector m Word, a)) => MultiPoly v n a -> Vector n (MultiPoly w m a) -> MultiPoly w m a -- | Take a derivative with respect to the i-th variable. -- --
--   >>> :set -XDataKinds
--   
--   >>> deriv 0 (X^3 + 3 * Y) :: UMultiPoly 2 Int
--   3 * X^2
--   
--   >>> deriv 1 (X^3 + 3 * Y) :: UMultiPoly 2 Int
--   3
--   
deriv :: (Eq a, Semiring a, Vector v (Vector n Word, a)) => Finite n -> MultiPoly v n a -> MultiPoly v n a -- | Compute an indefinite integral of a polynomial by the i-th -- variable, setting constant term to zero. -- --
--   >>> :set -XDataKinds
--   
--   >>> integral 0 (3 * X^2 + 2 * Y) :: UMultiPoly 2 Double
--   1.0 * X^3 + 2.0 * X * Y
--   
--   >>> integral 1 (3 * X^2 + 2 * Y) :: UMultiPoly 2 Double
--   3.0 * X^2 * Y + 1.0 * Y^2
--   
integral :: (Field a, Vector v (Vector n Word, a)) => Finite n -> MultiPoly v n a -> MultiPoly v n a -- | Interpret a multivariate polynomial over 1+m variables as a -- univariate polynomial, whose coefficients are multivariate polynomials -- over the last m variables. segregate :: (Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => MultiPoly v (1 + m) a -> VPoly (MultiPoly v m a) -- | Interpret a univariate polynomials, whose coefficients are -- multivariate polynomials over the first m variables, as a -- multivariate polynomial over 1+m variables. unsegregate :: (Vector v (Vector (1 + m) Word, a), Vector v (Vector m Word, a)) => VPoly (MultiPoly v m a) -> MultiPoly v (1 + m) a -- | Dense polynomials and a Semiring-based interface. module Data.Poly.Semiring -- | Polynomials of one variable with coefficients from a, backed -- by a Vector v (boxed, unboxed, storable, etc.). -- -- Use pattern X for construction: -- --
--   >>> (X + 1) + (X - 1) :: VPoly Integer
--   2 * X + 0
--   
--   >>> (X + 1) * (X - 1) :: UPoly Int
--   1 * X^2 + 0 * X + (-1)
--   
-- -- Polynomials are stored normalized, without leading zero coefficients, -- so 0 * X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. data Poly (v :: Type -> Type) (a :: Type) -- | Polynomials backed by boxed vectors. type VPoly = Poly Vector -- | Polynomials backed by unboxed vectors. type UPoly = Poly Vector -- | Convert Poly to a vector of coefficients (first element -- corresponds to a constant term). unPoly :: Poly v a -> v a -- | Return a 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
--   
leading :: Vector v a => Poly v a -> Maybe (Word, a) -- | Make Poly from a vector of coefficients (first element -- corresponds to a constant term). -- --
--   >>> :set -XOverloadedLists
--   
--   >>> toPoly [1,2,3] :: VPoly Integer
--   3 * X^2 + 2 * X + 1
--   
--   >>> toPoly [0,0,0] :: UPoly Int
--   0
--   
toPoly :: (Eq a, Semiring a, Vector v a) => v a -> Poly v a -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Semiring a, Vector v a) => Word -> a -> Poly v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^2 + 1) :: UPoly Int
--   3 * X^4 + 0 * X^3 + 3 * X^2 + 0 * X + 0
--   
scale :: (Eq a, Semiring a, Vector v a) => Word -> a -> Poly v a -> Poly v a -- | Create an identity polynomial. pattern X :: (Eq a, Semiring a, Vector v a) => Poly v a -- | Evaluate at a given point. -- --
--   >>> eval (X^2 + 1 :: UPoly Int) 3
--   10
--   
eval :: (Semiring a, Vector v a) => Poly v a -> a -> a -- | Substitute another polynomial instead of X. -- --
--   >>> subst (X^2 + 1 :: UPoly Int) (X + 1 :: UPoly Int)
--   1 * X^2 + 2 * X + 2
--   
subst :: (Eq a, Semiring a, Vector v a, Vector w a) => Poly v a -> Poly w a -> Poly w a -- | Take a derivative. -- --
--   >>> deriv (X^3 + 3 * X) :: UPoly Int
--   3 * X^2 + 0 * X + 3
--   
deriv :: (Eq a, Semiring a, Vector v a) => Poly v a -> Poly v a -- | Compute an indefinite integral of a polynomial, setting constant term -- to zero. -- --
--   >>> integral (3 * X^2 + 3) :: UPoly Double
--   1.0 * X^3 + 0.0 * X^2 + 3.0 * X + 0.0
--   
integral :: (Eq a, Field a, Vector v a) => Poly v a -> Poly v a -- | Convert from dense to sparse polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> denseToSparse (1 `plus` Data.Poly.X^2) :: Data.Poly.Sparse.UPoly Int
--   1 * X^2 + 1
--   
denseToSparse :: (Eq a, Semiring a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Convert from sparse to dense polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> sparseToDense (1 `plus` Data.Poly.Sparse.X^2) :: Data.Poly.UPoly Int
--   1 * X^2 + 0 * X + 1
--   
sparseToDense :: (Semiring a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Discrete Fourier transform <math>. dft :: (Ring a, Vector v a) => a -> v a -> v a -- | Inverse discrete Fourier transform <math>. inverseDft :: (Field a, Vector v a) => a -> v a -> v a -- | Multiplication of polynomials using discrete Fourier transform. -- It could be faster than '(*)' for large polynomials if multiplication -- of coefficients is particularly expensive. dftMult :: (Eq a, Field a, Vector v a) => (Int -> a) -> Poly v a -> Poly v a -> Poly v a -- | Classical orthogonal polynomials. module Data.Poly.Orthogonal -- | Legendre polynomials. -- --
--   >>> take 3 legendre :: [Data.Poly.VPoly Double]
--   [1.0,1.0 * X + 0.0,1.5 * X^2 + 0.0 * X + (-0.5)]
--   
legendre :: (Eq a, Field a, Vector v a) => [Poly v a] -- | Shifted Legendre polynomials. -- --
--   >>> take 3 legendreShifted :: [Data.Poly.VPoly Integer]
--   [1,2 * X + (-1),6 * X^2 + (-6) * X + 1]
--   
legendreShifted :: (Eq a, Euclidean a, Ring a, Vector v a) => [Poly v a] -- | Gegenbauer polynomials. gegenbauer :: (Eq a, Field a, Vector v a) => a -> [Poly v a] -- | Jacobi polynomials. jacobi :: (Eq a, Field a, Vector v a) => a -> a -> [Poly v a] -- | Chebyshev polynomials of the first kind. -- --
--   >>> take 3 chebyshev1 :: [VPoly Integer]
--   [1,1 * X + 0,2 * X^2 + 0 * X + (-1)]
--   
chebyshev1 :: (Eq a, Ring a, Vector v a) => [Poly v a] -- | Chebyshev polynomials of the second kind. -- --
--   >>> take 3 chebyshev2 :: [VPoly Integer]
--   [1,2 * X + 0,4 * X^2 + 0 * X + (-1)]
--   
chebyshev2 :: (Eq a, Ring a, Vector v a) => [Poly v a] -- | Probabilists' Hermite polynomials. -- --
--   >>> take 3 hermiteProb :: [VPoly Integer]
--   [1,1 * X + 0,1 * X^2 + 0 * X + (-1)]
--   
hermiteProb :: (Eq a, Ring a, Vector v a) => [Poly v a] -- | Physicists' Hermite polynomials. -- --
--   >>> take 3 hermitePhys :: [VPoly Double]
--   [1.0,2.0 * X + 0.0,4.0 * X^2 + 0.0 * X + (-2.0)]
--   
hermitePhys :: (Eq a, Ring a, Vector v a) => [Poly v a] -- | Laguerre polynomials. -- --
--   >>> take 3 laguerre :: [VPoly Double]
--   [1.0,(-1.0) * X + 1.0,0.5 * X^2 + (-2.0) * X + 1.0]
--   
laguerre :: (Eq a, Field a, Vector v a) => [Poly v a] -- | Generalized Laguerre polynomials laguerreGen :: (Eq a, Field a, Vector v a) => a -> [Poly v a] -- | Sparse polynomials with Num instance. module Data.Poly.Sparse -- | Sparse univariate polynomials with coefficients from a, -- backed by a Vector v (boxed, unboxed, storable, etc.). -- -- Use pattern X for construction: -- --
--   >>> (X + 1) + (X - 1) :: VPoly Integer
--   2 * X
--   
--   >>> (X + 1) * (X - 1) :: UPoly Int
--   1 * X^2 + (-1)
--   
-- -- Polynomials are stored normalized, without zero coefficients, so 0 * -- X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. type Poly (v :: Type -> Type) (a :: Type) = MultiPoly v 1 a -- | Polynomials backed by boxed vectors. type VPoly (a :: Type) = Poly Vector a -- | Polynomials backed by unboxed vectors. type UPoly (a :: Type) = Poly Vector a -- | Convert Poly to a vector of coefficients. unPoly :: (Vector v (Word, a), Vector v (Vector 1 Word, a)) => Poly v a -> v (Word, a) -- | Make Poly from a list of (power, coefficient) pairs. -- --
--   >>> :set -XOverloadedLists
--   
--   >>> toPoly [(0,1),(1,2),(2,3)] :: VPoly Integer
--   3 * X^2 + 2 * X + 1
--   
--   >>> toPoly [(0,0),(1,0),(2,0)] :: UPoly Int
--   0
--   
toPoly :: (Eq a, Num a, Vector v (Word, a), Vector v (Vector 1 Word, a)) => v (Word, a) -> Poly v a -- | Return a leading power and coefficient of a non-zero polynomial. -- --
--   >>> import Data.Poly.Sparse (UPoly)
--   
--   >>> leading ((2 * X + 1) * (2 * X^2 - 1) :: UPoly Int)
--   Just (3,4)
--   
--   >>> leading (0 :: UPoly Int)
--   Nothing
--   
leading :: Vector v (Vector 1 Word, a) => Poly v a -> Maybe (Word, a) -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Num a, Vector v (Vector 1 Word, a)) => Word -> a -> Poly v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^2 + 1) :: UPoly Int
--   3 * X^4 + 3 * X^2
--   
scale :: (Eq a, Num a, Vector v (Vector 1 Word, a)) => Word -> a -> Poly v a -> Poly v a -- | Create an identity polynomial. pattern X :: (Eq a, Num a, Vector v (Vector 1 Word, a)) => Poly v a -- | Evaluate at a given point. -- --
--   >>> eval (X^2 + 1 :: UPoly Int) 3
--   10
--   
eval :: (Num a, Vector v (Vector 1 Word, a)) => Poly v a -> a -> a -- | Substitute another polynomial instead of X. -- --
--   >>> subst (X^2 + 1 :: UPoly Int) (X + 1 :: UPoly Int)
--   1 * X^2 + 2 * X + 2
--   
subst :: (Eq a, Num a, Vector v (Vector 1 Word, a), Vector w (Vector 1 Word, a)) => Poly v a -> Poly w a -> Poly w a -- | Take a derivative. -- --
--   >>> deriv (X^3 + 3 * X) :: UPoly Int
--   3 * X^2 + 3
--   
deriv :: (Eq a, Num a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Compute an indefinite integral of a polynomial, setting constant term -- to zero. -- --
--   >>> integral (3 * X^2 + 3) :: UPoly Double
--   1.0 * X^3 + 3.0 * X
--   
integral :: (Fractional a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Polynomial division with remainder. -- --
--   >>> quotRemFractional (X^3 + 2) (X^2 - 1 :: UPoly Double)
--   (1.0 * X,1.0 * X + 2.0)
--   
quotRemFractional :: (Eq a, Fractional a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -> (Poly v a, Poly v a) -- | Convert from dense to sparse polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> denseToSparse (1 + Data.Poly.X^2) :: Data.Poly.Sparse.UPoly Int
--   1 * X^2 + 1
--   
denseToSparse :: (Eq a, Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Convert from sparse to dense polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> sparseToDense (1 + Data.Poly.Sparse.X^2) :: Data.Poly.UPoly Int
--   1 * X^2 + 0 * X + 1
--   
sparseToDense :: (Num a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Sparse Laurent polynomials. module Data.Poly.Sparse.Laurent -- | Laurent polynomials of one variable with coefficients from -- a, backed by a Vector v (boxed, unboxed, -- storable, etc.). -- -- Use pattern X and operator ^- for construction: -- --
--   >>> (X + 1) + (X^-1 - 1) :: VLaurent Integer
--   1 * X + 1 * X^-1
--   
--   >>> (X + 1) * (1 - X^-1) :: ULaurent Int
--   1 * X + (-1) * X^-1
--   
-- -- Polynomials are stored normalized, without zero coefficients, so 0 * X -- + 1 + 0 * X^-1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. type Laurent (v :: Type -> Type) (a :: Type) = MultiLaurent v 1 a -- | Laurent polynomials backed by boxed vectors. type VLaurent (a :: Type) = Laurent Vector a -- | Laurent polynomials backed by unboxed vectors. type ULaurent (a :: Type) = Laurent Vector a -- | 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)
--   
unLaurent :: Laurent v a -> (Int, Poly v a) -- | Construct 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 Int
--   2 * X^3 + 1 * X^2
--   
--   >>> toLaurent (-2) (2 * Data.Poly.Sparse.X + 1) :: ULaurent Int
--   2 * X^-1 + 1 * X^-2
--   
toLaurent :: Vector v (Vector 1 Word, a) => Int -> Poly v a -> Laurent v a -- | Return a 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
--   
leading :: Vector v (Vector 1 Word, a) => Laurent v a -> Maybe (Int, a) -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^-2 + 1) :: ULaurent Int
--   3 * X^2 + 3
--   
scale :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Int -> a -> Laurent v a -> Laurent v a -- | Create an identity polynomial. pattern X :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Laurent v a -- | This operator can be applied only to monomials with unit coefficients, -- but is instrumental to express Laurent polynomials in mathematical -- fashion: -- --
--   >>> X + 2 + 3 * (X^2)^-1 :: ULaurent Int
--   1 * X + 2 + 3 * X^-2
--   
(^-) :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Laurent v a -> Int -> Laurent v a -- | Evaluate at a given point. -- --
--   >>> eval (X^-2 + 1 :: ULaurent Double) 2
--   1.25
--   
eval :: (Field a, Vector v (Vector 1 Word, a)) => Laurent v a -> a -> a -- | 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
--   
subst :: (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 -- | Take a derivative. -- --
--   >>> deriv (X^-3 + 3 * X) :: ULaurent Int
--   3 + (-3) * X^-4
--   
deriv :: (Eq a, Ring a, Vector v (Vector 1 Word, a)) => Laurent v a -> Laurent v a -- | Sparse polynomials with Semiring instance. module Data.Poly.Sparse.Semiring -- | Sparse univariate polynomials with coefficients from a, -- backed by a Vector v (boxed, unboxed, storable, etc.). -- -- Use pattern X for construction: -- --
--   >>> (X + 1) + (X - 1) :: VPoly Integer
--   2 * X
--   
--   >>> (X + 1) * (X - 1) :: UPoly Int
--   1 * X^2 + (-1)
--   
-- -- Polynomials are stored normalized, without zero coefficients, so 0 * -- X + 1 equals to 1. -- -- Ord instance does not make much sense mathematically, it is -- defined only for the sake of Set, Map, etc. type Poly (v :: Type -> Type) (a :: Type) = MultiPoly v 1 a -- | Polynomials backed by boxed vectors. type VPoly (a :: Type) = Poly Vector a -- | Polynomials backed by unboxed vectors. type UPoly (a :: Type) = Poly Vector a -- | Convert Poly to a vector of coefficients. unPoly :: (Vector v (Word, a), Vector v (Vector 1 Word, a)) => Poly v a -> v (Word, a) -- | Make Poly from a list of (power, coefficient) pairs. -- --
--   >>> :set -XOverloadedLists
--   
--   >>> toPoly [(0,1),(1,2),(2,3)] :: VPoly Integer
--   3 * X^2 + 2 * X + 1
--   
--   >>> toPoly [(0,0),(1,0),(2,0)] :: UPoly Int
--   0
--   
toPoly :: (Eq a, Semiring a, Vector v (Word, a), Vector v (Vector 1 Word, a)) => v (Word, a) -> Poly v a -- | Return a leading power and coefficient of a non-zero polynomial. -- --
--   >>> import Data.Poly.Sparse (UPoly)
--   
--   >>> leading ((2 * X + 1) * (2 * X^2 - 1) :: UPoly Int)
--   Just (3,4)
--   
--   >>> leading (0 :: UPoly Int)
--   Nothing
--   
leading :: Vector v (Vector 1 Word, a) => Poly v a -> Maybe (Word, a) -- | Create a monomial from a power and a coefficient. monomial :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Word -> a -> Poly v a -- | Multiply a polynomial by a monomial, expressed as a power and a -- coefficient. -- --
--   >>> scale 2 3 (X^2 + 1) :: UPoly Int
--   3 * X^4 + 3 * X^2
--   
scale :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Word -> a -> Poly v a -> Poly v a -- | Create an identity polynomial. pattern X :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Poly v a -- | Evaluate at a given point. -- --
--   >>> eval (X^2 + 1 :: UPoly Int) 3
--   10
--   
eval :: (Semiring a, Vector v (Vector 1 Word, a)) => Poly v a -> a -> a -- | Substitute another polynomial instead of X. -- --
--   >>> subst (X^2 + 1 :: UPoly Int) (X + 1 :: UPoly Int)
--   1 * X^2 + 2 * X + 2
--   
subst :: (Eq a, Semiring a, Vector v (Vector 1 Word, a), Vector w (Vector 1 Word, a)) => Poly v a -> Poly w a -> Poly w a -- | Take a derivative. -- --
--   >>> deriv (X^3 + 3 * X) :: UPoly Int
--   3 * X^2 + 3
--   
deriv :: (Eq a, Semiring a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Compute an indefinite integral of a polynomial, setting constant term -- to zero. -- --
--   >>> integral (3 * X^2 + 3) :: UPoly Double
--   1.0 * X^3 + 3.0 * X
--   
integral :: (Field a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Convert from dense to sparse polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> denseToSparse (1 `plus` Data.Poly.X^2) :: Data.Poly.Sparse.UPoly Int
--   1 * X^2 + 1
--   
denseToSparse :: (Eq a, Semiring a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a -- | Convert from sparse to dense polynomials. -- --
--   >>> :set -XFlexibleContexts
--   
--   >>> sparseToDense (1 `plus` Data.Poly.Sparse.X^2) :: Data.Poly.UPoly Int
--   1 * X^2 + 0 * X + 1
--   
sparseToDense :: (Semiring a, Vector v a, Vector v (Vector 1 Word, a)) => Poly v a -> Poly v a