Data produced by modular prime selection: the selected prime, the image of the input polynomial over that prime field, and its modular factors.
- p : Nat
The selected prime modulus.
- bounds : ZMod64.Bounds self.p
Word-arithmetic bounds witness for
p, available for instance search. The input polynomial reduced modulo
p.Its monic irreducible factors over the prime field.
Instances For
Equations
- Hex.instInhabitedPrimeChoiceData = { default := { p := 3, bounds := Hex.bounds_three, fModP := 0, factorsModP := #[] } }
Executable normalization data for the public integer factorization API.
The public input is first split into its integer content, primitive part,
initial X power, and primitive square-free part. The Berlekamp-Zassenhaus
prime/lift/factorization computation runs on squareFreeCore; the other fields are
reassembled around the resulting factors of the square-free part.
- content : Int
The signed-independent integer content of the input.
- primitive : ZPoly
The content-free input with normalized sign.
- xPower : Nat
The largest exponent of
Xdividing the primitive input. - xFreePrimitive : ZPoly
The primitive input after removing its initial power of
X. - squareFreeCore : ZPoly
The primitive product of the distinct nonzero irreducible factors.
- repeatedPart : ZPoly
The primitive repeated-factor contribution.
Instances For
Executable data for the integer scaling transform that sends a primitive polynomial with positive leading coefficient to a monic integer polynomial with the same roots (scaled by the leading coefficient).
If core has degree n and leading coefficient c, monic is the
coefficientwise integer polynomial c^(n-1) * core (X / c): lower coefficient
a_i becomes a_i * c^(n-1-i) and the leading coefficient is normalised to
1.
- core : ZPoly
The primitive positive-leading polynomial being transformed.
- leadingCoeff : Int
The leading coefficient of
core. - degree : Nat
The degree of
core. - monic : ZPoly
The integral monic polynomial obtained by the scaling transform.
Instances For
The degree-dependent transform used for repeated-factor recovery.
Equations
- Hex.ZPoly.ToMonicData.transformedCore core degree = { coeffs := Hex.ZPoly.ToMonicData.transformedCoeffs core degree, normalized := ⋯ }
Instances For
The transformed coefficient array has one entry per degree up to and including the prescribed top degree.
The transformed coefficient array's top entry is one. Not @[simp]: the
getD left-hand side is not simp-normal (simp rewrites it to a getElem
access through transformedCoeffs_size); transformedCore_coeff_top applies
it explicitly.
The transformed polynomial stores degree + 1 coefficients.
The coefficient in the prescribed top degree of the transformed polynomial is one.
The transformed polynomial is monic in the prescribed degree.
The transformed polynomial's degree is the prescribed degree.
Build the ToMonicData packet for a square-free part by the integer scaling transform.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The packet records the source's leading coefficient.
The packet records the source's degree.
The polynomial stored by toMonic is monic, including the degenerate
constant branches.
The monic field of toMonic core is monic once the source has positive
degree.
The monic field preserves the recorded degree in nonconstant cases.
Applying toMonic to an already-monic polynomial leaves its monic field equal
to the original.
Public factorization result for an integer polynomial Hex.ZPoly.
The scalar carries the input's signed content: for nonzero inputs this is
sign(lc f) * ZPoly.content f, while zero inputs use scalar 0. Polynomial
factors are primitive, positive-leading-coefficient factors stored with
explicit multiplicities; factor order remains operational, with the
mathematical contract expressed by multiplying the scalar and stored factors.
- scalar : Int
Signed scalar absorbing both sign and integer content.
Polynomial factors paired with explicit positive multiplicities.
Instances For
Equations
Instances For
Natural powers of an integer polynomial.
Equations
- Hex.Factorization.polyPow f 0 = 1
- Hex.Factorization.polyPow f n.succ = Hex.Factorization.polyPow f n * f
Instances For
The zeroth factor power is one.
Each successive factor power multiplies by the factor once more.
Expand multiplicity pairs into the ordered polynomial product.
Equations
- φ.product = Array.foldl (fun (acc : Hex.ZPoly) (factor : Hex.ZPoly × Nat) => acc * Hex.Factorization.polyPow factor.fst factor.snd) (Hex.DensePoly.C φ.scalar) φ.factors
Instances For
A factorization with no polynomial factors multiplies to its scalar.
Characterize product using the public factorPower wrapper instead of the
private recursion used internally.
Compute the normalization data required before the square-free computation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compute an integer polynomial's content and primitive part together. The logical surface is the ordinary pair of operations.
Equations
Instances For
One-pass runtime implementation of ZPoly.contentPrimitive: compute
the coefficient gcd once, then reuse it for both the content and coefficient
division.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pointwise agreement between the specification contentPrimitive and its
single-pass compiled implementation.
@[csimp] bridge routing compiled contentPrimitive calls to the
single-pass implementation.
Certified trial prime for the modular square-free fast path. 499 is a
cheap fixed choice: it is large enough that a distinct-root input rarely reduces
non-square-free at it, but it carries no guarantee (a rationally square-free
input whose discriminant is divisible by 499 reduces non-square-free and simply
takes the exact fallback -- never a wrong answer).
The trial prime 499 fits the word-arithmetic bounds of ZMod64.
The prepared-input form of the modular square-free trial.
Equations
- Hex.modularSquareFreeCoreFires q = (!Hex.DensePoly.isZero q && q.leadingCoeffModP 499 != 0 && q.separableModP 499)
Instances For
Fast implementation of normalizeForFactor: a machine-word 𝔽_p
square-freeness trial on the primitive x-free square-free part. When it fires (the input
is square-free over ℚ) the decomposition is trivial; otherwise it falls back to
the exact rational computation, inlined rather than a self-call so the @[csimp]
rewrite below does not make the fallback recurse. Proven equal to
normalizeForFactor.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[csimp] bridge routing compiled normalization through the modular
square-free fast path; the guard's soundness lemma makes both sides agree.
The factor X with the requested multiplicity, omitted at multiplicity zero.
Equations
- Hex.xPowerFactorArray power = (List.replicate power Hex.ZPoly.X).toArray
Instances For
Normalize a polynomial factor's sign by negating it whenever the leading
coefficient is negative. The result has nonnegative leading coefficient and is
associated to the input over ℤ.
Equations
- Hex.normalizeFactorSign f = if Hex.DensePoly.leadingCoeff f < 0 then Hex.DensePoly.scale (-1) f else f
Instances For
A polynomial factor is recorded by the factorization routines only
when it is not zero and not a unit (±1). Exposed publicly so that
Mathlib-side lemmas can transport the predicate into ¬ IsUnit over
Polynomial ℤ.
Equations
Instances For
Increase the multiplicity of f, or append it with multiplicity one.
Equations
Instances For
The X-power and repeated-part factors preceding the square-free factors.
Equations
Instances For
Factors that come from normalization before the primitive square-free part is factored.
Equations
Instances For
Reassemble normalization factors around the factors of the primitive square-free part.
Equations
- Hex.reassembleNormalizedFactors d coreFactors = Hex.normalizationPrefixFactors d ++ coreFactors
Instances For
Exact-division check on integer polynomials: returns the quotient when
quot * candidate = target exactly, and rejects unit candidates so iterated
calls cannot loop forever on ±1.
Equations
Instances For
Successful exact-division extracts a multiplication witness:
exactQuotient? target candidate = some quotient implies
quotient * candidate = target. Forward companion of
exactQuotient?_eq_some_of_mul_eq_monic_of_pos_degree.
Greedy peel of candidate^? out of target via repeated exact division.
Returns (residual, multiplicity) with the invariant
candidate ^ multiplicity * residual = target. The recursion is bounded by
fuel, which the caller chooses based on the source degree.
Equations
- One or more equations did not get rendered due to their size.
- Hex.consumeExactPower target candidate 0 = (target, 0)
Instances For
Fold consumeExactPower over a list of candidate factors, accumulating
emitted copies and tracking the residual that has not yet been factored.
Invariant: polyProduct emitted * residual = initialRepeatedPart.
Equations
Instances For
Compute (emitted, residual) where each candidate factor q from
coreFactors appears in emitted to the maximum multiplicity such that
q^k exactly divides the running repeated-part. The fuel is the source
size, which dominates any irreducible's multiplicity in repeatedPart.
Equations
- Hex.expandRepeatedPartFactorArray rp coreFactors = Hex.expandRepeatedPartFactorsAux coreFactors.toList rp (Hex.DensePoly.size rp + 1)