HMath.Algebra¶
Module index · Numerical conventions
Description
Algebraic interfaces, exact law checks, checked modular rings, and finite extension fields GF(p^n). Runtime moduli are deliberately not Num instances: combining different rings is an explicit error. Finite fields are constructed only after primality and irreducibility have been proved under a budget.
On this page¶
| API | Purpose |
|---|---|
| Semiring | Commutative addition, associative multiplication, distributivity, additive identity and absorbing zero. |
| zero | Additive identity. |
| one | Additive identity. |
| plus | Additive identity. |
| times | Additive identity. |
| Ring | A semiring whose additive monoid is an abelian group. |
| negateRing | Additive inverse. |
| Field | A commutative ring in which each nonzero element has an inverse. |
| inverseField | Multiplicative inverse; zero returns a domain error. |
| Group | An associative operation with identity and inverse. |
| groupIdentity | Group identity. |
| groupCombine | Group identity. |
| groupInverse | Group identity. |
| Additive | A ring viewed as its additive group. |
| Additive | Declaration and type contract below. |
| getAdditive | Recover the underlying ring element. |
| Module | A left module with checked addition for runtime vector shapes. |
| moduleScale | Scalar action. |
| moduleAdd | Scalar action. |
| VectorSpace | A module over a field. |
| linearCombination | Checked linear combination. |
| semiringLaws | Exhaustive semiring identities on the supplied finite sample. |
| ringLaws | Semiring laws plus additive inverses on a finite sample. |
| fieldLaws | Ring laws, commutative multiplication and nonzero inverses. |
| groupLaws | Group identities on a finite sample. |
| moduleLaws | Check module scalar identity, composition, and both distributive laws. |
| Modular | A canonical residue in Z/mZ, retaining its runtime modulus. |
| modular | Construct a residue, requiring m>1; arbitrary signed values are reduced. |
| modularValue | Canonical value in [0,m). |
| modularModulus | Modulus greater than one. |
| addModular | Checked residue addition. |
| subtractModular | Checked residue subtraction. |
| multiplyModular | Checked residue multiplication. |
| inverseModular | Invert a unit; zero and nonunits are domain errors. |
| powerModular | Integer power, with negative powers supported for units. |
| FiniteField | An irreducible monic modulus over the proven prime field F_p. |
| finiteField | Construct GF(p^n) from an irreducible polynomial of positive degree. |
| primeField | Prime field GF(p), represented as F_p[x]/(x). |
| fieldCharacteristic | Prime characteristic p. |
| fieldDegree | Extension degree n. |
| fieldCardinality | Exact carrier size p^n. |
| fieldModulus | Ascending coefficients of the monic irreducible defining polynomial. |
| FieldElement | A canonical residue polynomial of degree smaller than its field degree. |
| fieldElement | Reduce an arbitrary integer polynomial into a finite field. |
| fieldElementCoefficients | Canonical ascending residue coefficients (trailing zeros removed). |
| fieldElements | Enumerate the complete carrier, rejecting sizes above an explicit storage budget. |
| addField | Addition; different defining fields are rejected even if isomorphic. |
| negateField | Additive inverse in the same field. |
| subtractField | Checked field subtraction. |
| multiplyField | Checked field multiplication, reduced modulo the defining polynomial. |
| inverseFieldElement | Nonzero inverse via the finite-field identity a^(q-2). |
| powerField | Binary exponentiation, with inverses for negative exponents. |
| finiteFieldLaws | Exhaustive carrier checks for small fields, including distributivity, associativity, identities and every nonzero inverse. |
Documentation
Semiring
class Semiring a where Source #
Commutative addition, associative multiplication, distributivity, additive identity and absorbing zero. Multiplication need not be commutative.
Methods
Additive identity.
Multiplicative identity.
Semiring addition.
Semiring multiplication.
Instances
| Semiring Rational Source # | |
| Semiring Integer Source # | |
| (Eq a, Num a) => Semiring (Polynomial a) Source # | |
Defined in HMath.Algebra Methods zero :: Polynomial a Source # one :: Polynomial a Source # plus :: Polynomial a -> Polynomial a -> Polynomial a Source # times :: Polynomial a -> Polynomial a -> Polynomial a Source # | |
Ring
class Semiring a => Ring a where Source #
A semiring whose additive monoid is an abelian group.
Instances
| Ring Rational Source # | |
Defined in HMath.Algebra Methods negateRing :: Rational -> Rational Source # | |
| Ring Integer Source # | |
Defined in HMath.Algebra Methods negateRing :: Integer -> Integer Source # | |
| (Eq a, Num a) => Ring (Polynomial a) Source # | |
Defined in HMath.Algebra Methods negateRing :: Polynomial a -> Polynomial a Source # | |
Field
class Ring a => Field a where Source #
A commutative ring in which each nonzero element has an inverse.
Methods
inverseField :: a -> Either MathError a Source #
Multiplicative inverse; zero returns a domain error.
Group
An associative operation with identity and inverse.
Methods
groupIdentity :: a Source #
Group identity.
groupCombine :: a -> a -> a Source #
Group operation, not necessarily commutative.
groupInverse :: a -> a Source #
Two-sided inverse.
Additive
A ring viewed as its additive group.
Constructors
| Additive | |
Fields
| |
Module
class Ring scalar => Module scalar vector | vector -> scalar where Source #
A left module with checked addition for runtime vector shapes.
Methods
moduleScale :: scalar -> vector -> vector Source #
Scalar action.
moduleAdd :: vector -> vector -> Either MathError vector Source #
Addition, rejecting incompatible runtime shapes.
VectorSpace
class (Field scalar, Module scalar vector) => VectorSpace scalar vector Source #
A module over a field. Rational finite-list vectors are an exact instance; list lengths define separate spaces, and moduleAdd rejects differing lengths.
Instances
| VectorSpace Rational [Rational] Source # | |
Defined in HMath.Algebra | |
linearCombination
linearCombination :: Module s v => v -> [(s, v)] -> Either MathError v Source #
Checked linear combination. Supply the zero vector explicitly so the empty combination retains its dimension.
semiringLaws
semiringLaws :: (Eq a, Semiring a) => [a] -> [(String, Bool)] Source #
Exhaustive semiring identities on the supplied finite sample. This is a test utility, not a proof for types with an infinite carrier.
ringLaws
ringLaws :: (Eq a, Ring a) => [a] -> [(String, Bool)] Source #
Semiring laws plus additive inverses on a finite sample.
fieldLaws
fieldLaws :: (Eq a, Field a) => [a] -> [(String, Bool)] Source #
Ring laws, commutative multiplication and nonzero inverses.
groupLaws
groupLaws :: (Eq a, Group a) => [a] -> [(String, Bool)] Source #
Group identities on a finite sample.
moduleLaws
moduleLaws :: (Eq v, Module s v) => [s] -> [v] -> [(String, Bool)] Source #
Check module scalar identity, composition, and both distributive laws. Vectors in the sample must belong to the same runtime space.
Modular
A canonical residue in Z/mZ, retaining its runtime modulus.
modular
modular :: Integer -> Integer -> Either MathError Modular Source #
Construct a residue, requiring m>1; arbitrary signed values are reduced.
addModular
addModular :: Modular -> Modular -> Either MathError Modular Source #
Checked residue addition.
subtractModular
subtractModular :: Modular -> Modular -> Either MathError Modular Source #
Checked residue subtraction.
multiplyModular
multiplyModular :: Modular -> Modular -> Either MathError Modular Source #
Checked residue multiplication.
inverseModular
inverseModular :: Modular -> Either MathError Modular Source #
Invert a unit; zero and nonunits are domain errors.
powerModular
powerModular :: Modular -> Integer -> Either MathError Modular Source #
Integer power, with negative powers supported for units.
FiniteField
data FiniteField Source #
An irreducible monic modulus over the proven prime field F_p. Coefficients are ascending canonical residues.
Instances
| Show FiniteField Source # | |
Defined in HMath.Algebra Methods showsPrec :: Int -> FiniteField -> ShowS # show :: FiniteField -> String # showList :: [FiniteField] -> ShowS # | |
| Eq FiniteField Source # | |
Defined in HMath.Algebra | |
finiteField
finiteField :: Int -> Integer -> [Integer] -> Either MathError FiniteField Source #
Construct GF(p^n) from an irreducible polynomial of positive degree. Primality is proven by trial division. Irreducibility uses successive Frobenius powers and polynomial gcds; n must not exceed the proof budget.
primeField
primeField :: Int -> Integer -> Either MathError FiniteField Source #
Prime field GF(p), represented as F_p[x]/(x).
fieldModulus
fieldModulus :: FiniteField -> [Integer] Source #
Ascending coefficients of the monic irreducible defining polynomial.
FieldElement
data FieldElement Source #
A canonical residue polynomial of degree smaller than its field degree.
Instances
| Show FieldElement Source # | |
Defined in HMath.Algebra Methods showsPrec :: Int -> FieldElement -> ShowS # show :: FieldElement -> String # showList :: [FieldElement] -> ShowS # | |
| Eq FieldElement Source # | |
Defined in HMath.Algebra | |
fieldElement
fieldElement :: FiniteField -> [Integer] -> FieldElement Source #
Reduce an arbitrary integer polynomial into a finite field.
fieldElementCoefficients
fieldElementCoefficients :: FieldElement -> [Integer] Source #
Canonical ascending residue coefficients (trailing zeros removed).
fieldElements
fieldElements :: Int -> FiniteField -> Either MathError [FieldElement] Source #
Enumerate the complete carrier, rejecting sizes above an explicit storage budget. Enumeration is coefficient-lexicographic and deterministic.
addField
addField :: FieldElement -> FieldElement -> Either MathError FieldElement Source #
Addition; different defining fields are rejected even if isomorphic.
subtractField
subtractField :: FieldElement -> FieldElement -> Either MathError FieldElement Source #
Checked field subtraction.
multiplyField
multiplyField :: FieldElement -> FieldElement -> Either MathError FieldElement Source #
Checked field multiplication, reduced modulo the defining polynomial.
inverseFieldElement
inverseFieldElement :: FieldElement -> Either MathError FieldElement Source #
Nonzero inverse via the finite-field identity a^(q-2).
powerField
powerField :: FieldElement -> Integer -> Either MathError FieldElement Source #
Binary exponentiation, with inverses for negative exponents.
finiteFieldLaws
finiteFieldLaws :: Int -> FiniteField -> Either MathError [(String, Bool)] Source #
Exhaustive carrier checks for small fields, including distributivity, associativity, identities and every nonzero inverse. Budget bounds enumeration; the cubic law checks are intended for small validation fields.