Skip to content

[Merged by Bors] - feat(Data/List/SignVariations): add List.signVariations - #43783

Closed
tomaz1502 wants to merge 6 commits into
leanprover-community:masterfrom
tomaz1502:add_signVariations
Closed

tomaz1502 wants to merge 6 commits into
leanprover-community:masterfrom
tomaz1502:add_signVariations

Conversation

@tomaz1502

@tomaz1502 tomaz1502 commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds List.signVariations, which counts the number of variations in a list, ignoring all zeroes, as well as its basic API. This counting is the mechanism of both Descartes' Rule of Signs and of Sturm-Tarski theorem, which will be added in upcoming PRs.

This PR also adapts RuleOfSigns.lean to use the new API, simplifying some of its proofs.

The contents of this PR were manually written. Claude Code (Fable 5.1) was used to review the code.

@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Sep 13, 2026
@github-actions

Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to Zulip and join the Lean community.
Thank you again for joining our community.

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

PR summary 1769435c55

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Algebra.Polynomial.RuleOfSigns 1
Mathlib.Data.List.SignVariations (new file) 800

Declarations diff (regex)

+ signVariations_congr
+ signVariations_cons_cons_of_ne_zero
+ signVariations_cons_replicate_zero
+ signVariations_cons_replicate_zero_append
+ signVariations_cons_zero_cons
+ signVariations_filter_ne_zero
+ signVariations_map
+ signVariations_map_of_sign_eq_neg
+ signVariations_map_sign
+ signVariations_nil
+ signVariations_singleton
+ signVariations_zero_cons
++- signVariations

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)

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

  • +13 new declarations
  • −0 removed declarations
+List.signVariations
+List.signVariations_congr
+List.signVariations_cons_cons_of_ne_zero
+List.signVariations_cons_replicate_zero
+List.signVariations_cons_replicate_zero_append
+List.signVariations_cons_zero_cons
+List.signVariations_filter_ne_zero
+List.signVariations_map
+List.signVariations_map_of_sign_eq_neg
+List.signVariations_map_sign
+List.signVariations_nil
+List.signVariations_singleton
+List.signVariations_zero_cons

No changes to strong technical debt.

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

Current commit 1769435c55
Reference commit 64401b008c

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 Sep 13, 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!

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Sep 13, 2026
@tomaz1502 tomaz1502 changed the title feat(Data/List/SignVariations.lean): Add List.signVariations feat(Data/List/SignVariations): add List.signVariations Sep 13, 2026
@kim-em

kim-em commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

I'm posting some review comments, identified with the assistance of Claude and Codex. I'm not putting separate ":robot:" attributions on each comment.

@kim-em kim-em left a comment

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.

  • The docstring of signVariations_X_sub_C_mul_eraseLead_le (L242, untouched by this PR) says the two counts are "the same", but the lemma only proves ≤, and equality is false: P = X^2 + X + 10, η = 2 gives 3 vs 1. Worth fixing while you're here.
  • PR description: "This counting mechanism of both ..." is missing a verb ("This is the counting mechanism behind both ...").

Comment thread Mathlib/Data/List/SignVariations.lean Resolved
Comment thread Mathlib/Data/List/SignVariations.lean Resolved
Comment thread Mathlib/Data/List/SignVariations.lean Resolved
Comment thread Mathlib/Data/List/SignVariations.lean Resolved
Comment thread Mathlib/Data/List/SignVariations.lean Resolved
Comment thread Mathlib/Data/List/SignVariations.lean Resolved
@kim-em

kim-em commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

bors merge

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 14, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 15, 2026
This PR adds `List.signVariations`, which counts the number of variations in a list, ignoring all zeroes, as well as its basic API. This counting is the mechanism of both [Descartes' Rule of Signs](https://github.com/leanprover-community/mathlib4/blob/master/Mathlib/Algebra/Polynomial/RuleOfSigns.lean) and of Sturm-Tarski theorem, which will be added in upcoming PRs.

This PR also adapts `RuleOfSigns.lean` to use the new API, simplifying some of its proofs.

The contents of this PR were manually written. Claude Code (Fable 5.1) was used to review the code.
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 15, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title feat(Data/List/SignVariations): add List.signVariations [Merged by Bors] - feat(Data/List/SignVariations): add List.signVariations Sep 15, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 15, 2026
rosborn added a commit to rosborn/mathlib4 that referenced this pull request Sep 15, 2026
* origin/master: (958 commits)
  chore(Combinatorics/SimpleGraph/Trails): golf and cleanup (leanprover-community#41447)
  refactor(Probability/Kernel): remove redundant case split in Invariant.comp (leanprover-community#43805)
  chore: bump toolchain to v4.34.0 (leanprover-community#43798)
  feat(Data/List/SignVariations): add List.signVariations (leanprover-community#43783)
  feat(LinearAlgebra/Span/Basic): add Submodule.prodEquiv (leanprover-community#43664)
  feat(cache): put with native Azure and S3 backends (leanprover-community#43378)
  feat(Combinatorics/SimpleGraph/Walk): more `transfer` API (leanprover-community#41717)
  feat(SimpleGraph): girth-diameter inequality (leanprover-community#25834)
  feat: make `simps?` and `to_dual?`/`to_additive?` more concise (leanprover-community#43775)
  feat(Basic/IsEmpty/Defs): add Fin.isEmpty_iff (leanprover-community#43763)
  feat(Data/ENNReal/Inv): add ENNReal.div_mul_div_cancel (leanprover-community#37954)
  chore(Tactic/Simproc/ExistsAndEq): fix two typos (leanprover-community#43797)
  feat(LinearAlgebra/Matrix/GeneralLinearGroup/Defs): add the proof of the range of toGL to be the ker of the determinant and the induced equivalence (leanprover-community#41786)
  chore(Data/Num/Lemmas): golf `transfer` tactic (leanprover-community#41167)
  refactor(Data/Nat/Choose/Central): move and rename `four_pow_le_two_mul_add_one_mul_central_binom` (leanprover-community#42606)
  feat(Combinatorics/Graph): edge cut of `Graph` (leanprover-community#37865)
  feat(Algebra/QuadraticAlgebra): classify quadratic algebras by their discriminant (leanprover-community#42708)
  fix: use the PR number in the deprecation reminder message (leanprover-community#43786)
  feat(Data/Fintype/Defs): add DecidableLE (∀ a, β a) (leanprover-community#43425)
  chore: redefine `Finsupp.indicator` using `Finsupp.onFinset` (leanprover-community#33434)
  ...

# Conflicts:
#	Mathlib/Tactic/Linter/DirectoryDependency.lean
mathlib-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
This PR defines `Polynomial.sturmSeq p q`, the Sturm sequence (signed remainder sequence) of two
polynomials over a field: the list `[p, q, -(p % q), …]` of successive negated remainders, ending at
the last nonzero one. It also proves its basic API:

* `sturmSeq_cons`, `sturmSeq_zero`, `sturmSeq_zero_right`, `sturmSeq_eq_nil_iff`: unfolding and
  degenerate cases;
* `mem_sturmSeq_self`, `head?_sturmSeq`, `zero_notMem_sturmSeq`: membership facts;
* `dvd_of_mem_sturmSeq`: every common divisor of `p` and `q` divides every entry;
* `sturmSeq_mul_left`: `sturmSeq (r * p) (r * q) = (sturmSeq p q).map (r * ·)` for `r ≠ 0`.

It also adds `Polynomial.neg_mod` and `Polynomial.mul_mod_mul_left` to `FieldDivision.lean`, used
in the proof of `sturmSeq_mul_left`.

This is the second PR of a series formalizing the Sturm–Tarski theorem, following #43783 
(`List.signVariations`). The development is a port of Wenda Li's Isabelle/AFP entry. The remaining
parts (local sign of a polynomial to the right of a point, the Cauchy index, and the theorem
itself) will follow in separate PRs. See also #43512.

The definition and the original proofs were written by hand. Claude Code (Fable 5.1) was used to
simplify part of the proofs and to review the code.

Co-authored-by: Pedro Saccomani <[email protected]>
Co-authored-by: Sarah Azevedo Pereira <[email protected]>
grunweg pushed a commit to grunweg/mathlib4 that referenced this pull request Sep 22, 2026
…#43954)

This PR defines `Polynomial.sturmSeq p q`, the Sturm sequence (signed remainder sequence) of two
polynomials over a field: the list `[p, q, -(p % q), …]` of successive negated remainders, ending at
the last nonzero one. It also proves its basic API:

* `sturmSeq_cons`, `sturmSeq_zero`, `sturmSeq_zero_right`, `sturmSeq_eq_nil_iff`: unfolding and
  degenerate cases;
* `mem_sturmSeq_self`, `head?_sturmSeq`, `zero_notMem_sturmSeq`: membership facts;
* `dvd_of_mem_sturmSeq`: every common divisor of `p` and `q` divides every entry;
* `sturmSeq_mul_left`: `sturmSeq (r * p) (r * q) = (sturmSeq p q).map (r * ·)` for `r ≠ 0`.

It also adds `Polynomial.neg_mod` and `Polynomial.mul_mod_mul_left` to `FieldDivision.lean`, used
in the proof of `sturmSeq_mul_left`.

This is the second PR of a series formalizing the Sturm–Tarski theorem, following leanprover-community#43783 
(`List.signVariations`). The development is a port of Wenda Li's Isabelle/AFP entry. The remaining
parts (local sign of a polynomial to the right of a point, the Cauchy index, and the theorem
itself) will follow in separate PRs. See also leanprover-community#43512.

The definition and the original proofs were written by hand. Claude Code (Fable 5.1) was used to
simplify part of the proofs and to review the code.

Co-authored-by: Pedro Saccomani <[email protected]>
Co-authored-by: Sarah Azevedo Pereira <[email protected]>
mathlib-bors Bot pushed a commit that referenced this pull request Oct 15, 2026
…e right of a point (#44248)

This PR defines `Polynomial.signRight x p : SignType`, the sign that a real polynomial `p` takes
on a sufficiently small interval `(x, x + ε)`, as the limit of `sign (p.eval y)` as `y → x` from the right, and
develops its basic API:

* `eventually_sign_eq_signRight`, `signRight_eq_iff`: the defining property and its uniqueness;
* `signRight_eq_zero_iff`: `signRight x p = 0` iff `p = 0`;
* `signRight_mul`, `signRight_neg`, `signRight_C`: `signRight x` is multiplicative, commutes with
  negation and agrees with `SignType.sign` on constants;
* `signRight_of_eval_ne_zero`, `signRight_of_eval_eq_zero`: the computation rule
  `signRight x p = sign (p.eval x)` if `p.eval x ≠ 0`, and `signRight x p = signRight x (derivative p)`
  otherwise (via the mean value theorem).

This is the local invariant behind Sturm's theorem: it determines the direction in which the sign
of a Sturm sequence changes across a root, and it will be used to define the Cauchy index in the
next PR of the series.

This is the third PR of a series formalising the Sturm–Tarski theorem, following #43783
(`List.signVariations`) and #43954 (`Polynomial.sturmSeq`). Everything is stated over `ℝ`; the
statements hold over any real closed field, and the implementation notes record what is needed to
generalise them.

Co-authored-by: Pedro Saccomani <[email protected]>
Co-authored-by: Sarah Pereira <[email protected]>
Co-authored-by: Kim Morrison <[email protected]>
Co-authored-by: Oliver Nash <[email protected]>
Co-authored-by: Oliver Nash <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! ready-to-merge This PR has been sent to bors. t-algebra Algebra (groups, rings, fields, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants