Skip to content

refactor(algebra): use Fintype sum zero criterion#3281

Merged
LionSR merged 1 commit into
mainfrom
codex/fintype-sum-zero-more-20260621
Jun 21, 2026
Merged

refactor(algebra): use Fintype sum zero criterion#3281
LionSR merged 1 commit into
mainfrom
codex/fintype-sum-zero-more-20260621

Conversation

@LionSR

@LionSR LionSR commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Mathlib provides Fintype.sum_eq_zero_iff_of_nonneg as a ready-made theorem for the case where the index set is the whole finite type; the manual specialisation Finset.sum_eq_zero_iff_of_nonneg ... Finset.univ in proof scripts is replaced to align with Mathlib idioms and reduce internal boilerplate.

Description

  • In seven modules, proof-internal applications of Finset.sum_eq_zero_iff_of_nonneg specialised to Finset.univ are replaced by Fintype.sum_eq_zero_iff_of_nonneg.
  • Affected files: TNLean/Algebra/MatrixAux.lean, TNLean/Algebra/PerronFrobenius/RankOne.lean, TNLean/Channel/FixedPoint/Cesaro.lean, TNLean/Channel/Irreducible/Growth/OneStep.lean, TNLean/Channel/Semigroup/LiouvillianKernel.lean, TNLean/MPS/Irreducible/FixedPointProjection.lean, TNLean/QPF/PosDef.lean.
  • Sums over proper subsets (e.g., Finset.univ.erase i in RankOne.lean) retain the Finset variant.
  • No theorem statements, public names, or mathematical conclusions change.

Testing

  • lake exe cache get
  • lake build TNLean.Algebra.MatrixAux TNLean.Algebra.PerronFrobenius.RankOne TNLean.Channel.FixedPoint.Cesaro TNLean.Channel.Irreducible.Growth.OneStep TNLean.QPF.PosDef TNLean.Channel.Semigroup.LiouvillianKernel TNLean.MPS.Irreducible.FixedPointProjection -q --log-level=info
  • git diff --check; added-line scan for sorry, admit, axiom, native_decide, unsafeCast.
  • python3 scripts/check_reader_facing_prose.py --root . --diff-base origin/main
  • python3 scripts/blueprint_lean_sync.py --root . --ci


Note

Low Risk
Mechanical proof refactor with no API or mathematical changes; only affects internal proof scripts in algebra/channel/MPS/QPF files.

Overview
Proofs that deduce each summand is zero from a sum of nonnegative terms equals zero now call Mathlib's Fintype.sum_eq_zero_iff_of_nonneg with congrFun, instead of manually instantiating Finset.sum_eq_zero_iff_of_nonneg on Finset.univ with Finset.mem_univ.

The pattern is updated in seven modules (matrix sums, Perron–Frobenius rank-one, Cesàro fixed points, irreducible growth, Liouvillian kernel, MPS fixed-point projection, QPF positive definiteness). Sums over proper subsets (e.g. Finset.univ.erase i in RankOne.lean) still use the Finset lemma.

No theorem statements, names, or proof conclusions change—only the Mathlib entry point for whole-Fintype sums.

Reviewed by Cursor Bugbot for commit 5fd6d0e. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blueprint ↔ Lean sync and prose review

0 equivalence mismatches · 0 stale tags · 0 prose issues

Category A — Blueprint ↔ Lean equivalence

No blueprint .tex files are changed. All seven modified files touch only internal proof tactic bodies (private lemmas); no public declaration signatures change. No \lean{...}, \leanok, or \notready tags are added or removed. There is nothing to check for blueprint/Lean synchronization drift.

Category B — Prose quality

No docstrings (/-- … -/), module docs (/-! … -/), block comments, line comments, or section/namespace names appear in the diff. The changed lines are exclusively proof-term rewrites inside tactic blocks and are out of scope for prose review.

@claude claude Bot added the cleanup Code cleanup and style fixes label Jun 21, 2026
@claude

claude Bot commented Jun 21, 2026

Copy link
Copy Markdown

PR cleanup

Field Before After
Title refactor(algebra): use Fintype sum zero criterion unchanged (already compliant)
Body ## Summary / ## Validation non-standard headings restructured to ### Motivation / ### Description / ### Testing template; Cursor Bugbot block preserved verbatim
Labels (none) added: cleanup
Issue no linked issue found no issue found after checking branch name (codex/fintype-sum-zero-more-20260621), PR body, commit messages, and open issue search — please add Addresses #N when a tracking issue is created

Note: The branch name suffix -more- indicates this is a follow-up to PR #3276 (refactor(Channel/Determinant): use Fintype sum zero criterion). Consider opening a tracking issue for the broader Mathlib-idiom cleanup campaign and linking both PRs to it.

Conventions: CONTRIBUTING.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: refactor(algebra): use Fintype sum zero criterion

Verdict: APPROVE. No 🔴 or 🟡 issues found.

This is a faithful mechanical refactor: in seven modules it replaces the proof-local idiom
Finset.sum_eq_zero_iff_of_nonneg (fun j _ => h j) |>.mp hsum i (Finset.mem_univ i) with
congrFun (Fintype.sum_eq_zero_iff_of_nonneg (fun j => h j) |>.mp hsum) i.

Correctness. I confirmed the Mathlib signature is
Fintype.sum_eq_zero_iff_of_nonneg : 0 ≤ f → (∑ i, f i = 0 ↔ f = 0). The nonnegativity
premise 0 ≤ f is the Pi order ∀ j, 0 ≤ f j, supplied correctly by fun j => h j; the
.mp yields the function equality f = 0, and congrFun … i extracts f i = 0 — exactly
the per-index fact the old Finset form produced via Finset.mem_univ. The two phrasings are
definitionally equivalent here, so no mathematical statement, hypothesis, or conclusion changes.
The LiouvillianKernel.lean site correctly adapts (le_of_eq <| congrFun … feeding the
le_antisymm).

Scope check. The claim that proper-subset sums are intentionally left on the Finset lemma
holds: RankOne.lean:114 keeps Finset.sum_eq_zero_iff_of_nonneg over Finset.univ.erase i,
where the whole-Fintype lemma does not apply. This is the right boundary.

Verification. Built TNLean.Algebra.MatrixAux and TNLean.QPF.PosDef locally — both
succeed (exit 0; the only warnings are pre-existing copyright/header-linter notices unrelated to
this diff).

  • Proof integrity: clean — no sorry/axiom/native_decide/kernel bypasses introduced.
  • Mathlib style: improves library integration (uses the dedicated Fintype entry point); lines
    within 100 cols.
  • Type safety / performance / docs: unaffected (no signatures or statements touched).

No changes requested.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: APPROVE ✅

This is a clean, mechanical proof-internal refactor. No issues found in any review category.

Summary of changes

The PR replaces Finset.sum_eq_zero_iff_of_nonneg + Finset.mem_univ with Fintype.sum_eq_zero_iff_of_nonneg + congrFun in seven modules. This is the Mathlib-idiomatic pattern for whole-type sums: Fintype lemmas are designed for sums over the entire finite type, while Finset lemmas handle arbitrary subsets.

Per-category assessment

Category Severity Status
🔴 Proof integrity Blocker ✅ Pass — no sorry, admit, axiom, native_decide, or unsafeCast in diff
🔴 Proof correctness Blocker ✅ Pass — Fintype.sum_eq_zero_iff_of_nonneg returns (∑ f = 0) ↔ (f = 0) (function equality), and congrFun extracts the per-element equality. Mathematically equivalent to the old formulation.
🟡 Mathlib style Requires changes ✅ Pass — using Fintype variant for whole-type sums is preferred Mathlib style
🔴 Type safety Blocker ✅ Pass — no new type-level changes
🟡 Performance Requires changes ✅ Pass — individual file builds complete in seconds; full build in progress
🟡 Modularity Requires changes ✅ Pass — Fintype lemma is the more general, appropriate entry point
🟡 Documentation Requires changes ✅ Pass — no new definitions or theorems requiring docstrings
🟡 Paper-gap notes Requires changes ✅ N/A — no paper-gap file changes

Verification

  • lake build on all seven changed modules: all pass
  • Diff scan for sorry/admit/axiom/native_decide/unsafeCast: clean
  • Proper-subset sums (e.g., Finset.univ.erase i in RankOne.lean) correctly left on Finset lemma

🤖 Generated with Claude Code

@LionSR LionSR merged commit abd4652 into main Jun 21, 2026
19 checks passed
@LionSR LionSR deleted the codex/fintype-sum-zero-more-20260621 branch June 21, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanup and style fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants