Skip to content

Generalize CMvPolynomial coefficient universes#178

Merged
dhsorens merged 4 commits intodhsorens/bump_to_4.29.0-rc6from
quang/cmvpoly-type-universe
Mar 31, 2026
Merged

Generalize CMvPolynomial coefficient universes#178
dhsorens merged 4 commits intodhsorens/bump_to_4.29.0-rc6from
quang/cmvpoly-type-universe

Conversation

@quangvdao
Copy link
Copy Markdown
Collaborator

@quangvdao quangvdao commented Mar 30, 2026

Posted by Cursor assistant (model: GPT-5.4) on behalf of the user (Quang Dao) with approval.

Summary

  • generalize the multivariate coefficient parameter from Type to Type* across the CMvPolynomial stack
  • make the core multivariate aliases infer their result universe instead of forcing Type 0
  • replace the monomorphic ExtTreeMapLemmas dependency surface with local universe-polymorphic Std.ExtTreeMap helpers used by CompPoly

Validation

  • ./scripts/check-imports.sh
  • lake build
  • lake test
  • ./scripts/lint-style.sh

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 30, 2026

🤖 Gemini PR Summary

Universe Generalization

  • Generalize CMvPolynomial and CMvMonomial stacks from Type to Type* to support universe-polymorphic coefficients.
  • Convert the Unlawful polynomial type from a definition to an abbreviation.
  • Update Lawful polynomial definitions to be universe-polymorphic, enabling multivariate aliases to infer result universes instead of defaulting to Type 0.
  • No sorry or admit placeholders were introduced in this PR.

Typeclass and Elaboration Refinement

  • Mark AlgebraTower.toAlgebra and ConcreteBTFieldAlgebra as @[reducible] to improve transparency for the simplifier and typeclass resolution.
  • Set set_option backward.isDefEq.respectTransparency false in binary tower and equivalence modules to resolve unification issues introduced by complex universe levels.
  • Mark BTF₃ and specific bivariate polynomial mappings as noncomputable to align with theoretical definitions and avoid unnecessary code generation.
  • Update numerous proofs to use erw (extended rewrite) instead of rw to handle definitional equalities complicated by universe generalization.

Dependencies and API Alignment

  • Replace the monomorphic ExtTreeMapLemmas dependency surface with local universe-polymorphic Std.ExtTreeMap helpers within CompPoly.
  • Update lakefile.lean to bump mathlib and ExtTreeMapLemmas to v4.29.0-rc6.
  • Adjust proofs to maintain compatibility with Lean 4 core and Std naming changes, such as the renaming of Array.sum_eq_sum_toList to Array.sum_toList.

Statistics

Metric Count
📝 Files Changed 42
Lines Added 318
Lines Removed 298

Lean Declarations

✏️ **Removed:** 20 declaration(s)
  • def mkRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Ring (ConcreteBTField k) where in CompPoly/Fields/Binary/Tower/Concrete/Core.lean
  • def isScalarTower_succ_right (l r : ℕ) (h_le : l ≤ r) in CompPoly/Fields/Binary/Tower/Concrete/Basis.lean
  • def binaryTowerModule {l r : ℕ} (h_le : l ≤ r) : Module (BTField l) (BTField r) in CompPoly/Fields/Binary/Tower/Abstract/Algebra.lean
  • def BTField.isScalarTower_succ_right (l r : ℕ) (h_le : l ≤ r) in CompPoly/Fields/Binary/Tower/Abstract/Basis.lean
  • def degreeOf {R : Type} {n : ℕ} [Zero R] (i : Fin n) : CMvPolynomial n R → ℕ in CompPoly/Multivariate/CMvPolynomial.lean
  • def binaryAlgebraTower {l r : ℕ} (h_le : l ≤ r) : Algebra (BTField l) (BTField r) in CompPoly/Fields/Binary/Tower/Abstract/Algebra.lean
  • def mkAddCommGroupInstance {k : ℕ} : AddCommGroup (ConcreteBTField k) in CompPoly/Fields/Binary/Tower/Concrete/Core.lean
  • def liftConcreteBTField (k : ℕ) (prevBTFResult : ConcreteBTFStepResult (k in CompPoly/Fields/Binary/Tower/Concrete/Field.lean
  • def vars {n : ℕ} {R : Type} [Zero R] (p : CMvPolynomial n R) : Finset (Fin n) in CompPoly/Multivariate/CMvPolynomial.lean
  • def ofPoly {R : Type*} [BEq R] [LawfulBEq R] [Nontrivial R] [Semiring R] in CompPoly/Bivariate/ToPoly.lean
  • instance instFintype {k : ℕ} : Fintype (ConcreteBTField k) in CompPoly/Fields/Binary/Tower/Concrete/Field.lean
  • def mkDivisionRingInstance {k : ℕ} (props : ConcreteBTFieldProps k) : in CompPoly/Fields/Binary/Tower/Concrete/Core.lean
  • def AlgebraTowerEquiv.toAlgebraOverRight (e : AlgebraTowerEquiv A B) (i j : ι) in CompPoly/Data/RingTheory/AlgebraTower.lean
  • def ConcreteBTFieldAlgebra {l r : ℕ} (h_le : l ≤ r) : in CompPoly/Fields/Binary/Tower/Concrete/Algebra.lean
  • def binaryTowerModule {l r : ℕ} (h_le : l ≤ r) : in CompPoly/Fields/Binary/Tower/Concrete/Algebra.lean
  • def AlgebraTowerEquiv.toAlgebraOverLeft (e : AlgebraTowerEquiv A B) (i j : ι) in CompPoly/Data/RingTheory/AlgebraTower.lean
  • def NZConst {n : ℕ} {R : Type} [Zero R] (p : Lawful n R) : Prop in CompPoly/Multivariate/Lawful.lean
  • def getBTFResult (k : ℕ) : ConcreteBTFStepResult k in CompPoly/Fields/Binary/Tower/Concrete/Field.lean
  • def mkFieldInstance {k : ℕ} (props : ConcreteBTFieldProps k) : Field (ConcreteBTField k) where in CompPoly/Fields/Binary/Tower/Concrete/Core.lean
  • def degrees {n : ℕ} {R : Type} [Zero R] (p : CMvPolynomial n R) : Multiset (Fin n) in CompPoly/Multivariate/CMvPolynomial.lean
✏️ **Added:** 1 declaration(s)
  • def NzConst {n : ℕ} {R : Type*} [Zero R] (p : Lawful n R) : Prop in CompPoly/Multivariate/Lawful.lean
✏️ **Affected:** 50 declaration(s) (line number changed)
  • lemma totalDegree_equiv {S : Type*} {p : CMvPolynomial n R} [CommSemiring S] : in CompPoly/Multivariate/MvPolyEquiv/Eval.lean moved from L56 to L56
  • def leadingCoeff {n : ℕ} {R : Type*} [Zero R] [MonomialOrder n] in CompPoly/Multivariate/Operations.lean moved from L85 to L85
  • def bind₁ {n m : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L166 to L166
  • lemma sumToIter_eq {n : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L378 to L378
  • def aeval {n : ℕ} {R σ : Type*} [CommSemiring R] [CommSemiring σ] [Algebra R σ] in CompPoly/Multivariate/Operations.lean moved from L126 to L126
  • def coeff {R : Type*} {n : ℕ} [Zero R] (m : CMvMonomial n) (p : Unlawful n R) : R in CompPoly/Multivariate/Unlawful.lean moved from L221 to L223
  • lemma X_eq_monomial {k : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L222 to L222
  • def Lawful (n : ℕ) (R : Type*) [Zero R] : Type _ in CompPoly/Multivariate/Lawful.lean moved from L28 to L30
  • def sumToIter {n : ℕ} {R : Type*} [Zero R] [Add R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L216 to L216
  • def rename {n m : ℕ} {R : Type*} [Zero R] [Add R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L207 to L207
  • def restrictDegree {n : ℕ} {R : Type*} [BEq R] [LawfulBEq R] [Zero R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L211 to L211
  • lemma eval₂_equiv {S : Type*} {p : CMvPolynomial n R} [CommSemiring S] {f : (R →+* S)} in CompPoly/Multivariate/MvPolyEquiv/Eval.lean moved from L25 to L25
  • lemma filter_get {R : Type*} [BEq R] [LawfulBEq R] {v : R} {m : CMvMonomial n} (a : Unlawful n R) : in CompPoly/Multivariate/Unlawful.lean moved from L225 to L227
  • lemma foldl_add_comm' {β : Type*} [AddCommMonoid β] {k : ℕ} in CompPoly/Multivariate/Rename.lean moved from L48 to L48
  • abbrev Unlawful (n : ℕ) (R : Type*) : Type _ in CompPoly/Multivariate/Unlawful.lean moved from L34 to L34
  • lemma coeff_sumToIter {n : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L389 to L389
  • lemma not_mem_zero : x ∉ (0 : Unlawful n R) in CompPoly/Multivariate/Unlawful.lean moved from L148 to L150
  • def eval₂ {R S : Type*} {n : ℕ} [Semiring R] [CommSemiring S] : in CompPoly/Multivariate/CMvPolynomial.lean moved from L128 to L128
  • def coeff {R : Type*} {n : ℕ} [Zero R] (m : CMvMonomial n) (p : CMvPolynomial n R) : R in CompPoly/Multivariate/CMvPolynomial.lean moved from L59 to L59
  • lemma eval₂Hom_apply {S : Type*} [CommSemiring S] in CompPoly/Multivariate/MvPolyEquiv/Eval.lean moved from L98 to L98
  • def evalMonomial {R : Type*} {n : ℕ} [CommSemiring R] : (Fin n → R) → CMvMonomial n → R in CompPoly/Multivariate/CMvMonomial.lean moved from L198 to L198
  • def eval {R : Type*} {n : ℕ} [CommSemiring R] : (Fin n → R) → CMvPolynomial n R → R in CompPoly/Multivariate/CMvPolynomial.lean moved from L133 to L133
  • lemma foldl_eq_sum {β : Type*} [AddCommMonoid β] in CompPoly/Multivariate/MvPolyEquiv/Instances.lean moved from L190 to L190
  • lemma isNoZeroCoef_zero : isNoZeroCoef (n in CompPoly/Multivariate/Unlawful.lean moved from L151 to L153
  • abbrev MonoR (n : ℕ) (R : Type*) in CompPoly/Multivariate/CMvMonomial.lean moved from L167 to L167
  • lemma foldl_add_comm {β : Type*} [AddCommMonoid β] {k : ℕ} in CompPoly/Multivariate/Operations.lean moved from L359 to L359
  • def monomial {n : ℕ} {R : Type*} [BEq R] [LawfulBEq R] [Zero R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L157 to L157
  • lemma sumToIter_add {n : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L398 to L398
  • def totalDegree {R : Type*} {n : ℕ} [Zero R] : CMvPolynomial n R → ℕ in CompPoly/Multivariate/CMvPolynomial.lean moved from L142 to L142
  • lemma degreeOf_equiv {S : Type*} {p : CMvPolynomial n R} [CommSemiring S] : in CompPoly/Multivariate/MvPolyEquiv/Eval.lean moved from L60 to L60
  • lemma fromCMvPolynomial_monomial {k : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L244 to L244
  • def leadingMonomial {n : ℕ} {R : Type*} [Zero R] [MonomialOrder n] in CompPoly/Multivariate/Operations.lean moved from L58 to L58
  • theorem ENNReal.mul_inv_rev_ENNReal {a b : ℕ} (ha : a ≠ 0) : in CompPoly/Data/Nat/Bitwise.lean moved from L52 to L52
  • def X {n : ℕ} {R : Type*} [Zero R] [One R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L53 to L53
  • lemma toList_pairs_monomial_coeff {β : Type*} [AddCommMonoid β] in CompPoly/Multivariate/MvPolyEquiv/Instances.lean moved from L179 to L179
  • def eval₂Hom {S : Type*} [CommSemiring S] in CompPoly/Multivariate/MvPolyEquiv/Eval.lean moved from L89 to L89
  • def restrictTotalDegree {n : ℕ} {R : Type*} [BEq R] [LawfulBEq R] [Zero R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L203 to L203
  • lemma degreeOf_eq_count_degrees {n : ℕ} {R : Type*} [Zero R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L169 to L169
  • lemma fromCMvPolynomial_X {k : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L271 to L271
  • lemma add_getD? [AddZeroClass R] {m : CMvMonomial n} {p q : Unlawful n R} : in CompPoly/Multivariate/Unlawful.lean moved from L229 to L231
  • def restrictBy {n : ℕ} {R : Type*} [BEq R] [LawfulBEq R] [Zero R] in CompPoly/Multivariate/CMvPolynomial.lean moved from L194 to L194
  • lemma zero_eq_empty : (0 : Lawful n R) = ∅ in CompPoly/Multivariate/Lawful.lean moved from L114 to L116
  • lemma bind₁_eq_aeval {n m : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R] in CompPoly/Multivariate/Operations.lean moved from L173 to L173
  • def support {R : Type*} {n : ℕ} [Zero R] (p : CMvPolynomial n R) : Finset (Fin n →₀ ℕ) in CompPoly/Multivariate/CMvPolynomial.lean moved from L138 to L138
  • def leadingTerm {n : ℕ} {R : Type*} [Zero R] [BEq R] [LawfulBEq R] [MonomialOrder n] in CompPoly/Multivariate/Operations.lean moved from L75 to L75
  • lemma zero_eq_empty [BEq R] [LawfulBEq R] : (0 : Unlawful n R) = ∅ in CompPoly/Multivariate/Unlawful.lean moved from L138 to L138
  • def C {n : ℕ} {R : Type*} [BEq R] [LawfulBEq R] [Zero R] (c : R) : CMvPolynomial n R in CompPoly/Multivariate/CMvPolynomial.lean moved from L49 to L49
  • abbrev CMvPolynomial (n : ℕ) (R : Type*) [Zero R] : Type _ in CompPoly/Multivariate/CMvPolynomial.lean moved from L42 to L42
  • lemma list_foldl_add_comm {β K V : Type*} [AddCommMonoid β] in CompPoly/Multivariate/Rename.lean moved from L36 to L36
  • lemma list_foldl_add_comm {β K V : Type*} [AddCommMonoid β] in CompPoly/Multivariate/Operations.lean moved from L348 to L348

sorry Tracking

  • No sorrys were added, removed, or affected.

🎨 **Style Guide Adherence**

The following review is based on the provided style guide and the code changes in the diff.

There are 24 violations of the style guide. They are grouped by rule below:

  • Transparency and API Design (16 violations)

    • Rule: "Abbreviations (abbrev): Creates reducible definitions that are always unfolded. Use this for type synonyms or lightweight aliases where the underlying term should be exposed." (In Lean 4, abbrev is the standard for @[reducible] def).
    • Examples:
      • CompPoly/Data/RingTheory/AlgebraTower.lean:44: @[simp, reducible] def AlgebraTower.toAlgebra
      • CompPoly/Fields/Binary/Tower/Abstract/Algebra.lean:180: @[reducible] def binaryAlgebraTower
      • CompPoly/Fields/Binary/Tower/Concrete/Core.lean:1492: @[reducible] def mkRingInstance
      • (Also occurring in CompPoly/Fields/Binary/Tower/Concrete/Algebra.lean, CompPoly/Fields/Binary/Tower/Concrete/Basis.lean, CompPoly/Fields/Binary/Tower/Concrete/Field.lean, and tests/CompPolyTests/Univariate/Linear.lean).
  • Syntax and Formatting (3 violations)

    • Rule: "Operators: Put spaces on both sides of ... infix operators."
    • CompPoly/Multivariate/Unlawful.lean:172: Missing spaces around + and * in (t.1+k, t.2*v).
    • Rule: "Empty Lines: Avoid empty lines inside definitions or proofs."
    • CompPoly/Fields/Binary/Tower/Abstract/Basis.lean:225: Empty line between tactic blocks in multilinearBasis_apply.
  • Naming Conventions (3 violations)

    • Rule: "Theorems and Proofs: snake_case (e.g., add_comm, list_reverse_id)." (Implies lowercase start).
    • CompPoly/Fields/Binary/Tower/Abstract/Algebra.lean:133: BTField.RingHom_comp_cast (starts with uppercase).
    • Rule: "Acronyms: Treat as words (e.g., HtmlParser not HTMLParser)."
    • CompPoly/Data/Nat/Bitwise.lean:52: ENNReal in mul_inv_rev_ENNReal should be Ennreal.
    • Rule: "Prop-valued Classes: If the class is an adjective, use the Is prefix (e.g., IsCompact, IsPrime)."
    • CompPoly/Multivariate/Lawful.lean:171: NzConst (predicate/adjective) should be IsNzConst.
  • Variable Conventions (1 violation)

    • Rule: "m, n, k, ... : Natural numbers."
    • CompPoly/Data/Nat/Bitwise.lean:52: Uses a and b as binders for natural numbers instead of m, n, or k.
  • Theorem Naming Logic (1 violation)

    • Rule: "Hypotheses: Use _of_ to separate hypotheses, listed in the order they appear."
    • CompPoly/Data/Nat/Bitwise.lean:52: mul_inv_rev_ENNReal name does not reflect the hypothesis ha : a ≠ 0 (e.g., mul_inv_rev_of_ne_zero).

📄 **Per-File Summaries**
  • CompPoly/Multivariate/CMvMonomial.lean: This change generalizes the definitions of MonoR and evalMonomial by allowing the type R to reside in any universe level (changing Type to Type*). This adjustment improves the flexibility of the library by enabling these constructions to work with a broader range of types and rings.
  • CompPoly/Multivariate/CMvPolynomialEvalLemmas.lean: This change generalizes the universe level of the type R from Type to Type* in the variable declaration. This allows the lemmas in this section to be applied to commutative semirings in any universe.
  • CompPoly/Multivariate/FinSuccEquiv.lean: This change generalizes the universe of the commutative semiring $R$ from Type to Type*. This allows the subsequent definitions and theorems to be universe polymorphic rather than restricted to the default universe.
  • CompPoly/Multivariate/MvPolyEquiv/Eval.lean: This change generalizes the universe levels of types R and S by replacing Type with Type* in several lemmas and the eval₂Hom definition. These modifications improve the library's flexibility without introducing new theorems or definitions.
  • CompPoly/Multivariate/Operations.lean: Updates various definitions and lemmas to use universe-polymorphic types by changing Type to Type* for the base ring and related parameters. This refactoring ensures broader applicability of the multivariate polynomial operations without modifying the existing proofs or logic. No sorry or admit placeholders were introduced.
  • CompPoly/Multivariate/VarsDegrees.lean: This change generalizes the universe level of the type parameter R by replacing Type with Type*. This allows the lemmas in the file to apply to types in any universe.
  • CompPoly/Fields/Binary/AdditiveNTT/Impl.lean: This change modifies the Fintype instance for the BTF₃ binary tower field by marking it as noncomputable. It does not introduce new theorems or proofs, nor does it contain any sorry placeholders.
  • CompPoly/Data/Vector/Basic.lean: This change modifies the proof of the tail_cons theorem by updating a lemma name within a simp call to maintain compatibility with updated naming conventions in the underlying library. No new theorems or definitions are introduced, and the proof remains complete without sorry placeholders.
  • CompPoly/Data/Polynomial/Frobenius.lean: This change performs a minor maintenance update to the proof of degree_dvd_of_irreducible_dvd_X_pow_card_pow_sub_X by replacing a standard rewrite with an extended rewrite (erw) to handle definitional unification. No new definitions, theorems, or sorry placeholders are introduced.
  • CompPoly/Data/RingTheory/AlgebraTower.lean: This update adds the @[reducible] attribute to AlgebraTower.toAlgebra, AlgebraTowerEquiv.toAlgebraOverLeft, and AlgebraTowerEquiv.toAlgebraOverRight. These changes are intended to improve the transparency of these definitions for typeclass resolution and the simplifier when working with towers of algebras.
  • CompPoly/Fields/Binary/AdditiveNTT/Correctness.lean: This change refines the proof of the additiveNTT_correctness theorem by adjusting the rewriting strategy for the base_coeffsBySuffix lemma. It replaces a simp application with explicit erw steps to ensure correct simplification of the intermediate polynomial state without introducing any new definitions or sorry placeholders.
  • CompPoly/Fields/Binary/AdditiveNTT/Intermediate.lean: This change modifies existing proofs by replacing standard rewrites with extended rewrites (erw) in the lemmas getSDomainBasisCoeff_of_iteratedQuotientMap and base_intermediateNovelBasisX. These updates resolve definitional equality issues encountered during the rewriting process.
  • CompPoly/Fields/Binary/AdditiveNTT/NovelPolynomialBasis.lean: This update refines and stabilizes existing proofs related to polynomial degrees and coefficient vector spaces, notably improving the robustness of natural number casting in the proof of degree_Xⱼ. The changes modify several internal proof steps and remove a redundant instance without introducing new definitions or sorry placeholders.
  • CompPoly/Bivariate/ToPoly.lean: This change marks the ofPoly definition as noncomputable and updates several proofs to correctly handle the underlying subtype representations and definitional equalities of computable bivariate polynomials. The modifications involve replacing standard rewrites with erw and incorporating Subtype.ext to fix proofs for operations such as addition, multiplication, and zero-initialization. No new theorems or sorry placeholders are introduced.
  • CompPoly/Data/Nat/Bitwise.lean: This PR refactors and simplifies proofs involving ENat and ENNReal arithmetic. It significantly shortens the proof of ENNReal.mul_inv_rev_ENNReal by utilizing core library lemmas and updates a lemma reference in ENat.le_floor_NNReal_iff.
  • CompPoly/Fields/Binary/Common.lean: This change refactors the proof of the lemma toPoly_128_extend_256 to improve clarity and maintainability. The modification replaces a complex simp call with more explicit logical steps regarding BitVec bit properties, without introducing new theorems or sorry placeholders.
  • CompPoly/Fields/Binary/Tower/Abstract/Algebra.lean: This PR refines existing proofs for the binary field tower and marks binaryAlgebraTower and binaryTowerModule as reducible to improve typeclass inference. The changes include minor proof modifications using erw and congr to better handle casting and equality, with no new sorry or admit placeholders introduced.
  • CompPoly/Fields/Binary/BF128Ghash/Basic.lean: This change modifies the proof of the root_satisfies_poly theorem by replacing a single simp tactic with a more explicit sequence using erw. This adjustment ensures the evaluation of polynomial powers is correctly handled during the rewrite process without introducing new definitions or sorry placeholders.
  • CompPoly/Fields/Binary/Tower/Concrete/Algebra.lean: This change optimizes typeclass resolution and unification for the binary field tower by marking ConcreteBTFieldAlgebra and binaryTowerModule as @[reducible]. It also modifies a global transparency setting for definitional equality to improve how these algebra and module instances are processed.
  • CompPoly/Fields/Binary/Tower/Concrete/Basis.lean: This change optimizes and stabilizes basis-related proofs for the concrete binary tower by adjusting transparency settings and marking isScalarTower_succ_right as reducible. It refactors the proofs of PowerBasis.cast_basis_succ_of_eq_rec_apply and multilinearBasis_apply to be more concise, utilizing convert and erw to better handle definitional equalities.
  • CompPoly/Fields/Binary/Tower/Abstract/Split.lean: This PR refines the proofs for unique linear decomposition and algebraic embeddings in binary field towers to be more robust. The changes focus on explicitly handling the relationship between AdjoinRoot operations and the tower's scalar multiplication, particularly when resolving eqRec and cast issues across field extensions.
  • CompPoly/Fields/Binary/Tower/Concrete/Field.lean: This PR adjusts transparency and computability attributes for the binary tower's field constructions, marking several instances and definitions as noncomputable and @[reducible]. It also modifies a global configuration option to relax definitional equality checks, ensuring smoother elaboration of the concrete field tower's structural properties.
  • CompPoly/Fields/Binary/Tower/Abstract/Basis.lean: This change refines existing proofs concerning the basis and scalar tower structure of binary fields, specifically adjusting transparency settings and using erw to resolve definitional equality issues in algebraMap instances. The primary modification involves updating the proof of multilinearBasis_apply to be more robust, along with marking isScalarTower_succ_right as reducible. No sorry or admit placeholders were introduced.
  • CompPoly/Fields/Binary/Tower/Concrete/Core.lean: This update refactors several proofs for conciseness and robustness, notably simplifying the logic for addition and multiplication lemmas using more efficient tactic sequences. It also marks field instance constructors as @[reducible] to improve typeclass resolution and transparency. No sorry or admit placeholders were introduced.
  • CompPoly/Fields/Binary/Tower/Equiv.lean: This change modifies the file's elaboration settings by disabling transparency checks during definitional equality testing (backward.isDefEq.respectTransparency). This adjustment is intended to facilitate unification and proof processing for the equivalences between abstract and concrete binary tower constructions, without introducing new definitions or theorems.
  • CompPoly/Fields/Binary/Tower/Support/Preliminaries.lean: This change adjusts the elaboration settings for two theorems concerning linear forms in adjoined commutative rings by disabling strict transparency for definitional equality checks. No new theorems or definitions are introduced, and the file contains no sorry or admit placeholders.
  • CompPoly/Multilinear/Basic.lean: This change refactors the proofs of mobius_apply_zeta_apply_eq_id and zeta_apply_mobius_apply_eq_id by removing redundant lemmas from simp calls. It streamlines existing proof scripts without modifying the library's definitions or introducing any sorry placeholders.
  • CompPoly/Multivariate/CMvPolynomial.lean: This update generalizes universe levels from Type to Type* across various polynomial definitions and lemmas to improve flexibility. Additionally, it marks the degreeOf, degrees, and vars definitions as noncomputable.
  • CompPoly/Multilinear/Equiv.lean: This change refactors the proofs of map_add' and map_smul' within the linearEquivMvPolynomialDeg1 definition to be more concise. It streamlines the proof scripts by replacing several simp and conv blocks with more direct applications of erw for coefficient and vector operations.
  • CompPoly/Multivariate/Lawful.lean: This update generalizes the Lawful polynomial definition and its associated functions to be universe-polymorphic and renames the NZConst predicate to NzConst. It also modifies existing proofs and local attributes to improve tactic performance and type class resolution, without introducing any sorry placeholders.
  • CompPoly/Multivariate/Rename.lean: This PR generalizes the universe levels of types in several lemmas and declarations by replacing Type with Type*. Additionally, it modifies the proof of toFinsupp_zero by adding an explicit step using Vector.getElem_zero.
  • CompPoly/ToMathlib/MvPolynomial/Equiv.lean: This change adjusts the elaboration behavior for the support_finSuccEquivNth theorem by disabling strict transparency checks for definitional equality. This modification is likely intended to resolve unification issues or performance regressions encountered during the proof's processing.
  • CompPoly/Multivariate/MvPolyEquiv/Instances.lean: This PR generalizes universe levels for type variables from Type to Type* and updates several proofs to improve robustness. Notably, the proof of map_mul was modified to handle potential beta-reduction changes in newer Lean versions, replacing some rw calls with erw and change. No new theorems, definitions, or sorry placeholders were introduced.
  • CompPoly/Multivariate/MvPolyEquiv/Core.lean: This change generalizes the universe level for the ring type $R$ and refines the proofs of the equivalence theorems between MvPolynomial and CMvPolynomial. The updates improve the logic for mapping between representations by using more direct ExtTreeMap lemmas in toCMvPolynomial_fromCMvPolynomial and fromCMvPolynomial_toCMvPolynomial. No new definitions or sorry placeholders are introduced.
  • CompPoly/Multivariate/Restrict.lean: This update generalizes ring types to be universe polymorphic and adjusts a lemma reference in a proof to maintain compatibility with library changes. The changes modify existing proofs without introducing new definitions, theorems, or sorry placeholders.
  • lakefile.lean: This change updates the project's dependencies, bumping the versions of mathlib and ExtTreeMapLemmas to align with the v4.29.0-rc6 release.
  • CompPoly/Univariate/Raw/Proofs.lean: This change updates the proof of the lemma equiv_mul_one by replacing a reference to Array.sum_eq_sum_toList with Array.sum_toList. This modification ensures compatibility with current library naming conventions without introducing any new definitions or sorry placeholders.
  • CompPoly/Multivariate/Unlawful.lean: This PR refactors the Unlawful polynomial type by changing it from a def to an abbrev and generalizing its universe levels. It relaxes the typeclass requirements for the add_getD? lemma and updates attributes and imports to improve compatibility with the grind tactic. No sorry or admit placeholders were introduced.
  • CompPoly/Univariate/Quotient/Core.lean: This refactors several proofs to use apply Quotient.sound instead of rewriting with Quotient.eq, streamlining the verification that various polynomial operations (such as addition, multiplication, and power) descend correctly to the quotient. The changes simplify existing proofs and remove redundant tactic steps without introducing new definitions or sorry placeholders.
  • tests/CompPolyTests/Univariate/Linear.lean: This update marks local BEq instances as reducible and refines their corresponding LawfulBEq proofs to ensure definitions unfold correctly during tactic application. The changes modify existing proof scripts to use erw for explicit unfolding, and no sorry placeholders are introduced.

Last updated: 2026-03-31 19:17 UTC.

@quangvdao quangvdao requested a review from dhsorens March 30, 2026 15:07
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 30, 2026

Build Timing Report

  • Commit: c192eb7
  • Message: Merge 7f3ab20 into fe33688
  • Ref: quang/cmvpoly-type-universe
  • Comparison baseline: 5f1f193 from the previous successful PR update.
  • Measured on ubuntu-latest with /usr/bin/time -p.
  • Commands: clean build rm -rf .lake/build && lake build; warm rebuild lake build; test path lake test.
Measurement Baseline (s) Current (s) Delta (s) Status
Clean build 257.65 239.72 -17.93 ok
Warm rebuild 1.67 1.69 +0.02 ok
Test path 19.09 16.00 -3.09 ok

Incremental Rebuild Signal

  • Warm rebuild saved 238.03s vs clean (141.85x faster).

This compares a clean project build against an incremental rebuild in the same CI job; it is a lightweight variability signal, not a full cross-run benchmark.

Slowest Current Clean-Build Files

Showing 20 slowest current targets, with comparison against the selected baseline when available.

Current (s) Baseline (s) Delta (s) Path
61.00 53.00 +8.00 CompPoly/Fields/Binary/Tower/Abstract/Basis.lean
54.00 84.00 -30.00 CompPoly/Fields/Binary/BF128Ghash/XPowTwoPowModCertificate.lean
49.00 48.00 +1.00 CompPoly/Bivariate/ToPoly.lean
29.00 29.00 +0.00 CompPoly/Fields/Binary/BF128Ghash/Impl.lean
28.00 28.00 +0.00 CompPoly/Univariate/Raw/Proofs.lean
24.00 23.00 +1.00 CompPoly/Univariate/Lagrange.lean
22.00 21.00 +1.00 CompPoly/Fields/Binary/Tower/Support/Preliminaries.lean
21.00 24.00 -3.00 CompPoly/Fields/Binary/AdditiveNTT/NovelPolynomialBasis.lean
20.00 13.00 +7.00 CompPoly/Univariate/Quotient/Core.lean
17.00 16.00 +1.00 CompPoly/Fields/Binary/AdditiveNTT/Domain.lean
14.00 18.00 -4.00 CompPoly/Fields/Binary/AdditiveNTT/Intermediate.lean
13.00 16.00 -3.00 CompPoly/Univariate/Basic.lean
13.00 10.00 +3.00 CompPoly/Fields/Binary/BF128Ghash/XPowTwoPowGcdCertificate.lean
12.00 19.00 -7.00 CompPoly/Fields/Binary/AdditiveNTT/Correctness.lean
12.00 10.00 +2.00 CompPoly/Fields/Binary/Tower/Abstract/Split.lean
11.00 12.00 -1.00 CompPoly/Fields/KoalaBear.lean
11.00 15.00 -4.00 CompPoly/Fields/Binary/Tower/Abstract/Core.lean
9.70 7.70 +2.00 CompPoly/Multilinear/Equiv.lean
9.40 7.80 +1.60 CompPoly/Fields/Binary/BF128Ghash/Prelude.lean
9.30 12.00 -2.70 CompPoly/Multivariate/Unlawful.lean

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 30, 2026

🤖 Initial AI review without external context

🤖 AI Review

Overall Summary:

TL;DR

This PR is in excellent shape, successfully applying standard Mathlib best practices across the board by generalizing universe levels (from Type to Type*), minimizing typeclass assumptions (e.g., [CommSemiring R] to [AddZeroClass R]), and streamlining definitions (such as changing Unlawful from a def to an abbrev). The mathematical formalization is entirely sound, with only a single minor nitpick regarding an unused variable.

Checklist Coverage

No explicit specification checklist was provided for this review.

Key Lean 4 / Mathlib Issues

None found. The refactoring perfectly aligns with Lean 4 and Mathlib conventions for universe polymorphism and minimal typeclasses.

Nitpicks & Minor Observations

  • Unused Variables (CompPoly/Multivariate/MvPolyEquiv/Eval.lean): In totalDegree_equiv and degreeOf_equiv, the type variable S and its [CommSemiring S] instance are completely unused in the theorem statements. While your work generalizing them to Type* was the correct move for universe polymorphism, these variables are likely copy-paste leftovers from eval₂_equiv and can be safely removed entirely to clean up the theorem signatures.

Overall Verdict

Approved

(Fantastic work on the cleanup—the typeclass minimization and universe polymorphism refactors are exactly what we look for in Lean 4 library development!)


📄 **Review for `CompPoly/Multivariate/CMvMonomial.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/CMvPolynomial.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

(The change from Type to Type* correctly makes the definitions and theorems universe-polymorphic, adhering to Mathlib best practices and allowing the library to be used with rings in arbitrary universes. The use of Type _ for the return type of CMvPolynomial properly infers the resulting universe level based on R.)

📄 **Review for `CompPoly/Multivariate/CMvPolynomialEvalLemmas.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/FinSuccEquiv.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/Lawful.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/MvPolyEquiv/Core.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/MvPolyEquiv/Eval.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:

  • In totalDegree_equiv and degreeOf_equiv, the type variable S and its [CommSemiring S] instance are completely unused in the theorem statements and could be safely removed (they were likely left over from a copy-paste of eval₂_equiv). However, generalizing them to Type* as done in this PR is the correct fix for universe polymorphism regardless.
📄 **Review for `CompPoly/Multivariate/MvPolyEquiv/Instances.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

(Note: Generalizing the universe levels by replacing Type with Type* for the ring R and the target space β is a great change. It properly aligns the file with Mathlib's universe polymorphism standards and matches the base definition of CMvPolynomial, which already took R : Type*.)

📄 **Review for `CompPoly/Multivariate/Operations.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

(The changes correctly generalize the universe levels of R, σ, β, K, V, and R' from Type 0 to Type u by replacing Type with Type*. This aligns the file with Mathlib's universe polymorphism best practices and properly matches the Type* definitions from CompPoly/Multivariate/CMvPolynomial.lean and CompPoly/Multivariate/Lawful.lean.)

📄 **Review for `CompPoly/Multivariate/Rename.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/Restrict.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `CompPoly/Multivariate/Unlawful.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

(Additional Context):
This PR contains excellent improvements. The shift from Type to Type* correctly ensures universe polymorphism. The change from [CommSemiring R] to [AddZeroClass R] for add_getD? elegantly minimalizes the required typeclasses, directly adhering to standard Mathlib best practices. The conversion of Unlawful from a def to an abbrev makes complete sense here, avoiding unnecessary definition unfolding hurdles down the line. Formatting and spacing touch-ups are also appreciated. Great work!

📄 **Review for `CompPoly/Multivariate/VarsDegrees.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

📄 **Review for `lakefile.lean`**

Verdict: Approved

Critical Misformalizations:
None

Lean 4 / Mathlib Issues:
None

Nitpicks:
None

Copy link
Copy Markdown
Collaborator

@dhsorens dhsorens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as this doesn't negatively affect performance, I'm happy with this but it might be nice to get a review/approval from @Julek just in case. @quangvdao do you have a specific use case in mind for making CMvPolynomial polymorphic over universes?

@quangvdao
Copy link
Copy Markdown
Collaborator Author

None right now, though this brings the multivariate case on par with univariate case that is already universe polymorphic. And I don't think we have any perf regression

Copy link
Copy Markdown
Collaborator

@dhsorens dhsorens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see some minor comments but otherwise I'm happy with this!

Comment on lines +1 to +10
/-
Copyright (c) 2026 CompPoly. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Quang Dao
-/
import CompPoly.Multivariate.FinSuccEquiv
import CompPoly.Multivariate.Operations
import CompPoly.Univariate.ToPoly.Impl

/-!
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a duplicate of the file already merged in? possibly this branch needs rebasing?

Comment on lines +107 to +105
λ (m, c) => repr c ++ " * " ++ repr m⟩
fun (m, c) repr c ++ " * " ++ repr m⟩
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a kind of funny change - should we choose either \lambda and \mapsto together, or fun and => together?

lemma filter_get {R : Type} [BEq R] [LawfulBEq R] {v : R} {m : CMvMonomial n} (a : Unlawful n R) :
(ExtTreeMap.filter (fun _ c => c != v) a)[m]?.getD v = a[m]?.getD v := by
lemma filter_get {R : Type*} [BEq R] [LawfulBEq R] {v : R} {m : CMvMonomial n} (a : Unlawful n R) :
(ExtTreeMap.filter (fun _ c c != v) a)[m]?.getD v = a[m]?.getD v := by
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this spirit, if we're changing => to \mapsto, shall we also change fun to \lambda?

Comment on lines +39 to +41
- Working on the dedicated one-variable
`CMvPolynomial 1 R ≃+* CPolynomial R` bridge:
start in `CompPoly/Multivariate/UnivariateEquiv.lean`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another instance of probably needing to rebase

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are more in the other wiki docs but I won't comment them all

lakefile.lean Outdated
require "leanprover-community" / mathlib @ git "v4.28.0"

require ExtTreeMapLemmas from git "https://github.com/Verified-zkEVM/ExtTreeMapLemmas"@"v4.28.0-patch-1"
require ExtTreeMapLemmas from git "https://github.com/quangvdao/ExtTreeMapLemmas"@"ed753cfcaa1ad3699e204899a0136ffa2383526c"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re this dependency change - I just merged your PR in ExtTreeMapLemmas and issued a new tag, v4.29.0-rc6-patch-1 - can we please us that here? hopefully 4.29.0-rc6 works as a dependency

on a separate note it might be nice to consider just putting ExtTreeMapLemmas into CompPoly since it's small and a sort of annoying dependency

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fully support moving that into CompPoly. Can be an internal detail of CMvPolynomial

@quangvdao quangvdao force-pushed the quang/cmvpoly-type-universe branch from 2d5d34c to 5f1f193 Compare March 31, 2026 19:06
@quangvdao quangvdao force-pushed the quang/cmvpoly-type-universe branch from 5f1f193 to 7f3ab20 Compare March 31, 2026 19:15
@quangvdao quangvdao changed the base branch from master to dhsorens/bump_to_4.29.0-rc6 March 31, 2026 19:15
Copy link
Copy Markdown
Collaborator Author

Posted by Cursor assistant (model: GPT-5) on behalf of the user (Quang Dao) with approval.

Thanks for the review. I addressed the minor comments and cleaned up the branch shape:

  • removed the accidental univariate/doc overlap from this PR, so the duplicate-file/wiki comments should now be outdated
  • cleaned the small style nits in CompPoly/Multivariate/Unlawful.lean and CompPoly/Multivariate/MvPolyEquiv/Core.lean
  • restacked this PR onto dhsorens/bump_to_4.29.0-rc6
  • switched ExtTreeMapLemmas over to the upstream Verified-zkEVM/ExtTreeMapLemmas@v4.29.0-rc6-patch-1

While restacking onto the 4.29 branch, a few small proof adjustments were needed for Lean 4.29 in:

  • CompPoly/Multivariate/Unlawful.lean
  • CompPoly/Multivariate/Lawful.lean
  • CompPoly/Multivariate/MvPolyEquiv/Core.lean

Revalidated with:

  • lake update ExtTreeMapLemmas
  • lake build
  • lake test
  • ./scripts/lint-style.sh

So at this point the PR is aligned with the 4.29 base and the upstream dependency tag.

Copy link
Copy Markdown
Collaborator

@dhsorens dhsorens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thanks! happy with this

@dhsorens dhsorens merged commit ba504dc into dhsorens/bump_to_4.29.0-rc6 Mar 31, 2026
4 of 5 checks passed
@dhsorens dhsorens deleted the quang/cmvpoly-type-universe branch March 31, 2026 19:44
@dhsorens dhsorens restored the quang/cmvpoly-type-universe branch March 31, 2026 19:45
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.

2 participants