refactor: make the CPolynomial namespace open-friendly - #279
refactor: make the CPolynomial namespace open-friendly#279mitschabaude-bot wants to merge 3 commits into
Conversation
These lemmas exist to discharge the `Semiring`/`CommRing`/`Module` instance fields; downstream code reaches them through the algebraic hierarchy. Leaving them unprotected means `open CompPoly.CPolynomial` rebinds `mul_comm`, `add_zero`, `one_mul` and 16 more, so every unrelated ring step in the opening file has to be written `_root_.mul_comm`. Mathlib's `Polynomial` is open-friendly because it never restates its ring axioms. This makes `CPolynomial` behave the same way. The lemmas stay available as `CPolynomial.mul_comm` and instance resolution is unaffected.
🤖 PR Summary
Refactoring
Statistics
Lean Declarations ✏️ Affected: 18 declaration(s) (line number changed)
📋 **Additional Analysis**Differences from the contribution guidelines. See table below. 📄 **Per-File Summaries**
Last updated: 2026-07-30 13:48 UTC. |
|
for context, this was motivated by zcash/ironwood#146, which made @dhsorens can you review or suggest a reviewer? |
|
thanks @mitschabaude - I will review this asap! |
dhsorens
left a comment
There was a problem hiding this comment.
@mitschabaude you're right, this is a good idea. merging
|
@mitschabaude would you mind fixing the linting errors? I'll merge this when it passes (I would do it myself but I can't push to your fork) |
Adding `protected ` took seven headers past the style limit; each is wrapped after its instance binders, matching the file's own style.
|
Caution This summary did not complete normally. One or more AI calls failed for a spend, quota, or authentication reason, or the per-run budget was exhausted. The summary below is PARTIAL — see the Actions log for details. 🤖 PR SummaryFailed to generate AI summary. Please check the per-file summaries and statistics below. Statistics
Lean Declarations ✏️ Affected: 18 declaration(s) (line number changed)
📄 **Per-File Summaries**
Last updated: 2026-08-04 14:35 UTC. |
|
@dhsorens fixed up the warnings! |
Marks the ring- and module-axiom lemmas in
CPolynomialasprotected, so thatopen CompPoly.CPolynomialno longer shadows the root-level lemmas of the same name.Why
These lemmas exist to discharge the
Semiring/CommRing/Moduleinstance fields. Once the instances are built, downstream code reaches them through the algebraic hierarchy — nobody should be citingCPolynomial.mul_commby name. But because they are unprotected,open CompPoly.CPolynomialrebindsmul_comm,add_zero,one_mul,smul_addand 15 more to theCPolynomial-specific versions, and every unrelatedring-style step in the opening file has to be written_root_.mul_comm.Mathlib's
Polynomialis open-friendly for exactly this reason: it never restates its ring axioms, soopen Polynomialcosts nothing.For scale, a downstream development that moved its polynomial layer from
PolynomialtoCPolynomialaccumulated 75_root_.qualifications purely from this, dominated bymul_comm(32),add_zero(19),mul_assoc(16),one_mul(13) andmul_one(12). All of them disappear with this change.What changed
protectedon 19 declarations inUnivariate/Basic.lean:These are precisely the members of
CompPoly.CPolynomialthat collide with an existing root-level name; I enumerated them from the environment rather than by eye.protectedrequires qualification inside the declaring namespace too, so six internal call sites are now writtenCPolynomial.add_command the like. All six are inBasic.leanand all but two are instance fields consuming the lemma they are named after —AddCommSemigroup.add_assoc/add_comm,CommSemiring.mul_comm, and the fiveModulefields. The other two arerw [add_comm]steps insideX_mul_divX_addandinduction_on.Those two are worth a note: they did not fail with an unknown identifier but with an ambiguity between
_root_.add_commandRaw.add_comm.CPolynomial.Rawis a sub-namespace, so its own unprotected copy of the axiom was previously masked by the outer one; removing the outer one exposes it.Nothing about instance resolution changes, and every lemma remains accessible as
CPolynomial.foo.Verified with a full
lake buildof the package: 2605 jobs, no errors.Basic.leanis the only file that needed touching.Not included
CPolynomial.RawandQuotientCPolynomialcarry the same axiom lemmas and have the same issue — the ambiguity above is a symptom. They are sub-namespaces that are rarely opened, so I left them alone; happy to extend this if you'd like.