Copyright | (c) Masahiro Sakai 2012-2013 |
---|---|
License | BSD-style |
Maintainer | masahiro.sakai@gmail.com |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Polynomials
References:
- Monomial order http://en.wikipedia.org/wiki/Monomial_order
- Polynomial class for Ruby http://www.math.kobe-u.ac.jp/~kodama/tips-RubyPoly.html
- constructive-algebra package http://hackage.haskell.org/package/constructive-algebra
- data Polynomial r v
- class Vars a v => Var a v | a -> v where
- var :: v -> a
- constant :: (Eq k, Num k, Ord v) => k -> Polynomial k v
- terms :: Polynomial k v -> [Term k v]
- fromTerms :: (Eq k, Num k, Ord v) => [Term k v] -> Polynomial k v
- coeffMap :: Polynomial r v -> Map (Monomial v) r
- fromCoeffMap :: (Eq k, Num k, Ord v) => Map (Monomial v) k -> Polynomial k v
- fromTerm :: (Eq k, Num k, Ord v) => Term k v -> Polynomial k v
- class Degree t where
- class Ord v => Vars a v | a -> v where
- lt :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> Term k v
- lc :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> k
- lm :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> Monomial v
- coeff :: (Num k, Ord v) => Monomial v -> Polynomial k v -> k
- lookupCoeff :: Ord v => Monomial v -> Polynomial k v -> Maybe k
- isPrimitive :: (Eq k, Num k, ContPP k, Ord v) => Polynomial k v -> Bool
- class Factor a where
- class SQFree a where
- class ContPP k where
- cont :: Ord v => Polynomial k v -> k
- pp :: Ord v => Polynomial k v -> Polynomial k v
- deriv :: (Eq k, Num k, Ord v) => Polynomial k v -> v -> Polynomial k v
- integral :: (Eq k, Fractional k, Ord v) => Polynomial k v -> v -> Polynomial k v
- eval :: (Num k, Ord v) => (v -> k) -> Polynomial k v -> k
- subst :: (Eq k, Num k, Ord v1, Ord v2) => Polynomial k v1 -> (v1 -> Polynomial k v2) -> Polynomial k v2
- mapCoeff :: (Eq k1, Num k1, Ord v) => (k -> k1) -> Polynomial k v -> Polynomial k1 v
- toMonic :: (Eq r, Fractional r, Ord v) => MonomialOrder v -> Polynomial r v -> Polynomial r v
- toUPolynomialOf :: (Ord k, Num k, Ord v) => Polynomial k v -> v -> UPolynomial (Polynomial k v)
- divModMP :: forall k v. (Eq k, Fractional k, Ord v) => MonomialOrder v -> Polynomial k v -> [Polynomial k v] -> ([Polynomial k v], Polynomial k v)
- reduce :: (Eq k, Fractional k, Ord v) => MonomialOrder v -> Polynomial k v -> [Polynomial k v] -> Polynomial k v
- type UPolynomial r = Polynomial r X
- data X = X
- type UTerm k = Term k X
- type UMonomial = Monomial X
- div :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k
- mod :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k
- divMod :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> (UPolynomial k, UPolynomial k)
- divides :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> Bool
- gcd :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k
- lcm :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k
- exgcd :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> (UPolynomial k, UPolynomial k, UPolynomial k)
- pdivMod :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> (r, UPolynomial r, UPolynomial r)
- pdiv :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> UPolynomial r
- pmod :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> UPolynomial r
- gcd' :: (Eq r, Integral r) => UPolynomial r -> UPolynomial r -> UPolynomial r
- isRootOf :: (Eq k, Num k) => k -> UPolynomial k -> Bool
- isSquareFree :: (Eq k, Fractional k) => UPolynomial k -> Bool
- nat :: MonomialOrder X
- type Term k v = (k, Monomial v)
- tdeg :: Term k v -> Integer
- tscale :: (Num k, Ord v) => k -> Term k v -> Term k v
- tmult :: (Num k, Ord v) => Term k v -> Term k v -> Term k v
- tdivides :: (Fractional k, Ord v) => Term k v -> Term k v -> Bool
- tdiv :: (Fractional k, Ord v) => Term k v -> Term k v -> Term k v
- tderiv :: (Eq k, Num k, Ord v) => Term k v -> v -> Term k v
- tintegral :: (Eq k, Fractional k, Ord v) => Term k v -> v -> Term k v
- data Monomial v
- mone :: Monomial v
- mfromIndices :: Ord v => [(v, Integer)] -> Monomial v
- mfromIndicesMap :: Ord v => Map v Integer -> Monomial v
- mindices :: Ord v => Monomial v -> [(v, Integer)]
- mindicesMap :: Monomial v -> Map v Integer
- mmult :: Ord v => Monomial v -> Monomial v -> Monomial v
- mpow :: Ord v => Monomial v -> Integer -> Monomial v
- mdivides :: Ord v => Monomial v -> Monomial v -> Bool
- mdiv :: Ord v => Monomial v -> Monomial v -> Monomial v
- mderiv :: Ord v => Monomial v -> v -> (Integer, Monomial v)
- mintegral :: Ord v => Monomial v -> v -> (Rational, Monomial v)
- mlcm :: Ord v => Monomial v -> Monomial v -> Monomial v
- mgcd :: Ord v => Monomial v -> Monomial v -> Monomial v
- mcoprime :: Ord v => Monomial v -> Monomial v -> Bool
- type MonomialOrder v = Monomial v -> Monomial v -> Ordering
- lex :: Ord v => MonomialOrder v
- revlex :: Ord v => Monomial v -> Monomial v -> Ordering
- grlex :: Ord v => MonomialOrder v
- grevlex :: Ord v => MonomialOrder v
- data PrintOptions k v = PrintOptions {
- pOptPrintVar :: PrettyLevel -> Rational -> v -> Doc
- pOptPrintCoeff :: PrettyLevel -> Rational -> k -> Doc
- pOptIsNegativeCoeff :: k -> Bool
- pOptMonomialOrder :: MonomialOrder v
- defaultPrintOptions :: (PrettyCoeff k, PrettyVar v, Ord v) => PrintOptions k v
- prettyPrint :: (Ord k, Num k, Ord v) => PrintOptions k v -> PrettyLevel -> Rational -> Polynomial k v -> Doc
- class PrettyCoeff a where
- pPrintCoeff :: PrettyLevel -> Rational -> a -> Doc
- isNegativeCoeff :: a -> Bool
- class PrettyVar a where
- pPrintVar :: PrettyLevel -> Rational -> a -> Doc
Polynomial type
data Polynomial r v Source
Polynomial over commutative ring r
SQFree (UPolynomial Integer) | |
SQFree (UPolynomial Rational) | |
Nat p => SQFree (UPolynomial (PrimeField p)) | |
Factor (UPolynomial Integer) | |
Factor (UPolynomial Rational) | |
Nat p => Factor (UPolynomial (PrimeField p)) | |
(Eq r, Eq v) => Eq (Polynomial r v) | |
(Eq k, Num k, Ord v) => Num (Polynomial k v) | |
(Ord r, Ord v) => Ord (Polynomial r v) | |
(Show v, Ord v, Show k) => Show (Polynomial k v) | |
(Eq k, Num k, Ord v, IsString v) => IsString (Polynomial k v) | |
(NFData k, NFData v) => NFData (Polynomial k v) | |
(Hashable k, Hashable v) => Hashable (Polynomial k v) | |
(Ord k, Num k, Ord v, PrettyCoeff k, PrettyVar v) => Pretty (Polynomial k v) | |
(Eq k, Num k, Ord v) => VectorSpace (Polynomial k v) | |
(Eq k, Num k, Ord v) => AdditiveGroup (Polynomial k v) | |
(Num c, Ord c, PrettyCoeff c, Ord v, PrettyVar v) => PrettyCoeff (Polynomial c v) | |
Degree (Polynomial k v) | |
Typeable (* -> * -> *) Polynomial | |
(Eq k, Num k, Ord v) => Vars (Polynomial k v) v | |
(Eq k, Num k, Ord v) => Var (Polynomial k v) v | |
type Scalar (Polynomial k v) = k |
Conversion
constant :: (Eq k, Num k, Ord v) => k -> Polynomial k v Source
construct a polynomial from a constant
terms :: Polynomial k v -> [Term k v] Source
list of terms
fromTerms :: (Eq k, Num k, Ord v) => [Term k v] -> Polynomial k v Source
construct a polynomial from a list of terms
coeffMap :: Polynomial r v -> Map (Monomial v) r Source
fromCoeffMap :: (Eq k, Num k, Ord v) => Map (Monomial v) k -> Polynomial k v Source
fromTerm :: (Eq k, Num k, Ord v) => Term k v -> Polynomial k v Source
construct a polynomial from a singlet term
Query
total degree of a given polynomial
Degree AReal | Degree of the algebraic number. If the algebraic number's |
Degree (Monomial v) | |
Degree (Polynomial k v) |
lt :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> Term k v Source
leading term with respect to a given monomial order
lc :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> k Source
leading coefficient with respect to a given monomial order
lm :: (Eq k, Num k, Ord v) => MonomialOrder v -> Polynomial k v -> Monomial v Source
leading monomial with respect to a given monomial order
coeff :: (Num k, Ord v) => Monomial v -> Polynomial k v -> k Source
Look up a coefficient for a given monomial.
If no such term exists, it returns 0
.
lookupCoeff :: Ord v => Monomial v -> Polynomial k v -> Maybe k Source
Look up a coefficient for a given monomial.
If no such term exists, it returns Nothing
.
isPrimitive :: (Eq k, Num k, ContPP k, Ord v) => Polynomial k v -> Bool Source
a polynomial is called primitive if the greatest common divisor of its coefficients is 1.
Operations
Prime factorization of polynomials
factor :: a -> [(a, Integer)] Source
factor a polynomial p
into p1 ^ n1 * p2 ^ n2 * ..
and
return a list [(p1,n1), (p2,n2), ..]
.
Factor (UPolynomial Integer) | |
Factor (UPolynomial Rational) | |
Nat p => Factor (UPolynomial (PrimeField p)) |
Square-free factorization of polynomials
sqfree :: a -> [(a, Integer)] Source
factor a polynomial p
into p1 ^ n1 * p2 ^ n2 * ..
and
return a list [(p1,n1), (p2,n2), ..]
.
SQFree (UPolynomial Integer) | |
SQFree (UPolynomial Rational) | |
Nat p => SQFree (UPolynomial (PrimeField p)) |
cont :: Ord v => Polynomial k v -> k Source
Content of a polynomial
pp :: Ord v => Polynomial k v -> Polynomial k v Source
Primitive part of a polynomial
deriv :: (Eq k, Num k, Ord v) => Polynomial k v -> v -> Polynomial k v Source
Formal derivative of polynomials
integral :: (Eq k, Fractional k, Ord v) => Polynomial k v -> v -> Polynomial k v Source
Formal integral of polynomials
eval :: (Num k, Ord v) => (v -> k) -> Polynomial k v -> k Source
Evaluation
subst :: (Eq k, Num k, Ord v1, Ord v2) => Polynomial k v1 -> (v1 -> Polynomial k v2) -> Polynomial k v2 Source
Substitution or bind
mapCoeff :: (Eq k1, Num k1, Ord v) => (k -> k1) -> Polynomial k v -> Polynomial k1 v Source
Transform polynomial coefficients.
toMonic :: (Eq r, Fractional r, Ord v) => MonomialOrder v -> Polynomial r v -> Polynomial r v Source
Transform a polynomial into a monic polynomial with respect to the given monomial order.
toUPolynomialOf :: (Ord k, Num k, Ord v) => Polynomial k v -> v -> UPolynomial (Polynomial k v) Source
Convert K[x,x1,x2,…] into K[x1,x2,…][x].
divModMP :: forall k v. (Eq k, Fractional k, Ord v) => MonomialOrder v -> Polynomial k v -> [Polynomial k v] -> ([Polynomial k v], Polynomial k v) Source
Multivariate division algorithm
divModMP cmp f [g1,g2,..]
returns a pair ([q1,q2,…],r)
such that
f = g1*q1 + g2*q2 + .. + r
andg1, g2, ..
do not divider
.
reduce :: (Eq k, Fractional k, Ord v) => MonomialOrder v -> Polynomial k v -> [Polynomial k v] -> Polynomial k v Source
Multivariate division algorithm
reduce cmp f gs = snd (divModMP cmp f gs)
Univariate polynomials
type UPolynomial r = Polynomial r X Source
Univariate polynomials over commutative ring r
Variable "x"
Bounded X | |
Enum X | |
Eq X | |
Data X | |
Ord X | |
Read X | |
Show X | |
NFData X | |
Hashable X | |
PrettyVar X | |
Typeable * X | |
SQFree (UPolynomial Integer) | |
SQFree (UPolynomial Rational) | |
Nat p => SQFree (UPolynomial (PrimeField p)) | |
Factor (UPolynomial Integer) | |
Factor (UPolynomial Rational) | |
Nat p => Factor (UPolynomial (PrimeField p)) |
div :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k infixl 7 Source
division of univariate polynomials
mod :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k infixl 7 Source
division of univariate polynomials
divMod :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> (UPolynomial k, UPolynomial k) Source
division of univariate polynomials
divides :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> Bool Source
gcd :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k Source
GCD of univariate polynomials
lcm :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> UPolynomial k Source
LCM of univariate polynomials
exgcd :: (Eq k, Fractional k) => UPolynomial k -> UPolynomial k -> (UPolynomial k, UPolynomial k, UPolynomial k) Source
Extended GCD algorithm
pdivMod :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> (r, UPolynomial r, UPolynomial r) Source
pseudo division
pdiv :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> UPolynomial r Source
pseudo quotient
pmod :: (Eq r, Num r) => UPolynomial r -> UPolynomial r -> UPolynomial r Source
pseudo reminder
gcd' :: (Eq r, Integral r) => UPolynomial r -> UPolynomial r -> UPolynomial r Source
GCD of univariate polynomials
isRootOf :: (Eq k, Num k) => k -> UPolynomial k -> Bool Source
Is the number a root of the polynomial?
isSquareFree :: (Eq k, Fractional k) => UPolynomial k -> Bool Source
Is the polynomial square free?
nat :: MonomialOrder X Source
Natural ordering x^0 < x^1 < x^2 .. is the unique monomial order for univariate polynomials.
Term
Monic monomial
Monic monomials
Eq v => Eq (Monomial v) | |
Ord v => Ord (Monomial v) | |
(Ord v, Show v) => Show (Monomial v) | |
(Ord v, IsString v) => IsString (Monomial v) | |
NFData v => NFData (Monomial v) | |
Hashable v => Hashable (Monomial v) | |
Degree (Monomial v) | |
Ord v => Vars (Monomial v) v | |
Ord v => Var (Monomial v) v | |
Typeable (* -> *) Monomial |
mfromIndices :: Ord v => [(v, Integer)] -> Monomial v Source
mindicesMap :: Monomial v -> Map v Integer Source
Monomial order
type MonomialOrder v = Monomial v -> Monomial v -> Ordering Source
lex :: Ord v => MonomialOrder v Source
Lexicographic order
revlex :: Ord v => Monomial v -> Monomial v -> Ordering Source
Reverse lexicographic order.
Note that revlex is NOT a monomial order.
grlex :: Ord v => MonomialOrder v Source
Graded lexicographic order
grevlex :: Ord v => MonomialOrder v Source
Graded reverse lexicographic order
Pretty Printing
data PrintOptions k v Source
PrintOptions | |
|
(PrettyCoeff k, PrettyVar v, Ord v) => Default (PrintOptions k v) |
defaultPrintOptions :: (PrettyCoeff k, PrettyVar v, Ord v) => PrintOptions k v Source
prettyPrint :: (Ord k, Num k, Ord v) => PrintOptions k v -> PrettyLevel -> Rational -> Polynomial k v -> Doc Source
class PrettyCoeff a where Source
pPrintCoeff :: PrettyLevel -> Rational -> a -> Doc Source
isNegativeCoeff :: a -> Bool Source
PrettyCoeff Integer | |
PrettyCoeff AReal | |
(PrettyCoeff a, Integral a) => PrettyCoeff (Ratio a) | |
PrettyCoeff (PrimeField a) | |
(Num c, Ord c, PrettyCoeff c, Ord v, PrettyVar v) => PrettyCoeff (Polynomial c v) |