HaskellForMaths-0.4.9: Combinatorics, group theory, commutative algebra, non-commutative algebra

Math.CommutativeAlgebra.Polynomial

Contents

Description

A module defining the algebra of commutative polynomials over a field k. Polynomials are represented as the free k-vector space with the monomials as basis.

A monomial ordering is required to specify how monomials are to be ordered. The Lex, Glex, and Grevlex monomial orders are defined, with the possibility to add others.

In order to make use of this module, some variables must be defined, for example:

[t,u,v,x,y,z] = map glexvar ["t","u","v","x","y","z"]
Synopsis

Documentation

class (Eq m, Show m, Mon m) => Monomial m where Source #

In order to work with monomials, we need to be able to multiply them and divide them. Multiplication is defined by the Mon (monoid) class. Division is defined in this class. The functions here are primarily intended for internal use only.

Methods

mdivides :: m -> m -> Bool Source #

mdiv :: m -> m -> m Source #

mgcd :: m -> m -> m Source #

mlcm :: m -> m -> m Source #

mcoprime :: m -> m -> Bool Source #

mdeg :: m -> Int Source #

Instances
 (Ord v, Show v) => Monomial (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Grevlex v -> Grevlex v -> Bool Source #mdiv :: Grevlex v -> Grevlex v -> Grevlex v Source #mgcd :: Grevlex v -> Grevlex v -> Grevlex v Source #mlcm :: Grevlex v -> Grevlex v -> Grevlex v Source #mcoprime :: Grevlex v -> Grevlex v -> Bool Source #mdeg :: Grevlex v -> Int Source # (Ord v, Show v) => Monomial (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Glex v -> Glex v -> Bool Source #mdiv :: Glex v -> Glex v -> Glex v Source #mgcd :: Glex v -> Glex v -> Glex v Source #mlcm :: Glex v -> Glex v -> Glex v Source #mcoprime :: Glex v -> Glex v -> Bool Source #mdeg :: Glex v -> Int Source # (Ord v, Show v) => Monomial (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Lex v -> Lex v -> Bool Source #mdiv :: Lex v -> Lex v -> Lex v Source #mgcd :: Lex v -> Lex v -> Lex v Source #mlcm :: Lex v -> Lex v -> Lex v Source #mcoprime :: Lex v -> Lex v -> Bool Source #mdeg :: Lex v -> Int Source # (Ord v, Show v) => Monomial (MonImpl v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: MonImpl v -> MonImpl v -> Bool Source #mdiv :: MonImpl v -> MonImpl v -> MonImpl v Source #mgcd :: MonImpl v -> MonImpl v -> MonImpl v Source #mlcm :: MonImpl v -> MonImpl v -> MonImpl v Source #mcoprime :: MonImpl v -> MonImpl v -> Bool Source #mdeg :: MonImpl v -> Int Source # (Monomial a, Monomial b) => Monomial (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Elim2 a b -> Elim2 a b -> Bool Source #mdiv :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mgcd :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mlcm :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mcoprime :: Elim2 a b -> Elim2 a b -> Bool Source #mdeg :: Elim2 a b -> Int Source #

class MonomialConstructor m where Source #

We want to be able to construct monomials over any set of variables that we choose. Although we will often use String as the type of our variables, it is useful to define polymorphic types for monomials.

Methods

mvar :: v -> m v Source #

mindices :: m v -> [(v, Int)] Source #

Instances
 Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Grevlex v Source #mindices :: Grevlex v -> [(v, Int)] Source # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Glex v Source #mindices :: Glex v -> [(v, Int)] Source # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Lex v Source #mindices :: Lex v -> [(v, Int)] Source # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> MonImpl v Source #mindices :: MonImpl v -> [(v, Int)] Source #

var :: (Num k, MonomialConstructor m) => v -> Vect k (m v) Source #

var v creates a variable in the vector space of polynomials. For example, if we want to work in Q[x,y,z], we might define:

[x,y,z] = map var ["x","y","z"] :: [GlexPoly Q String]

Notice that, in general, it is necessary to provide a type annotation so that the compiler knows which field and which term order to use.

data MonImpl v Source #

The underlying implementation of monomials in variables of type v. Most often, we will be interested in MonImpl String, with the variable "x" represented by M 1 [("x",1)]. However, other types can be used instead.

No Ord instance is defined for MonImpl v, so it cannot be used as the basis for a free vector space of polynomials. Instead, several different newtype wrappers are provided, corresponding to different monomial orderings.

Constructors

 M Int [(v, Int)]
Instances
 Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsfmap :: (a -> b) -> MonImpl a -> MonImpl b #(<$) :: a -> MonImpl b -> MonImpl a # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> MonImpl v Source #mindices :: MonImpl v -> [(v, Int)] Source # Eq v => Eq (MonImpl v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methods(==) :: MonImpl v -> MonImpl v -> Bool #(/=) :: MonImpl v -> MonImpl v -> Bool # Show v => Show (MonImpl v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial MethodsshowsPrec :: Int -> MonImpl v -> ShowS #show :: MonImpl v -> String #showList :: [MonImpl v] -> ShowS # Ord v => Mon (MonImpl v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmmult :: MonImpl v -> MonImpl v -> MonImpl v Source # (Ord v, Show v) => Monomial (MonImpl v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: MonImpl v -> MonImpl v -> Bool Source #mdiv :: MonImpl v -> MonImpl v -> MonImpl v Source #mgcd :: MonImpl v -> MonImpl v -> MonImpl v Source #mlcm :: MonImpl v -> MonImpl v -> MonImpl v Source #mcoprime :: MonImpl v -> MonImpl v -> Bool Source #mdeg :: MonImpl v -> Int Source # newtype Lex v Source # A type representing monomials with Lex ordering. Lex stands for lexicographic ordering. For example, in Lex ordering, monomials up to degree two would be ordered as follows: x^2+xy+xz+x+y^2+yz+y+z^2+z+1. Constructors  Lex (MonImpl v) Instances  Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsfmap :: (a -> b) -> Lex a -> Lex b #(<$) :: a -> Lex b -> Lex a # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Lex v Source #mindices :: Lex v -> [(v, Int)] Source # (Eq k, Num k, Ord v, Show v) => Algebra k (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsunit :: k -> Vect k (Lex v) Source #mult :: Vect k (Tensor (Lex v) (Lex v)) -> Vect k (Lex v) Source # Eq v => Eq (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methods(==) :: Lex v -> Lex v -> Bool #(/=) :: Lex v -> Lex v -> Bool # Ord v => Ord (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodscompare :: Lex v -> Lex v -> Ordering #(<) :: Lex v -> Lex v -> Bool #(<=) :: Lex v -> Lex v -> Bool #(>) :: Lex v -> Lex v -> Bool #(>=) :: Lex v -> Lex v -> Bool #max :: Lex v -> Lex v -> Lex v #min :: Lex v -> Lex v -> Lex v # Show v => Show (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial MethodsshowsPrec :: Int -> Lex v -> ShowS #show :: Lex v -> String #showList :: [Lex v] -> ShowS # Ord v => Mon (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmmult :: Lex v -> Lex v -> Lex v Source # (Ord v, Show v) => Monomial (Lex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Lex v -> Lex v -> Bool Source #mdiv :: Lex v -> Lex v -> Lex v Source #mgcd :: Lex v -> Lex v -> Lex v Source #mlcm :: Lex v -> Lex v -> Lex v Source #mcoprime :: Lex v -> Lex v -> Bool Source #mdeg :: Lex v -> Int Source #

type LexPoly k v = Vect k (Lex v) Source #

A type representing polynomials with Lex term ordering.

lexvar :: v -> LexPoly Q v Source #

lexvar v creates a variable in the algebra of commutative polynomials over Q with Lex term ordering. It is provided as a shortcut, to avoid having to provide a type annotation, as with var. For example, the following code creates variables called x, y and z:

[x,y,z] = map lexvar ["x","y","z"]

newtype Glex v Source #

A type representing monomials with Glex ordering.

Glex stands for graded lexicographic. Thus monomials are ordered first by degree, then by lexicographic order. For example, in Glex ordering, monomials up to degree two would be ordered as follows: x^2+xy+xz+y^2+yz+z^2+x+y+z+1.

Constructors

 Glex (MonImpl v)
Instances
 Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsfmap :: (a -> b) -> Glex a -> Glex b #(<$) :: a -> Glex b -> Glex a # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Glex v Source #mindices :: Glex v -> [(v, Int)] Source # (Eq k, Num k, Ord v, Show v) => Algebra k (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsunit :: k -> Vect k (Glex v) Source #mult :: Vect k (Tensor (Glex v) (Glex v)) -> Vect k (Glex v) Source # Eq v => Eq (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methods(==) :: Glex v -> Glex v -> Bool #(/=) :: Glex v -> Glex v -> Bool # Ord v => Ord (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodscompare :: Glex v -> Glex v -> Ordering #(<) :: Glex v -> Glex v -> Bool #(<=) :: Glex v -> Glex v -> Bool #(>) :: Glex v -> Glex v -> Bool #(>=) :: Glex v -> Glex v -> Bool #max :: Glex v -> Glex v -> Glex v #min :: Glex v -> Glex v -> Glex v # Show v => Show (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial MethodsshowsPrec :: Int -> Glex v -> ShowS #show :: Glex v -> String #showList :: [Glex v] -> ShowS # Ord v => Mon (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmmult :: Glex v -> Glex v -> Glex v Source # (Ord v, Show v) => Monomial (Glex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Glex v -> Glex v -> Bool Source #mdiv :: Glex v -> Glex v -> Glex v Source #mgcd :: Glex v -> Glex v -> Glex v Source #mlcm :: Glex v -> Glex v -> Glex v Source #mcoprime :: Glex v -> Glex v -> Bool Source #mdeg :: Glex v -> Int Source # type GlexPoly k v = Vect k (Glex v) Source # A type representing polynomials with Glex term ordering. glexvar :: v -> GlexPoly Q v Source # glexvar v creates a variable in the algebra of commutative polynomials over Q with Glex term ordering. It is provided as a shortcut, to avoid having to provide a type annotation, as with var. For example, the following code creates variables called x, y and z: [x,y,z] = map glexvar ["x","y","z"] newtype Grevlex v Source # A type representing monomials with Grevlex ordering. Grevlex stands for graded reverse lexicographic. Thus monomials are ordered first by degree, then by reverse lexicographic order. For example, in Grevlex ordering, monomials up to degree two would be ordered as follows: x^2+xy+y^2+xz+yz+z^2+x+y+z+1. In general, Grevlex leads to the smallest Groebner bases. Constructors  Grevlex (MonImpl v) Instances  Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsfmap :: (a -> b) -> Grevlex a -> Grevlex b #(<$) :: a -> Grevlex b -> Grevlex a # Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmvar :: v -> Grevlex v Source #mindices :: Grevlex v -> [(v, Int)] Source # (Eq k, Num k, Ord v, Show v) => Algebra k (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsunit :: k -> Vect k (Grevlex v) Source #mult :: Vect k (Tensor (Grevlex v) (Grevlex v)) -> Vect k (Grevlex v) Source # Eq v => Eq (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methods(==) :: Grevlex v -> Grevlex v -> Bool #(/=) :: Grevlex v -> Grevlex v -> Bool # Ord v => Ord (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodscompare :: Grevlex v -> Grevlex v -> Ordering #(<) :: Grevlex v -> Grevlex v -> Bool #(<=) :: Grevlex v -> Grevlex v -> Bool #(>) :: Grevlex v -> Grevlex v -> Bool #(>=) :: Grevlex v -> Grevlex v -> Bool #max :: Grevlex v -> Grevlex v -> Grevlex v #min :: Grevlex v -> Grevlex v -> Grevlex v # Show v => Show (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial MethodsshowsPrec :: Int -> Grevlex v -> ShowS #show :: Grevlex v -> String #showList :: [Grevlex v] -> ShowS # Ord v => Mon (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmmult :: Grevlex v -> Grevlex v -> Grevlex v Source # (Ord v, Show v) => Monomial (Grevlex v) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Grevlex v -> Grevlex v -> Bool Source #mdiv :: Grevlex v -> Grevlex v -> Grevlex v Source #mgcd :: Grevlex v -> Grevlex v -> Grevlex v Source #mlcm :: Grevlex v -> Grevlex v -> Grevlex v Source #mcoprime :: Grevlex v -> Grevlex v -> Bool Source #mdeg :: Grevlex v -> Int Source #

type GrevlexPoly k v = Vect k (Grevlex v) Source #

A type representing polynomials with Grevlex term ordering.

grevlexvar :: v -> GrevlexPoly Q v Source #

grevlexvar v creates a variable in the algebra of commutative polynomials over Q with Grevlex term ordering. It is provided as a shortcut, to avoid having to provide a type annotation, as with var. For example, the following code creates variables called x, y and z:

[x,y,z] = map grevlexvar ["x","y","z"]

data Elim2 a b Source #

Constructors

 Elim2 !a !b
Instances
 (Eq k, Num k, Ord a, Mon a, Ord b, Mon b) => Algebra k (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsunit :: k -> Vect k (Elim2 a b) Source #mult :: Vect k (Tensor (Elim2 a b) (Elim2 a b)) -> Vect k (Elim2 a b) Source # Functor (Elim2 a) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsfmap :: (a0 -> b) -> Elim2 a a0 -> Elim2 a b #(<\$) :: a0 -> Elim2 a b -> Elim2 a a0 # (Eq a, Eq b) => Eq (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methods(==) :: Elim2 a b -> Elim2 a b -> Bool #(/=) :: Elim2 a b -> Elim2 a b -> Bool # (Ord a, Ord b) => Ord (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodscompare :: Elim2 a b -> Elim2 a b -> Ordering #(<) :: Elim2 a b -> Elim2 a b -> Bool #(<=) :: Elim2 a b -> Elim2 a b -> Bool #(>) :: Elim2 a b -> Elim2 a b -> Bool #(>=) :: Elim2 a b -> Elim2 a b -> Bool #max :: Elim2 a b -> Elim2 a b -> Elim2 a b #min :: Elim2 a b -> Elim2 a b -> Elim2 a b # (Show a, Show b) => Show (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial MethodsshowsPrec :: Int -> Elim2 a b -> ShowS #show :: Elim2 a b -> String #showList :: [Elim2 a b] -> ShowS # (Mon a, Mon b) => Mon (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmunit :: Elim2 a b Source #mmult :: Elim2 a b -> Elim2 a b -> Elim2 a b Source # (Monomial a, Monomial b) => Monomial (Elim2 a b) Source # Instance detailsDefined in Math.CommutativeAlgebra.Polynomial Methodsmdivides :: Elim2 a b -> Elim2 a b -> Bool Source #mdiv :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mgcd :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mlcm :: Elim2 a b -> Elim2 a b -> Elim2 a b Source #mcoprime :: Elim2 a b -> Elim2 a b -> Bool Source #mdeg :: Elim2 a b -> Int Source #

bind :: (Eq k, Num k, MonomialConstructor m, Ord a, Show a, Algebra k a) => Vect k (m v) -> (v -> Vect k a) -> Vect k a Source #

Given (Num k, MonomialConstructor m), then Vect k (m v) is the free commutative algebra over v. As such, it is a monad (in the mathematical sense). The following pseudo-code (not legal Haskell) shows how this would work:

instance (Num k, Monomial m) => Monad (\v -> Vect k (m v)) where
return = var
(>>=) = bind

bind corresponds to variable substitution, so v bind f returns the result of making the substitutions encoded in f into v.

Note that the type signature is slightly more general than that required by (>>=). For a monad, we would only require:

bind :: (MonomialConstructor m, Num k, Ord (m v), Show (m v), Algebra k (m v)) =>
Vect k (m u) -> (u -> Vect k (m v)) -> Vect k (m v)

Instead, the given type signature allows us to substitute in elements of any algebra. This is occasionally useful.

bind performs variable substitution

flipbind :: (Num k, Ord b, Eq k, Show b, Algebra k b, MonomialConstructor m) => (t -> Vect k b) -> Vect k (m t) -> Vect k b Source #

eval :: (Eq k, Num k, MonomialConstructor m, Eq (m v), Show v) => Vect k (m v) -> [(Vect k (m v), k)] -> k Source #

Evaluate a polynomial at a point. For example eval (x^2+y^2) [(x,1),(y,2)] evaluates x^2+y^2 at the point (x,y)=(1,2).

subst :: (Eq k, Num k, MonomialConstructor m, Eq (m u), Show u, Ord (m v), Show (m v), Algebra k (m v)) => Vect k (m u) -> [(Vect k (m u), Vect k (m v))] -> Vect k (m v) Source #

Perform variable substitution on a polynomial. For example subst (x*z-y^2) [(x,u^2),(y,u*v),(z,v^2)] performs the substitution x -> u^2, y -> u*v, z -> v^2.

vars :: (Num k, Ord k, MonomialConstructor m, Ord (m v)) => Vect k (m v) -> [Vect k (m v)] Source #

List the variables used in a polynomial

lt :: Vect k b -> (b, k) Source #

lm :: Vect b c -> c Source #

lc :: Vect c a -> c Source #

deg :: Monomial m => Vect k m -> Int Source #

toMonic :: (Eq k, Ord b, Show b, Algebra k b, Fractional k) => Vect k b -> Vect k b Source #

tdivides :: Monomial m => (m, b1) -> (m, b2) -> Bool Source #

tdiv :: (Monomial a, Fractional b) => (a, b) -> (a, b) -> (a, b) Source #

tgcd :: (Monomial a, Num b1) => (a, b2) -> (a, b3) -> (a, b1) Source #

tmult :: (Mon a, Num b) => (a, b) -> (a, b) -> (a, b) Source #

(*->) :: (Mon b, Num k) => (b, k) -> Vect k b -> Vect k b infixl 7 Source #

quotRemMP :: (Monomial m, Fractional b, Eq b, Ord m, Algebra b m) => Vect b m -> [Vect b m] -> ([Vect b m], Vect b m) Source #

rewrite :: (Eq b, Ord m, Algebra b m, Monomial m, Fractional b) => Vect b m -> [Vect b m] -> Vect b m Source #

(%%) :: (Eq k, Fractional k, Monomial m, Ord m, Algebra k m) => Vect k m -> [Vect k m] -> Vect k m infixl 7 Source #

f %% gs is the reduction of a polynomial f with respect to a list of polynomials gs. In the case where the gs are a Groebner basis for an ideal I, then f %% gs is the equivalence class representative of f in R/I, and is zero if and only if f is in I.

Orphan instances

 (Eq k, Fractional k, Monomial m, Ord m, Algebra k m) => Fractional (Vect k m) Source # As a convenience, a partial instance of Fractional is defined for polynomials. The instance is well-defined only for scalars, and gives an error if used on other values. The purpose of this is to allow entry of fractional scalars, in expressions such as x/2. On the other hand, an expression such as 2/x will return an error. Instance details Methods(/) :: Vect k m -> Vect k m -> Vect k m #recip :: Vect k m -> Vect k m #fromRational :: Rational -> Vect k m #