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

Safe Haskell | None
Language | Haskell98

Math.CommutativeAlgebra.Polynomial

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

- class (Eq m, Show m, Mon m) => Monomial m where
  - mdivides :: m -> m -> Bool
  - mdiv :: m -> m -> m
  - mgcd :: m -> m -> m
  - mlcm :: m -> m -> m
  - mcoprime :: m -> m -> Bool
  - mdeg :: m -> Int
- mproperlydivides :: Monomial m => m -> m -> Bool
- class MonomialConstructor m where
  - mvar :: v -> m v
  - mindices :: m v -> [(v, Int)]
- var :: (Num k, MonomialConstructor m) => v -> Vect k (m v)
- data MonImpl v = M Int [(v, Int)]
- newtype Lex v = Lex (MonImpl v)
- type LexPoly k v = Vect k (Lex v)
- lexvar :: v -> LexPoly Q v
- newtype Glex v = Glex (MonImpl v)
- type GlexPoly k v = Vect k (Glex v)
- glexvar :: v -> GlexPoly Q v
- newtype Grevlex v = Grevlex (MonImpl v)
- type GrevlexPoly k v = Vect k (Grevlex v)
- grevlexvar :: v -> GrevlexPoly Q v
- data Elim2 a b = Elim2 !a !b
- 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
- flipbind :: (Eq k, Num k, Ord b, Show b, Algebra k b, MonomialConstructor m) => (v -> Vect k b) -> Vect k (m v) -> Vect k b
- eval :: (Eq k, Num k, MonomialConstructor m, Eq (m v), Show v) => Vect k (m v) -> [(Vect k (m v), k)] -> k
- 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)
- vars :: (Num k, Ord k, MonomialConstructor m, Ord (m v)) => Vect k (m v) -> [Vect k (m v)]
- lt :: Vect t t1 -> (t1, t)
- lm :: Vect b c -> c
- lc :: Vect c a -> c
- deg :: Monomial m => Vect t m -> Int
- toMonic :: (Eq k, Fractional k, Ord b, Show b, Algebra k b) => Vect k b -> Vect k b
- tdivides :: Monomial m => (m, t) -> (m, t1) -> Bool
- tdiv :: (Fractional t1, Monomial t) => (t, t1) -> (t, t1) -> (t, t1)
- tgcd :: (Num t3, Monomial t2) => (t2, t) -> (t2, t1) -> (t2, t3)
- tmult :: (Num t1, Mon t) => (t, t1) -> (t, t1) -> (t, t1)
- (*->) :: (Num k, Mon b) => (b, k) -> Vect k b -> Vect k b
- quotRemMP :: (Eq t, Fractional t, Ord m, Algebra t m, Monomial m) => Vect t m -> [Vect t m] -> ([Vect t m], Vect t m)
- rewrite :: (Eq t, Fractional t, Ord m, Algebra t m, Monomial m) => Vect t m -> [Vect t m] -> Vect t m
- (%%) :: (Eq k, Fractional k, Monomial m, Ord m, Algebra k m) => Vect k m -> [Vect k m] -> Vect k m

# 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 |
(Ord v, Show v) => Monomial (Glex v) Source |
(Ord v, Show v) => Monomial (Lex v) Source |
(Ord v, Show v) => Monomial (MonImpl v) Source |
(Monomial a, Monomial b) => Monomial (Elim2 a b) Source |

mproperlydivides :: Monomial m => m -> m -> Bool 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

MonomialConstructor Grevlex Source |
MonomialConstructor Glex Source |
MonomialConstructor Lex Source |
MonomialConstructor MonImpl 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

Functor MonImpl Source |
MonomialConstructor MonImpl Source |
Eq v => Eq (MonImpl v) Source |
Show v => Show (MonImpl v) Source |
Ord v => Mon (MonImpl v) Source |
(Ord v, Show v) => Monomial (MonImpl v) 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

Functor Lex Source |
MonomialConstructor Lex Source |
(Eq k, Num k, Ord v, Show v) => Algebra k (Lex v) Source |
Eq v => Eq (Lex v) Source |
Ord v => Ord (Lex v) Source |
Show v => Show (Lex v) Source |
Ord v => Mon (Lex v) Source |
(Ord v, Show v) => Monomial (Lex v) 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

Functor Glex Source |
MonomialConstructor Glex Source |
(Eq k, Num k, Ord v, Show v) => Algebra k (Glex v) Source |
Eq v => Eq (Glex v) Source |
Ord v => Ord (Glex v) Source |
Show v => Show (Glex v) Source |
Ord v => Mon (Glex v) Source |
(Ord v, Show v) => Monomial (Glex v) 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

Functor Grevlex Source |
MonomialConstructor Grevlex Source |
(Eq k, Num k, Ord v, Show v) => Algebra k (Grevlex v) Source |
Eq v => Eq (Grevlex v) Source |
Ord v => Ord (Grevlex v) Source |
Show v => Show (Grevlex v) Source |
Ord v => Mon (Grevlex v) Source |
(Ord v, Show v) => Monomial (Grevlex v) 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 |
Functor (Elim2 a) Source |
(Eq a, Eq b) => Eq (Elim2 a b) Source |
(Ord a, Ord b) => Ord (Elim2 a b) Source |
(Show a, Show b) => Show (Elim2 a b) Source |
(Mon a, Mon b) => Mon (Elim2 a b) Source |
(Monomial a, Monomial b) => Monomial (Elim2 a b) 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 :: (Eq k, Num k, Ord b, Show b, Algebra k b, MonomialConstructor m) => (v -> Vect k b) -> Vect k (m v) -> 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 t t1 -> (t1, t) Source

lm :: Vect b c -> c Source

lc :: Vect c a -> c Source

deg :: Monomial m => Vect t m -> Int Source

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

tdivides :: Monomial m => (m, t) -> (m, t1) -> Bool Source

tdiv :: (Fractional t1, Monomial t) => (t, t1) -> (t, t1) -> (t, t1) Source

tgcd :: (Num t3, Monomial t2) => (t2, t) -> (t2, t1) -> (t2, t3) Source

tmult :: (Num t1, Mon t) => (t, t1) -> (t, t1) -> (t, t1) Source

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

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

rewrite :: (Eq t, Fractional t, Ord m, Algebra t m, Monomial m) => Vect t m -> [Vect t m] -> Vect t 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.