Documentation

HexBerlekampZassenhaus.Factorization

Method that produced a public factorization result.

  • constant : FactorMethod

    Constant-polynomial normalization.

  • quadratic : FactorMethod

    Direct extraction of integer roots from a quadratic.

  • classical : FactorMethod

    Exhaustive recombination of lifted modular factors.

  • lattice : FactorMethod

    Lattice recombination using logarithmic derivatives.

  • replay : FactorMethod

    Exact classical replay of a partition proposed by a small CLD lattice.

  • trial : FactorMethod

    Trial division by bounded candidate factors.

  • quadraticNorm : FactorMethod

    An iterated-quadratic-norm certificate proved the square-free core irreducible.

Instances For
    @[instance_reducible]
    Equations

    A short diagnostic name for a factorization method.

    Equations
    Instances For

      Trace derived from the same factorization result used by the untraced API.

      • method : FactorMethod

        The method that produced the returned factorization.

      • classicalDecline : Option DeclineReason

        The reason classical recombination declined, when it did.

      • classical : ClassicalStats

        Measurements from the classical recombination attempt.

      Instances For
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          structure Hex.ClassicalRun (f : ZPoly) :

          Result of normalization followed by classical recombination. A successful prime plan is retained even when recombination declines, so lattice recombination can consume the exact modular factorization already computed.

          Instances For
            structure Hex.FactorRun :

            Raw factors and trace produced by the total selector in one execution.

            • factors : Array ZPoly

              The raw polynomial factors before multiplicities are collected.

            • The method and classical-search measurements.

            Instances For
              def Hex.instDecidableEqFactorRun.decEq (x✝ x✝¹ : FactorRun) :
              Decidable (x✝ = x✝¹)
              Equations
              Instances For
                theorem Hex.bhksRecoveryCoreWithBound_ne_none_of_recovery_on_schedule (core : ZPoly) (B : Nat) (primeData : PrimeChoiceData) {start fuel target : Nat} {factors : Array ZPoly} (hfloor : bhksRecoveryFloor core target) (hmem : target henselPrecisionSchedule B start fuel) (hrecover : bhksRecover? core (core.directLiftData target primeData) = some factors) :
                bhksRecoveryCoreWithBound core B primeData start fuel none

                A successful lift-and-recover at any scheduled precision at or above the recovery floor forces the bounded BHKS recovery loop to return a result.

                Number of modular factors above which incremental partition replay is attempted before exhaustive direct recombination.

                Equations
                Instances For

                  Number of nonzero coefficients in a polynomial.

                  Equations
                  Instances For
                    def Hex.proposalEligible (f : ZPoly) (liftedFactorCount : Nat) :

                    Cost predicate for the proposal tier. Large dense inputs may benefit from support peeling and, after an exact peel, a small CLD lattice on the residual; lacunary inputs retain the direct classical route, whose coefficient filters are especially effective there.

                    Equations
                    Instances For
                      @[instance_reducible]
                      instance Hex.instDecidableProposalEligible (f : ZPoly) (liftedFactorCount : Nat) :
                      Decidable (proposalEligible f liftedFactorCount)
                      Equations
                      inductive Hex.ClassicalInput (f : ZPoly) :

                      Normalization and prime selection for the classical engine. The selected plan carries its defining equality, so every later route consumes exactly the prime data computed here.

                      Instances For

                        Normalize and select the modular input for direct recombination.

                        Once the modular factorization is in hand its support width is known, and with it the size of the recombination walk that would follow. At or above Hex.QuadraticNormCertificate.widthFloor that walk is expensive enough to be worth one attempt at the iterated-quadratic-norm certificate, which answers the whole square-free core as a single irreducible factor. A success is an ordinary answered, reassembled by the same Hex.reassemblePolynomialFactors as the constant and quadratic cases, so it returns the same Hex.Factorization any other singleton proof would. A failure falls through to planned with no state carried, and every route below the floor is untouched.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Execute direct recombination from an already selected modular plan.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Run the unrestricted classical method from a prepared input.

                            Equations
                            Instances For

                              Route an eligible normalized large-support input to proposal replay before direct recombination. All other inputs run the unrestricted classical method.

                              Equations
                              Instances For

                                Normalize once, select one modular plan, and execute the unrestricted direct-coordinate classical engine.

                                Equations
                                Instances For

                                  Cost-routed classical front end used by the total factorizer. A normalized eligible large-support input retains its plan and yields to proposal replay; every other input agrees with runClassical.

                                  Equations
                                  Instances For

                                    Raw factor array for the sole production classical method.

                                    Equations
                                    Instances For

                                      Factor via the direct-coordinate, size-ordered classical engine. Returns none only with a typed decline recorded by runClassical.

                                      Equations
                                      Instances For

                                        Classical factorization and typed trace derived from one shared execution.

                                        Equations
                                        Instances For

                                          Measurements from one selected-coordinate CLD lattice.

                                          • residualDegree : Nat

                                            Degree of the residual integer polynomial.

                                          • liftedFactorCount : Nat

                                            Lifted local factors represented by indicator coordinates.

                                          • coordinates : Array Nat

                                            Selected coefficient coordinates.

                                          • cutThresholds : Array Nat

                                            Per-column coefficient cut thresholds.

                                          • dimension : Nat

                                            Square lattice dimension.

                                          • henselPrecision : Nat

                                            Hensel exponent used by the CLD rows.

                                          • maxEntryBits : Nat

                                            Maximum bit length of an entry in the lattice basis.

                                          • reducedRows : Nat

                                            Rows produced by the exact native LLL reducer.

                                          • projectedRows : Nat

                                            Rows retained after exact LLL and the Gram-Schmidt cut.

                                          • indicatorCount : Nat

                                            Support classes suggested by row reduction.

                                          • supportSizes : Array Nat

                                            Sizes of the proposed lifted-factor support classes.

                                          • candidateDegrees : Array Nat

                                            Degrees of exactly reconstructed candidate pieces.

                                          • accepted : Bool

                                            Whether reconstruction produced an exact nontrivial partition.

                                          Instances For
                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Diagnostics for low-cardinality peeling, CLD partitioning, and replay.

                                              • classical : ClassicalStats

                                                Classical measurements, including peeled degrees and residual support.

                                              • Selected-coordinate lattices tried in order.

                                              • pieceDegrees : Array Nat

                                                Degrees of exact pieces presented to proved classical replay.

                                              • factorDegrees : Array Nat

                                                Degrees returned by the proved replay calls.

                                              Instances For
                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  Deterministic incremental widths for selected-coordinate CLD lattices.

                                                  Equations
                                                  Instances For

                                                    Candidate budget reserved for the proposal tier's complete low-cardinality levels. A later level that does not fit leaves the already peeled factors and exact residual intact.

                                                    Equations
                                                    Instances For

                                                      Maximum bit length among entries of a square CLD lattice basis.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        Cardinalities of proposed indicator support classes.

                                                        Equations
                                                        Instances For

                                                          Reduce a proposal lattice through the certified selector. Without an installed provider this is the exact native reducer; an installed external candidate is used only after Hex's certificate checks accept it.

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            Try one prefix of prepared selected-coordinate CLD data and reconstruct an exact candidate partition.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              Replay an incremental selected-coordinate schedule against one shared maximum-width CLD preparation until an exact partition is reconstructed.

                                                              Equations
                                                              Instances For

                                                                Prepare the largest requested CLD prefix once, then try its nested prefixes in order.

                                                                Equations
                                                                Instances For

                                                                  Replay the unrestricted proved classical factorizer on each exact proposal piece and concatenate the returned factor arrays.

                                                                  Equations
                                                                  Instances For

                                                                    Factor every proposed integer piece again with the existing proved classical factorizer.

                                                                    Equations
                                                                    Instances For

                                                                      A self-contained successful proposal and replay result. The proof fields are erased at runtime; they expose exactly the checks used at the executable acceptance boundary.

                                                                      Instances For

                                                                        Low-cardinality peeling, selected-coordinate CLD partitioning after exact progress, and proved classical replay from an existing modular plan. With no peeled factor, the proposal declines before building a lattice so production can proceed directly to its exact full-CLD fallback.

                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For

                                                                          Standalone proposal/replay entry. Production reuses the modular plan already selected by runClassical; this wrapper is retained for diagnostics.

                                                                          Equations
                                                                          • One or more equations did not get rendered due to their size.
                                                                          Instances For

                                                                            Raw factor array produced by the integer trial-division slow path.

                                                                            Handles the deg-0 square-free part and integer-root cases up front via the same constant/quadratic-root short-circuits as the classical method; the residual exhaustive branch selects to the standalone integer trial-division algorithm (exhaustiveIntegerTrialCoreFactorsWithBound). This is the trial-division method of the three-method factorize combinator.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For

                                                                              Factor using exhaustive recombination with the supplied coefficient bound.

                                                                              Equations
                                                                              Instances For

                                                                                Characterise the bounded integer trial-division slow wrapper as the raw factor array packed into the public Factorization representation.

                                                                                Factor using the integer trial-division path at the default Mignotte coefficient bound. This is the trial-division method of the three-method factorize combinator.

                                                                                Equations
                                                                                Instances For

                                                                                  Trial factorization uses the default coefficient bound.

                                                                                  Precision cap used by the public fast path.

                                                                                  The cap is the larger of the BHKS separation threshold bound of the primitive square-free part and the Mignotte coefficient bound of the input, so later termination proofs can use the same precision for both lattice separation and exact integer reconstruction.

                                                                                  The CLD lattice is built directly over (normalizeForFactor f).squareFreeCore. The square-free part remains explicit because it can have a larger coefficient norm than f (for f = (x¹⁸ - 1)(x¹⁹ - 1) the square-free part f / (x - 1) has coeffNormSq 36 against f's 4).

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    The cap dominates the BHKS resultant-precision bound of the primitive square-free part, the first of the four maxima defining it.

                                                                                    The cap clears the CLD column-adequacy floor of the primitive square-free part, so the lattice method's cap-precision run is column-adequate by construction.

                                                                                    The cap dominates the input polynomial's own Mignotte-style coefficient bound, so cap-precision recovery covers ordinary factor reconstruction.

                                                                                    The public precision cap clears the whole fast recovery acceptance floor, so the conditional loop always has admissible precisions on its schedule.

                                                                                    The cap dominates the Mignotte bound of the primitive square-free part itself, needed by the true-support nonemptiness argument at cap precision.

                                                                                    At the public precision cap, the monic lift for the primitive square-free part clears the BHKS separation threshold: 2 · bhksBound core < p ^ k. This is the hprec obligation of the lattice method's cap-precision irreducibility certification; it is what forces the cap's BHKS component to be computed from the square-free part rather than from f.

                                                                                    Variant of two_mul_bhksBound_squareFreeCore_lt_pow_cap keyed on the lattice method's prime-selection witness, matching the shape of the hprec side goal at the factorLatticeFactorsWithBound call site.

                                                                                    The CLD recovery's equivalence-class partition at this precision is the single all-ones class; the signature of an irreducible input (all lifted mod-p factors form the one integer factor). At column-adequate precision (bhksRecoveryFloor core ≤ k) this certifies irreducibility; the proven count lower bound forces a reducible square-free part to exhibit ≥ 2 classes there (squareFreeCore_irreducible_of_bhksSingleAllOnes in the Mathlib layer); while below the floor it may instead mean the lattice has not separated the factors yet, so callers must only trust it at k ≥ bhksRecoveryFloor core. (A cap-free CLD path would treat this partition as degenerate and decline, which is why such a path "misses" on Swinnerton-Dyer inputs; the lattice method uses this predicate, both in latticeCoreLoop's early stop and in the trailing cap check, to turn the declined-but-certified case into a positive irreducibility verdict.)

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For
                                                                                      def Hex.latticeCoreWithBound (core : ZPoly) (B : Nat) (primeData : PrimeChoiceData) (k fuel : Nat) :

                                                                                      Lattice factorization loop entry: bhksRecoveryCoreWithBound with certificate-backed early termination on the single all-ones partition. Computes the CLD column-adequacy floor once (through the irreducible bhksRecoveryThreshold) and runs latticeCoreLoop.

                                                                                      Equations
                                                                                      Instances For
                                                                                        theorem Hex.latticeCoreWithBound_ne_none_of_recovery_on_schedule (core : ZPoly) (B : Nat) (primeData : PrimeChoiceData) {start fuel target : Nat} {factors : Array ZPoly} (hfloor : bhksRecoveryFloor core target) (hmem : target henselPrecisionSchedule B start fuel) (hrecover : bhksRecover? core (core.directLiftData target primeData) = some factors) :
                                                                                        latticeCoreWithBound core B primeData start fuel none

                                                                                        A successful fixed-precision recovery on the scheduled lattice path forces the certificate-aware lattice recovery loop to return some result.

                                                                                        theorem Hex.latticeCoreWithBound_some_spec {core : ZPoly} {B : Nat} {primeData : PrimeChoiceData} {k fuel : Nat} {cf : Array ZPoly} (h : latticeCoreWithBound core B primeData k fuel = some cf) :
                                                                                        bhksRecoveryCoreWithBound core B primeData k fuel = some cf cf = #[core] (k' : Nat), bhksRecoveryFloor core k' bhksSingleAllOnesPartition core (core.directLiftData k' primeData) = true

                                                                                        A successful latticeCoreWithBound call is either a bhksRecoveryCoreWithBound success or the early irreducibility certificate; the singleton #[core] with a witness precision k' clearing bhksRecoveryFloor core whose partition is the single all-ones class. The witness pair is exactly the hB_floor/hbhks input of the Mathlib layer's squareFreeCore_irreducible_of_bhksSingleAllOnes.

                                                                                        Large-r lattice factorization factorisation: the van Hoeij CLD recovery, plus irreducibility certification. When the recovery splits core, use its factors; when the loop's certificate-backed early stop fires (single all-ones partition at column-adequate precision), core is irreducible (#[core]); when the loop declines all the way to the cap, check the cap-precision partition once more: the single all-ones class means core is irreducible (#[core]), anything else is a genuine failure (none).

                                                                                        Both certification arms are conditional on the column-adequacy floor: the loop's early stop only examines the partition at k ≥ bhksRecoveryThreshold core, and the trailing cap check requires bhksRecoveryThreshold core ≤ B; below the floor the all-ones partition may merely mean the lattice has not separated the factors yet, so certifying there would be unsound. The public factorLattice supplies latticePrecisionCap, which clears the floor by construction.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For

                                                                                          Reassemble a lattice result from an existing direct prime plan. The plan is indexed by the normalized polynomial, so callers cannot reuse modular factors for a different polynomial.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For

                                                                                            Raw factor array for the large-r lattice method: the CLD lattice recovery, certifying irreducibility at the cap so that Swinnerton-Dyer / high-r irreducibles return some #[f] instead of none.

                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For

                                                                                              The bounded lattice method represents the zero polynomial by its normalized zero factor.

                                                                                              Attempt lattice recombination with the supplied coefficient bound.

                                                                                              Equations
                                                                                              Instances For

                                                                                                Van Hoeij CLD lattice method (large-r) at the full BHKS precision cap. Certifies irreducibility (unlike a cap-free CLD path), so it returns some on Swinnerton-Dyer and cyclotomic high-r irreducibles.

                                                                                                Equations
                                                                                                Instances For

                                                                                                  Package the CLD result from an existing modular plan, retaining the trial factorizer as the total backstop.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For

                                                                                                    Total integer-polynomial factorization with bounded fast paths.

                                                                                                    Small modular supports use the proved size-ordered classical search directly. Large supports first search support sizes one through three, then reuse the same Hensel lift to keep peeling factors of support size one or two. After at least one exact peel, the residual and its complementary lifted support pass to a small leading-column CLD lattice for partitioning. Without exact progress, production skips that speculative lattice and proceeds directly to the full CLD fallback. The small lattice is only a proposal: exact product checks and proved classical factorization of every proposed piece decide acceptance. If that composition declines, the full proved CLD method remains the fallback, followed by trial division when necessary.

                                                                                                    Returns the chosen Factorization and a DirectFactorTrace whose method records which method answered. A classical decline retains its direct prime plan, and the lattice fallback consumes that plan without repeating modular factorization.

                                                                                                    Self-certifying. Each non-backstop method's Factorization is accepted only when it reconstructs the input (Factorization.product φ = f, decidable on ZPoly); on the (corpus-never) miss it falls through to the proven factorTrial backstop. This makes Factorization.product (ZPoly.factorize f) = f provable unconditionally without yet proving the classical recombination loop reconstructs (that, with per-factor irreducibility, is the separate re-proof step). Proposal irreducibility comes solely from the proved replay calls, not from trusting the selected-column lattice.

                                                                                                    The raw factors and trace are retained together so every public view observes the same selection execution.

                                                                                                    Equations
                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                    Instances For

                                                                                                      Factor an integer polynomial and return a trace of the selected method.

                                                                                                      Equations
                                                                                                      Instances For

                                                                                                        The public total factorisation of a Hex.ZPoly.

                                                                                                        Small modular supports use Hex.factorClassical. Large supports reuse one Hensel lift for repeated exact low-cardinality peeling. Once peeling makes exact progress, a selected-column CLD proposal partitions the hard residual; otherwise the speculative tier is skipped. Every proposed piece is checked and factored again by the proved classical method. If the proposal declines, Hex.factorLattice tries full CLD recombination. Hex.factorTrial is the total backstop. It does not depend on Hex.choosePrimeData?, so this function still returns a factorisation when prime selection fails.

                                                                                                        This definition lives in the Hex.ZPoly namespace, so it can be called with dot notation as f.factorize.

                                                                                                        Equations
                                                                                                        Instances For

                                                                                                          The irreducible factors of f with their multiplicities: the factors field of the full factorisation f.factorize.

                                                                                                          Equations
                                                                                                          Instances For

                                                                                                            The CLD lattice method's Factorization is the raw lattice factor array packed through factorizationOfFactors f.

                                                                                                            Raw factor array produced by the same total-selection execution as ZPoly.factorize.

                                                                                                            Equations
                                                                                                            Instances For

                                                                                                              The cost-based hybrid factorisation is the factorizationOfFactors-packed form of its raw factor array factorFactors. Every method (classical / lattice / trial) assembles via factorizationOfFactors f, so this correspondence lets the structural factorizationOfFactors_entry_* lemmas apply to every entry of the hybrid result.

                                                                                                              A modular plan retained by the classical run is exactly the plan selected for the normalized polynomial.

                                                                                                              A modular plan retained by the full classical run is exactly the plan the direct prime selector chose for the normalized polynomial.

                                                                                                              A modular plan retained by the cost router is the unique plan selected in its classical input.

                                                                                                              theorem Hex.routeClassical_success (f : ZPoly) {factors : Array ZPoly} (h : (routeClassical f).factors = some factors) :

                                                                                                              A successful cost-routed classical run is the same success returned by the unrestricted public classical method.

                                                                                                              Every factor returned by a planned CLD run comes from its successful lattice result or from the trial-factorization backstop.

                                                                                                              Every raw factor of the total selector comes from proposal replay, the classical method, the CLD lattice method, or the trial backstop.

                                                                                                              Every raw factor of the total selector comes from proposal replay or one of the established classical, lattice, and trial branches.

                                                                                                              Scalar contract for a factorization assembled from a raw factor array. The public statement exposes the signed-content convention without exposing the private helper used to compute it.

                                                                                                              @[simp]

                                                                                                              Packing raw factors of the zero polynomial records the zero scalar.

                                                                                                              A nonzero input with negative leading coefficient records the negated content as its scalar.

                                                                                                              A nonzero input with positive leading coefficient records its content as its scalar.

                                                                                                              The packed scalar vanishes exactly on the zero input.

                                                                                                              Scalar contract for the default public factorization entry point.

                                                                                                              @[simp]

                                                                                                              The default factorization of 0 records the zero scalar.

                                                                                                              The default factorization of 0 records no polynomial factors: the primitive square-free part of 0 is the unit 1, so every reassembled raw factor is dropped by the shouldRecordPolynomialFactor filter. This lets factorize_irreducible_of_nonUnit discharge the degenerate f = 0 case vacuously, without a nonzero hypothesis.

                                                                                                              A nonzero polynomial with negative leading coefficient records the negated content as its scalar, keeping every stored factor's leading coefficient positive.

                                                                                                              A nonzero polynomial with positive leading coefficient keeps its content as scalar factor.

                                                                                                              The public scalar vanishes exactly on the zero input.

                                                                                                              theorem Hex.factorize_entry_multiplicity_pos (f : ZPoly) (entry : ZPoly × Nat) (hmem : entry f.factorize.factors.toList) :
                                                                                                              0 < entry.snd

                                                                                                              Every recorded entry of the default public factorization has positive multiplicity.

                                                                                                              Every recorded entry of the default public factorization is fixed by normalizeFactorSign.