Skip to content

feat(ComputablePolynomial): define SparsePoly, a computable univariate polynomial - #41339

Open
mkaratarakis wants to merge 4 commits into
leanprover-community:masterfrom
mkaratarakis:sparsepoly-1-basic
Open

mkaratarakis wants to merge 4 commits into
leanprover-community:masterfrom
mkaratarakis:sparsepoly-1-basic

Conversation

@mkaratarakis

@mkaratarakis mkaratarakis commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor

SparsePoly R is a computable, kernel-reducible representation of univariate polynomials over a commutative ring R with DecidableEq R: a list of (exponent, coefficient) pairs with strictly decreasing exponents and nonzero coefficients, making the representation canonical. This first part defines the structure, the semantics toPoly : SparsePoly R → Polynomial R, and addition.

Started by Mario Carneiro at the Hausdorff Institute (June 2024) with design notes and an original Lean prototype by James Davenport (https://github.com/JamesHDavenport/Dagstuhl23401, verify-irred/VerifyIrred) and the proofs were done with the help of Claude code.


@github-actions

github-actions Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

PR summary 21af48fbe7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Tactic 1
Mathlib.Tactic.ComputablePolynomial.Basic (new file) 1290

Declarations diff (regex)

+ C
+ SparsePoly
+ addCore
+ addCore_degLT
+ addCore_sorted
+ degGE
+ degGT
+ degLE
+ degLT
+ instance : Add (SparsePoly R)
+ instance : One (SparsePoly R)
+ instance : Zero (SparsePoly R)
+ instance [CommRing R] [Lean.ToFormat R] : Lean.ToFormat (SparsePoly R)
+ ofSortedList
+ ofSortedList_of_nonzero
+ toPoly
+ toPolyCore

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean -- stale, waiting for the new build)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit abf9c61).

  • +32 new declarations
  • −0 removed declarations
+SparsePoly
+SparsePoly.C
+SparsePoly.addCore
+SparsePoly.addCore.eq_def
+SparsePoly.addCore_degLt
+SparsePoly.addCore_sorted
+SparsePoly.casesOn
+SparsePoly.coeffs
+SparsePoly.ctorIdx
+SparsePoly.degLt
+SparsePoly.ext
+SparsePoly.ext_iff
+SparsePoly.instAdd
+SparsePoly.instOne
+SparsePoly.instToFormat
+SparsePoly.instZero
+SparsePoly.mk
+SparsePoly.mk.congr_simp
+SparsePoly.mk.inj
+SparsePoly.mk.injEq
+SparsePoly.mk.noConfusion
+SparsePoly.mk.sizeOf_spec
+SparsePoly.noConfusion
+SparsePoly.noConfusionType
+SparsePoly.nonzero
+SparsePoly.ofSortedList
+SparsePoly.ofSortedList_of_nonzero
+SparsePoly.rec
+SparsePoly.recOn
+SparsePoly.sorted
+SparsePoly.toPoly
+SparsePoly.toPolyCore

No changes to strong technical debt.

Increase in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5099 1 exposed public sections

Current commit 21af48fbe7
Reference commit 84ae864884

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions

github-actions Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

✅ PR Title Formatted Correctly

The title of this PR has been updated to match our commit style conventions.
Thank you!

@mkaratarakis mkaratarakis changed the title feat(Tactic/ComputablePolynomial): SparsePoly, a computable univariate polynomial feat(Tactic/ComputablePolynomial): define SparsePoly, a computable univariate polynomial Jul 4, 2026
@mathlib-triage mathlib-triage Bot assigned JovanGerb and unassigned thorimur Jul 27, 2026
@mkaratarakis mkaratarakis changed the title feat(Tactic/ComputablePolynomial): define SparsePoly, a computable univariate polynomial feat(ComputablePolynomial): define SparsePoly, a computable univariate polynomial Aug 4, 2026
@mathlib-triage mathlib-triage Bot assigned joneugster and unassigned kim-em Sep 17, 2026
@mathlib-triage mathlib-triage Bot assigned eric-wieser and unassigned joneugster Oct 3, 2026

@joneugster joneugster left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry this PR has been lying on the queue for quite a while!

Looks good to me, thanks! Only minor suggestions

@joneugster joneugster added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 16, 2026
@joneugster joneugster self-assigned this Oct 16, 2026
@[ext] structure SparsePoly (R : Type) [CommRing R] : Type where
/-- The underlying list of `(exponent, coefficient)` pairs, ordered by strictly decreasing
exponent with all coefficients nonzero. -/
coeffs : List (ℕ × R)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be more efficient to use a single inductive, Lean.AssocList, instead of combining List and Prod?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks! I kept List (ℕ × R) because of the List API e.g Pairwise, filter, which AssocList doesn't have, but I'm happy to switch. Batteries.AssocList might be another option via toList. Let me know if you'd prefer that

Comment thread Mathlib.lean

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems that there or some open questions about the right design of the entire stack of PRs and about how useful the resulting tactics will be.

Some of this was written on #41282, which contained the entire stack of PRs combined. Some was initially discussed in the reviewer stream linked above. I'll mark this

awaiting-zulip

for now. I think there needs to be some discussion about what tactics we get out of this and how useful they will be

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this discussion should be continued/restarted in a public topic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@joneugster joneugster added the awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there label Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants