Skip to content

feat(univariate): enumerate the polynomials of degree below n - #420

Merged
alexanderlhicks merged 4 commits into
mainfrom
alh/bounded-degree-enumeration
Nov 19, 2026
Merged

alexanderlhicks merged 4 commits into
mainfrom
alh/bounded-degree-enumeration

Conversation

@alexanderlhicks

@alexanderlhicks alexanderlhicks commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

CompPoly has a coefficient equivalence for polynomials of degree below n. Finite searches also need an executable enumeration and a way to relate their results to Mathlib polynomials.

Change

CompPoly.Univariate.Linear defines ofFnEquiv from Fin n → R to ↥(degreeLT n). Its inverse is degreeLTCoeffs, and ofCoeffVector_eq_ofFnEquiv relates it to the fixed-width codec. The existing ofFn_mem_degreeLT and ofFn_coeff_of_mem_degreeLT lemmas move from Bytes to Linear, which Bytes already imports. Their names and statements stay the same.

instFintypeDegreeLT enumerates the subtype from coefficient functions using [Zero R] [BEq R] [LawfulBEq R] [Fintype R]. At n = 0, the enumeration contains only the zero polynomial. card_degreeLT gives the cardinality Fintype.card R ^ n for any enumeration of the subtype, using only [Zero R] and the two Fintype instances.

CompPoly.Univariate.ToPoly.Degree connects bounded searches to Mathlib polynomials over [Semiring R] [BEq R] [LawfulBEq R].

  • exists_degreeLT_toPoly_iff and forall_degreeLT_toPoly_iff transport a single quantifier.
  • forall₂_degreeLT_toPoly_iff transports two universal quantifiers with separate degree bounds.
  • exists_degreeLT_toPoly_iff_of_degree_lt lets the predicate supply the degree bound.

ArkLib's exact combiner error evaluators will use this API in place of their local copy.

Tests and validation

A downstream by decide test checks the enumeration size over ZMod 2. A second theorem checks that the cardinality agrees across two lawful equality instances. Compiled tests over ZMod 5 check counts, distinct polynomials, the zero bound, and searches that inspect polynomial values. The bridge examples prove that those decisions agree with the corresponding Mathlib propositions.

  • lake build --wfail and lake test --wfail pass.
  • ./scripts/lint-style.sh, ./scripts/check-imports.sh, and the documentation integrity check pass.
  • The writing checker reports no suggestions on the diff.
  • lake exe axiomsweep --check passes. This PR adds no admissions and leaves the axiom baseline unchanged.

alexanderlhicks and others added 2 commits November 18, 2026 23:10
`ofFn_mem_degreeLT` and `ofFn_coeff_of_mem_degreeLT` describe how `ofFn`
interacts with `degreeLT`. They do not use any serialization API, so this
commit moves them from `Univariate/Bytes.lean` to `Univariate/Linear.lean`,
which defines `degreeLT`. Their statements, proofs and names do not change.
`Univariate/Bytes.lean` imports `Univariate/Linear.lean`, so every module
that used the lemmas still sees them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ofFnEquiv n` is the equivalence between the coefficient vectors
`Fin n → R` and `↥(degreeLT n)`, through `ofFn` and `coeff`. Over a finite
coefficient type, `instFintypeDegreeLT` makes `↥(degreeLT n)` a `Fintype`
through this equivalence. The enumeration is executable and needs only
`[Zero R] [BEq R] [LawfulBEq R] [Fintype R]`. `card_degreeLT` states that
`↥(degreeLT n)` has `card R ^ n` elements, for every `Fintype` instance.
The simp lemmas `ofFnEquiv_apply_val` and `ofFnEquiv_symm_apply`
characterize the equivalence, whose body stays opaque downstream.

Four lemmas in `ToPoly/Degree.lean` restate a quantifier over
`↥(degreeLT n)` as a quantifier over Mathlib polynomials of degree below
`n`:

* `exists_degreeLT_toPoly_iff`
* `forall_degreeLT_toPoly_iff`
* `forall₂_degreeLT_toPoly_iff`
* `exists_degreeLT_toPoly_iff_of_degree_lt`

`toPoly` is noncomputable, so these lemmas serve only in proofs. They let
a finite search over the enumeration prove a statement about all Mathlib
polynomials below a degree bound. ArkLib's exact affine-combiner error
evaluators can use them in this way.

The test module `CompPolyTests.Univariate.ToPoly.Degree` evaluates the
enumeration over `ZMod 5` with `#guard` in compiled code. It checks the
counts `5 ^ n`, the single zero polynomial at `n = 0`, and searches for
known polynomials. Its examples are kernel-checked theorems. Each one
states that a search returns `true` exactly when the corresponding
statement about Mathlib polynomials holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Summary

Mathematical Formalization

Enumeration and linear isomorphism. The core addition is the module CompPoly.Univariate.Linear, which provides:

  • ofFnEquiv – an explicit linear isomorphism between Fin n → R and ↥(degreeLT n), implemented by the map (a i) ↦ ∑ a i * X^i.
  • instFintypeDegreeLT – a Fintype instance on the subtype degreeLT n when R is finite (requires [Zero R] [BEq R] [LawfulBEq R] [Fintype R]). At n = 0 the subtype contains only the zero polynomial.
  • card_degreeLT – the cardinality formula Fintype.card (↥(degreeLT n)) = (Fintype.card R) ^ n, valid for any [Zero R] and the two Fintype instances.
  • ofFnEquiv_symm_eq_degreeLTCoeffs – relates the inverse to the existing fixed-width coefficient vector.

Quantifier transport lemmas. The file CompPoly.Univariate.ToPoly.Degree adds four lemmas that connect back‐end proofs over the finite subtype ↥(degreeLT n) to the (noncomputable) Mathlib polynomial type:

  • exists_degreeLT_toPoly_iff
  • forall_degreeLT_toPoly_iff
  • forall₂_degreeLT_toPoly_iff (two universal quantifiers with separate degree bounds)
  • exists_degreeLT_toPoly_iff_of_degree_lt (the predicate supplies the degree bound)

These lemmas are intended for proofs only – they allow an executable predicate decided by a search over instFintypeDegreeLT to be related to the corresponding Mathlib predicate via .toPoly. ArkLib's exact combiner error evaluators will use this API in place of a local copy.

Refactoring

  • The theorems ofFn_mem_degreeLT and ofFn_coeff_of_mem_degreeLT have been moved from CompPoly.Univariate.Bytes to CompPoly.Univariate.Linear. Their names and statements are unchanged. Bytes now imports Linear and re‑exports the lemmas (the diff moves the definitions, not just the declarations).

Documentation

  • CompPoly/Univariate/README.md – updated to list the key definitions and lemmas introduced in Linear.lean and ToPoly/Degree.lean.
  • docs/wiki/field-extensions.md – rewritten to clarify that Ext.toQuot picks a canonical representative of degree below d, and to point to the degreeLT API in Linear.lean and the degreeLTEquiv in ToPoly/Degree.lean. The previous remark about those APIs being “unwired” has been removed.

Tests

  • tests/CompPolyTests/Univariate/ToPoly/Degree.lean – new test file that verifies:
    • Cardinalities over ZMod 2 and ZMod 5 using Fintype.card and card_degreeLT (by decide).
    • Independence of cardinality from the BEq instance.
    • Polynomial distinctness, degree bounds, existence of a specific linear‑factor polynomial, and counting of zeros at 1 and 2 (via #guard).
    • Three kernel‑checked example equivalences that connect searches over ↥(degreeLT n) to universal/existential statements over Mathlib polynomials (forall_degreeLT_toPoly_iff, exists_degreeLT_toPoly_iff_of_degree_lt, forall₂_degreeLT_toPoly_iff).
  • tests/CompPolyTests.lean – added a public import CompPolyTests.Univariate.ToPoly.Degree line to expose the new test module.

No sorry or admit are added anywhere in this PR.


Statistics

Metric Count
📝 Files Changed 7
✅ Lines Added 284
❌ Lines Removed 32

Lean Declarations

✏️ Removed: 2 declaration(s)

CompPoly/Univariate/Bytes.lean (2)

  • theorem ofFn_coeff_of_mem_degreeLT {n : ℕ} {p : CPolynomial R} (hp : p ∈ degreeLT (R
  • theorem ofFn_mem_degreeLT {n : ℕ} (f : Fin n → R) : ofFn f ∈ degreeLT (R
✏️ Added: 20 declaration(s)

CompPoly/Univariate/Bytes.lean (1)

  • theorem ofCoeffVector_eq_ofFnEquiv (n : ℕ) (v : Vector R n) :

CompPoly/Univariate/Linear.lean (8)

  • def ofFnEquiv (n : ℕ) : (Fin n → R) ≃ ↥(degreeLT (R
  • instance instFintypeDegreeLT [Fintype R] (n : ℕ) : Fintype ↥(degreeLT (R
  • theorem card_degreeLT [Zero R] [Fintype R] (n : ℕ) [Fintype ↥(degreeLT (R
  • theorem ofFnEquiv_apply_val (n : ℕ) (f : Fin n → R) : (ofFnEquiv n f).val = ofFn f
  • theorem ofFnEquiv_symm_apply (n : ℕ) (p : ↥(degreeLT (R
  • theorem ofFnEquiv_symm_eq_degreeLTCoeffs (n : ℕ) :
  • theorem ofFn_coeff_of_mem_degreeLT {n : ℕ} {p : CPolynomial R} (hp : p ∈ degreeLT (R
  • theorem ofFn_mem_degreeLT {n : ℕ} (f : Fin n → R) : ofFn f ∈ degreeLT (R

CompPoly/Univariate/ToPoly/Degree.lean (4)

  • theorem exists_degreeLT_toPoly_iff (n : ℕ) (Q : R[X] → Prop) :
  • theorem exists_degreeLT_toPoly_iff_of_degree_lt (n : ℕ) (Q : R[X] → Prop)
  • theorem forall_degreeLT_toPoly_iff (n : ℕ) (Q : R[X] → Prop) :
  • theorem forall₂_degreeLT_toPoly_iff (m n : ℕ) (Q : R[X] → R[X] → Prop) :

tests/CompPolyTests/Univariate/ToPoly/Degree.lean (7)

  • abbrev F : Type
  • example : Fintype.card ↥(degreeLT (R
  • example : Fintype.card ↥(degreeLT (R
  • example : decide (∀ f g : ↥(degreeLT (R
  • example : decide (∀ p : ↥(degreeLT (R
  • example : decide (∃ p : ↥(degreeLT (R
  • example {R : Type*} [Zero R] [Fintype R] (b₁ b₂ : BEq R)

sorry Tracking

  • No sorrys were added, removed, or affected.

📋 **Additional Analysis**

The diff is well-structured overall and follows most guidelines. The main issue is a redundant duplicate import block in the new test file.


📄 **Per-File Summaries**
  • CompPoly/Univariate/Bytes.lean: Removed the theorems ofFn_mem_degreeLT and ofFn_coeff_of_mem_degreeLT (which related ofFn to membership in degreeLT). Added the theorem ofCoeffVector_eq_ofFnEquiv stating ofCoeffVector n v = ofFnEquiv n (fun i => v[i]), proved via Subtype.ext and ofFnEquiv_apply_val; the definitions coeffVector, ofCoeffVector, and ofCoeffVector_coeffVector are otherwise unchanged.
  • CompPoly/Univariate/Linear.lean: Adds ofFn_mem_degreeLT, ofFn_coeff_of_mem_degreeLT, ofFnEquiv, ofFnEquiv_apply_val, ofFnEquiv_symm_apply, instFintypeDegreeLT, card_degreeLT, and ofFnEquiv_symm_eq_degreeLTCoeffs to establish an executable linear equivalence between coefficient vectors Fin n → R and the subtype of polynomials of degree below n, and to prove a cardinality formula for that subtype over finite coefficient types. No sorry or admit appear in the diff. Alexander Hicks is added as an author of the file. The module-level docstring is expanded to describe the new definitions.
  • CompPoly/Univariate/README.md: The README was updated to include explicit lists of key lemmas and definitions in the ToPoly/Degree.lean and Linear.lean sections. For ToPoly/Degree.lean, the entry now names the four quantifier-transport lemmas (exists_degreeLT_toPoly_iff, forall_degreeLT_toPoly_iff, forall₂_degreeLT_toPoly_iff, exists_degreeLT_toPoly_iff_of_degree_lt) and describes their role in connecting bounded-degree searches with Mathlib polynomials. For Linear.lean, the entry now mentions the isomorphism ofFnEquiv that identifies degreeLT n with coefficient functions on Fin n, the instFintypeDegreeLT instance that enumerates the subtype over a finite coefficient type, and the card_degreeLT cardinality formula.
  • CompPoly/Univariate/ToPoly/Degree.lean: This change adds a new section of quantifier lemmas that transport statements over ↥(degreeLT n) to corresponding statements over Mathlib polynomials with degree bounds. The theorems exists_degreeLT_toPoly_iff, forall_degreeLT_toPoly_iff, forall₂_degreeLT_toPoly_iff, and exists_degreeLT_toPoly_iff_of_degree_lt are introduced, each establishing an equivalence between a quantifier over degreeLT n (applied through toPoly) and a quantifier over R[X] with an explicit or implicit degree condition. Importantly, these lemmas are intended only for proofs because toPoly is noncomputable, but they allow an executable predicate to be decided by a search over instFintypeDegreeLT and then related to the corresponding Mathlib predicate. The docstring for the file was also expanded to describe degreeLTEquiv and summarize each new theorem.
  • docs/wiki/field-extensions.md: The diff rewrites the documentation paragraph about degree bounds in field-extensions.md. It clarifies that Ext.toQuot picks a canonical representative of degree below d, and that the theorem degree_repr_lt in Extension/Bridge.lean proves this bound using Polynomial.degree_sum_le and Polynomial.degree_C_mul_X_pow_le. It also notes that a separate CPolynomial API defines degreeLT in Univariate/Linear.lean and degreeLTEquiv in Univariate/ToPoly/Degree.lean, and removes the previous commentary about these APIs being unwired from the framework.
  • tests/CompPolyTests.lean: Added a public import CompPolyTests.Univariate.ToPoly.Degree line to the import block at the bottom of the file. This exposes the test module Degree (likely containing tests for degree-related operations) from the CompPolyTests.Univariate.ToPoly subdirectory, making its definitions and tests available when CompPolyTests is imported. No existing imports, definitions, or theorems were modified; no sorry or admit were added.
  • tests/CompPolyTests/Univariate/ToPoly/Degree.lean: This new test file Degree.lean adds executable enumeration and kernel-checked theorems for degreeLT (bounded-degree polynomials over finite fields). It verifies cardinalities (Fintype.card) over ZMod 2 and ZMod 5 using by decide and card_degreeLT, and proves that cardinality is independent of the BEq instance. It includes #guard checks for polynomial distinctness, degree bounds, existence of a specific linear factor polynomial, and the number of polynomials vanishing at 1 and 2. The file also provides three kernel-checked example equivalences (using forall_degreeLT_toPoly_iff, exists_degreeLT_toPoly_iff_of_degree_lt, and forall₂_degreeLT_toPoly_iff) that connect finite searches over ↥(degreeLT n) to universal/existential statements about Mathlib Polynomial over ZMod 5. No sorry or admit are present.

Last updated: 2026-11-19 13:30 UTC.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Build Timing Report

  • Commit: f07c3eb
  • Message: Merge b14a49f into afb9b13
  • Ref: alh/bounded-degree-enumeration
  • Comparison baseline: ea4b8de from the previous successful PR update.
  • Measured on ubuntu-latest with /usr/bin/time -p.
  • Commands: library build (warm) lake build; test path lake test.
  • Clean build was skipped (warm/incremental CI; no toolchain or lake-manifest change). Runs automatically when lean-toolchain or lake-manifest.json changes, or via Actions → Lean Action CI → Run workflow with clean_build.
Measurement Baseline (s) Current (s) Delta (s) Status
Library build (warm) 114.70 1.94 -112.76 ok
Test path 20.80 1.22 -19.58 ok

Incremental Rebuild Signal

  • Warm-only run: default CI reuses cached oleans and rebuilds dirty modules only. No same-job clean:warm ratio.

Slowest Current Build Files (warm library build)

Showing 1 slowest current targets from the warm library build log, with comparison against the baseline warm library build log when available.

Current (s) Baseline (s) Delta (s) Path
1.10 1.20 -0.10 CompPoly/Univariate/Linear.lean

State the cardinality theorem without equality assumptions and relate the coefficient equivalence to the linear map and vector codec. Check downstream cardinality reduction and scope the prime instance to the linear-factor test.
@alexanderlhicks
alexanderlhicks merged commit 1a9ad0e into main Nov 19, 2026
7 checks passed
alexanderlhicks added a commit to Verified-zkEVM/ArkLib that referenced this pull request Nov 20, 2026
Move the CompPoly pin from `afb9b13` to `1a9ad0e`, the merge of
Verified-zkEVM/CompPoly#420. That commit is the only change between the
two revisions. It adds `instFintypeDegreeLT`, an executable enumeration
of the polynomials of degree below `n`, to `CompPoly.Univariate.Linear`.
It also adds four lemmas to `CompPoly.Univariate.ToPoly.Degree` that
restate a quantifier over these polynomials as a quantifier over Mathlib
polynomials. The evaluators in `AffineCombiner/Computable.lean`
enumerate with `instFintypeDegreeLT`, and the proofs that relate them to
the semantic predicates use three of these lemmas.

CompPoly at `1a9ad0e` uses Lean v4.36.0 and the same Mathlib revision as
ArkLib, so only the CompPoly entries of `lakefile.toml` and
`lake-manifest.json` change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexanderlhicks added a commit to Verified-zkEVM/ArkLib that referenced this pull request Nov 20, 2026
…1548)

* chore(deps): bump CompPoly to 1a9ad0e (Verified-zkEVM/CompPoly#420)

Move the CompPoly pin from `afb9b13` to `1a9ad0e`, the merge of
Verified-zkEVM/CompPoly#420. That commit is the only change between the
two revisions. It adds `instFintypeDegreeLT`, an executable enumeration
of the polynomials of degree below `n`, to `CompPoly.Univariate.Linear`.
It also adds four lemmas to `CompPoly.Univariate.ToPoly.Degree` that
restate a quantifier over these polynomials as a quantifier over Mathlib
polynomials. The evaluators in `AffineCombiner/Computable.lean`
enumerate with `instFintypeDegreeLT`, and the proofs that relate them to
the semantic predicates use three of these lemmas.

CompPoly at `1a9ad0e` uses Lean v4.36.0 and the same Mathlib revision as
ArkLib, so only the CompPoly entries of `lakefile.toml` and
`lake-manifest.json` change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(Probability): compute exact worst-case probabilities of finite event families

`ArkLib/Data/Probability/MaxEventProbability.lean` defines
`Probability.maxEventProbability`, the exact worst-case probability of a
finite family of Boolean events, in `ℚ≥0`. It divides the largest event
count in the family by the size of the challenge space.
`ofReal_maxEventProbability_eq_iSup` proves that `ENNReal.ofReal` of its
real cast is the `ENNReal` supremum of the counting probabilities.
`ofReal_maxEventProbability_eq_iSup_of_iff` gives the same supremum for a
propositional event that the Boolean event decides. The exact
combiner-error evaluators in `AffineCombiner/Computable.lean` count with
`maxEventProbability`.

The acceptance tests evaluate `maxEventProbability` on a family with known
value `3/4`, on an empty family, and on an empty challenge space.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(AffineCombiner): compute the combiner errors as exact rationals

`AffineCombiner/Computable.lean` computes the affine, scalar, and
equal-degree combiner errors as exact values in `ℚ≥0`:

* `ReedSolomon.affineMcaErrorRat`
* `ReedSolomon.scalarMcaErrorRat`
* `ReedSolomon.equalDegreeMcaErrorRat`

Each evaluator enumerates the received word pairs and the challenges, and
counts with `Probability.maxEventProbability`. The evaluators search the
CompPoly candidates of bounded degree. For a fixed candidate, the
`Decidable` instances of `ReedSolomon.Computable.IsAffineExceptional`,
`IsScalarExceptional`, and `IsEqualDegreeExceptional` search the witnesses
of bounded degree. In the affine and scalar combiners, the candidate `P`
and the second witness `G₀` determine the first witness `F₀ = P - L G₀` for the
multiplier `L`, so these instances search `G₀` only. The `_iff` theorems identify the
three predicates with the semantic predicates. The theorems
`ofReal_affineMcaErrorRat`, `ofReal_scalarMcaErrorRat`, and
`ofReal_equalDegreeMcaErrorRat` prove that `ENNReal.ofReal` of the real
cast of each rational value is the semantic `ENNReal` error. The three
proofs share `Probability.ofReal_maxEventProbability_eq_iSup_of_iff`.

The module docstring states the cost of the search. Let `q` be the field
size, `n` the domain size, and `d` the output degree bound. The affine
and scalar evaluators examine up to `q^(2n+2d+3)` combinations of a word
pair, a challenge, a candidate, and a witness. The equal-degree evaluator
examines up to `q^(2n+3d+4)` combinations, because it searches both
witnesses. Charge one unit for each field operation, equality test,
natural-number operation, and evaluation of `domain`, as well as for each
other primitive step, such as an array access, a list-cell allocation, or
a closure call. Suppose the `Fintype` instances list the elements of `F`
and `ι` in `O(q)` and `O(n)` steps. In this model, the running time is at
most the number of combinations times a factor polynomial in `n` and `d`.
Each search builds its whole enumeration before the first test.

`Polynomial.degree_lt_succ_iff` in `ArkLib/ToMathlib/Polynomial/DegreeLT.lean`
states that a polynomial has degree below `n + 1` exactly when it has
degree at most `n`. The correctness proofs use it. It also replaces a
private copy in `AffineCombiner/Probability.lean` and an inline proof in
`ReedSolomon.lean`.

The acceptance tests evaluate all three errors over `ZMod 2` and
`ZMod 3`. For each combiner, the cases include degree zero, an empty
domain, a threshold above the domain size, and positive loss. The scalar
tests compare zero and one point of loss on the same two-point domain.
They also check a nonzero error with positive loss on the full ternary
domain. Other examples relate the rational values to uniform event
probabilities and `mcaError`, and assert the axioms of the three bridges.

The module docstrings of `AffineCombiner/Basic.lean` and
`AffineCombiner/EqualDegree.lean` refer to the evaluators. The docstrings
of `AffineCombiner/Basic.lean` also state the combined word at index `i`
as `f i + L(domain i) g i`. They cite Section 1.1 of [CWYZ26] for the
affine error. For the scalar error, they cite the definition of `ε_sc` at
the start of Section 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: describe the exact computable combiner errors

The CWYZ26 paper page lists `AffineCombiner/Computable.lean` among its
related modules and touchpoints. Its representation section names the
three evaluators and their bridge theorems.

The coding-theory and proximity-error conventions record `ℚ≥0` as the
type of an exact computable combiner error. The proximity-error
conventions also record how the scalar zero-loss value gives the
affine-line `mcaError`. The probability conventions explain how
`Probability.maxEventProbability` relates computable values to semantic
`ENNReal` probabilities. The repository map lists
`MaxEventProbability.lean` with the other finite-probability helpers.

The KB page and the proximity-error conventions refer to the module
docstring of `AffineCombiner/Computable.lean` for the cost of the search
and do not repeat it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant