Computable arithmetic for monic quotient presentations #
ExtensionParams F stores the degree, lower modulus coefficients and an explicit inverse-exponent
parameter q. Ext P is one nominal carrier with coefficient vectors in ascending degree order.
Its coordinate maps require no algebraic structure; arithmetic uses a ring of coefficients.
The presentation index separates parameter values for a fixed coefficient algebra. Operations
and their theorems are relative to the supplied ring or field structure on F; the raw carrier
does not separate alternative algebra structures on that same type. Distinct coefficient
presentations should use nominal coefficient types and explicit ring maps. The polynomial quotient
interpretation uses commutative coefficients; the raw formulas are defined for any ring.
Multiplication reduces monomials with shiftReduce. The executable reduction-table implementation
mulTbl is connected to mul by mul_eq_mulTbl. Power uses binary exponentiation, and the
canonical inverse candidate uses the literal exponent q^d - 2.
This module supplies no cardinality or irreducibility certificate. Polynomial specifications and
quotient correspondence belong to Extension/Defs.lean and Extension/Bridge.lean; certified field
laws belong to Extension/Field.lean. Raw parameters with an incorrect q still admit arithmetic
but do not thereby acquire field laws. The binomial conversion describes the modulus X^d - W.
The data defining an extension F[X] / f by a monic modulus f of degree d.
The modulus is stored by its d lower coefficients: f = X^d + ∑_{i < d} lower[i] · X^i. The
leading coefficient is an implicit 1, so f is monic by construction.
Irreducibility is not part of these parameters: the quotient is a commutative ring for every monic modulus over a commutative ring. Field laws additionally require finite-cardinality and irreducibility certificates.
- d : ℕ
The degree of the extension.
Degree at least two; a degree-one "extension" is just
F.The lower coefficients of the monic modulus, little-endian:
lower[i]is the coefficient ofX^iinpoly, fori < d. The coefficient ofX^dis an implicit1.- q : ℕ
Instances For
The coefficient of X^i in the lower part of the modulus.
Instances For
The lower modulus coefficient at index k, or zero when P.d ≤ k.
Instances For
The carrier of the quotient by the monic modulus in P, with coefficients in ascending
order of powers. The parameter remains part of the type even when two moduli have equal degree.
The coefficient of
X^iis stored at indexi.
Instances For
Build an element from coefficients in ascending order of powers.
Instances For
Extracting the coefficients of a constructed element returns the input vector.
Reconstructing an element from its coefficient vector returns that element.
The coefficient vector uniquely determines an element.
Build an element from a coefficient function.
Instances For
The coefficient of X^i.
Instances For
The coefficient at index i, or zero when P.d ≤ i.
Instances For
Distinguished elements #
ofBase places a coefficient-ring element in the constant coordinate, and gen has the
coordinates of X. The quotient bridge over a field promotes the constant embedding to an
Algebra structure and identifies the reduced power gen ^ d with monomialMod d.
Place a coefficient-ring element in the constant coordinate.
Instances For
The coordinate vector with coefficient one at X and zero elsewhere.
Instances For
Operations #
Multiplication is defined in terms of shiftReduce — the "multiply by X, reduce mod f"
map — whose iterates monomialMod k = shiftReduce^[k] 1 are the reduced monomials X^k mod f.
Everything downstream is proved from the single homomorphism law
toQuot (shiftReduce e) = rt * toQuot e.
Multiply by X and reduce modulo f.
X · (∑ eᵢ Xⁱ) = ∑ eᵢ X^(i+1), whose top term e_{d-1} X^d wraps via X^d = -∑ lowerₘ Xᵐ.
So coefficient m of the reduced result is e_{m-1} - e_{d-1} · lowerₘ, with e_{-1} = 0.
This is the single linear map whose iterates build the reduction table red.
Instances For
The reduced form of X^k modulo f, obtained by iterating shiftReduce (multiply by X,
reduce) k times from 1 = X^0. Its image under toQuot is rt ^ k.
Instances For
The monic-reduction product formula, representing multiplication in F[X] / f
when the coefficient ring is commutative.
Each product monomial Xⁱ⁺ʲ is reduced modulo f by monomialMod (i + j), so coefficient m
of the product collects xᵢ · yⱼ · [X^(i+j) mod f]ₘ over all pairs (i, j).
Instances For
Append cur, shiftReduce cur, …, n entries in all, to acc; the scan that builds red.
This is the table the shiftReduce docstring above refers to.
Instances For
The reduction table: red P holds X^k mod f for every k ≤ 2d - 2, i.e. every exponent a
product of two reduced elements can reach.
Built by one redScan from 1, so the whole table costs O(d^2); Vector.ofFn (monomialMod ·)
would iterate shiftReduce from scratch for every entry, O(d^3) in all. It exists purely for
speed: mul is the specification, and mulTbl below is the compiled implementation that
consults this table.
Instances For
A left fold that adds f i at each step is a plus the sum; the bridge from the loops the
compiler runs to the Finset.sums the specification is stated with.
Coefficient k of the unreduced product x · y in F[X], the convolution ∑_{i + j = k} xᵢ yⱼ,
as one loop over i with j = k - i; a pair outside [0, d) contributes zero. k ranges over
[0, 2d - 1), the degrees a product of two reduced elements can reach.
Deliberately a separate function over its own Mul and Add instances, @[noinline] and
@[nospecialize], and likewise contractCoeff below. Written inside mulTbl, or inlined or
specialised on the Ring F instance, * and + on F are re-derived from the ring dictionary
on every step of the innermost loop, through projections that allocate an intermediate structure
each time; the emitted C of the first loop run had instDistribOfSemiring in the loop body.
Here the two operations arrive as arguments, derived once per call of mulTbl, and the loop
only applies them. (nospecialize matters: instance arguments are specialised even without
@[specialize] on the callee.)
Instances For
Coefficient m of the reduction of the unreduced product prod against the table tbl:
∑_k prodₖ · [X^k mod f]ₘ. See convCoeff for why this is a separate function.
Instances For
Table-driven multiplication: the compiled implementation of mul.
Mathematically identical to mul, in two stages: the unreduced product x · y in F[X],
2d - 1 coefficients by convCoeff, then one contraction of those against the reduction table
red by contractCoeff. That is d^2 + (2d - 1) d coefficient multiplications where mul
performs d^3, and the reduced monomials come from the table instead of being re-derived by
monomialMod for every output coefficient. The sums are Fin.foldl loops rather than
Finset.sum, which compiles to list-building Multiset machinery.
mul remains the definition everything is proved about; mul_eq_mulTbl below swaps this in for
compilation via @[csimp]. The loops live in convCoeff and contractCoeff, for the reason
given there.
Specialised on P as well as on the instances: at a call site whose modulus is a constant, which
is every concrete extension field, the table red P is then a closed term the compiler
evaluates once, rather than being rebuilt on every multiplication.
Instances For
convCoeff from zero is the convolution sum, with the second index as a coeffNat.
The reindexing behind mul_eq_mulTbl: summing g (i + j) over j < d is summing g k over
the k < 2d - 1 that i + j reaches, for a fixed i < d.
Nat-power by binary exponentiation, so x ^ n costs O(log n) multiplications.
Coefficients of the operations #
ofBase agrees with 1 on the multiplicative unit.
ofBase agrees with 0.
ofBase agrees with the ℕ-cast, so scalars and numerals do not diverge.
ofBase agrees with the ℤ-cast.
The canonical inverse candidate x ^ (q^d - 2).
Inverse laws require finite-cardinality and irreducibility certificates. For arbitrary q,
this operation need not send zero to zero.
Instances For
Binomial extensions as a special case #
A binomial extension F[X] / (X^d - W) is the case lower = (-W, 0, …, 0). BinomialParams
keeps the W-only interface; toExtensionParams maps it into the general framework. The
polynomial correspondence and binomial irreducibility criterion are proved separately.
Parameters for the quotient F[X] / (X^d - W): the degree, constant W, and a proposed
base cardinality. The modulus has lower coefficients (-W, 0, …, 0).
- d : ℕ
The degree of the extension.
- W : F
Degree at least two; a degree-one "extension" is just
F.- q : ℕ
The proposed base cardinality used by the inverse exponent.
Instances For
The general-framework parameters for the binomial modulus X^d - W: the lower coefficient
vector is (-W, 0, …, 0).