Skip to content

refactor(Channel/Determinant): use Fintype sum zero criterion#3276

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

refactor(Channel/Determinant): use Fintype sum zero criterion#3276
LionSR merged 1 commit into
mainfrom
codex/fintype-sum-nonneg

Conversation

@LionSR

@LionSR LionSR commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Motivation

The determinant-saturation auxiliary lemma eq_zero_of_nonneg_of_sum_le_zero was still written through the Finset form of the finite-sum nonnegativity and zero-sum criteria. The statement is over an arbitrary Fintype, so the corresponding Fintype lemmas state the same argument more directly.

Description

  • Replaces the local Finset.sum_nonneg and Finset.sum_eq_zero_iff_of_nonneg steps with Fintype.sum_nonneg and Fintype.sum_eq_zero_iff_of_nonneg.
  • Leaves the public statement and all callers unchanged.

Testing

  • lake exe cache get
  • lake build TNLean.Channel.Determinant.HilbertSchmidt -q
  • git diff --check
  • rg -n "sorry|admit|axiom|native_decide|unsafeCast" TNLean/Channel/Determinant/HilbertSchmidt.lean || true
  • python3 scripts/check_reader_facing_prose.py --root . --diff-base origin/main
  • python3 scripts/blueprint_lean_sync.py --root . --ci

Addresses #22

Note

Low Risk
Proof refactor only; no API or behavioral change to the lemma or its callers.

Overview
Refactors the proof of eq_zero_of_nonneg_of_sum_le_zero in HilbertSchmidt.lean so the argument uses Fintype.sum_nonneg and Fintype.sum_eq_zero_iff_of_nonneg instead of the Finset versions (Finset.sum_nonneg, Finset.sum_eq_zero_iff_of_nonneg, and explicit Finset.mem_univ).

The lemma's statement and its use in HeisenbergDual.lean are unchanged; only the internal proof steps are shortened and aligned with the [Fintype ι] hypothesis.

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

@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 equivalence and status (Category A): No .tex files changed. The only modified declaration, eq_zero_of_nonneg_of_sum_le_zero, has its proof body simplified but its statement is unchanged, so no \lean{...}, \leanok, or \uses{...} tags are affected. Nothing to flag.

Prose quality (Category B): No blueprint prose, docstrings, or comments were modified. Nothing to flag.

0 equivalence mismatches, 0 stale status tags, 0 prose issues.

@claude claude Bot added formalization Lean 4 formalization task wolf-ch6 Wolf Lecture Notes — Chapter 6: Spectral Properties tracking Tracking issue for a formalization area labels Jun 21, 2026
@claude

claude Bot commented Jun 21, 2026

Copy link
Copy Markdown

PR cleanup

Field Before After
Title refactor(Channel/Determinant): use Fintype sum zero criterion unchanged
Body Refs #22. inside Description section; <!-- CURSOR_SUMMARY --> HTML comment delimiters present restructured: Refs #22. removed from Description, Addresses #22 added as standard footer after ---; Cursor Bugbot > [!NOTE] block preserved after footer; HTML comment markers removed
Labels (none) added: formalization, wolf-ch6, tracking
Issue linked to #22 (tracking: Wolf Ch6 spectral properties)

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(Channel/Determinant): use Fintype sum zero criterion

Verdict: APPROVE. No 🔴 or 🟡 issues found.

What was checked

This PR rewrites the proof of eq_zero_of_nonneg_of_sum_le_zero in TNLean/Channel/Determinant/HilbertSchmidt.lean, swapping the Finset.sum_nonneg / Finset.sum_eq_zero_iff_of_nonneg (+ explicit Finset.mem_univ) steps for the Fintype-namespaced Fintype.sum_nonneg and Fintype.sum_eq_zero_iff_of_nonneg.

  • Proof integrity 🔴: No sorry/admit/axiom/native_decide/unsafeCast introduced; file scans clean.
  • Proof correctness 🔴: The new proof is sound. Fintype.sum_nonneg is the to_additive of Fintype.one_le_prod (Mathlib/Algebra/Order/BigOperators/Group/Finset.lean:612), whose hypothesis 0 ≤ f in the Pi order is definitionally ∀ i, 0 ≤ f i, so Fintype.sum_nonneg hf typechecks against hf : ∀ i, 0 ≤ f i. Fintype.sum_eq_zero_iff_of_nonneg (to_additive of prod_eq_one_iff_of_one_le, line 618) yields ∑ i, f i = 0 ↔ f = 0 with function equality on the right, so congrFun (… .mp hsum_zero) i : f i = (0 : ι → ℝ) i, defeq to the goal f i = 0. The le_antisymm hsum (Fintype.sum_nonneg hf) step is correct.
  • Statement faithfulness: The public signature ({ι} [Fintype ι] (f) (hf) (hsum) : ∀ i, f i = 0) and docstring are unchanged; the sole caller eq_zero_of_nonneg_of_sum_le_zero _ hgap_trace_nonneg hgap_trace_sum_le (HeisenbergDual.lean:180) still matches positionally. No hypotheses added or removed.
  • Type safety 🔴 / Performance 🟡 / Modularity 🟡 / Documentation 🟡: No concerns. The change reduces five proof lines to two and removes the Finset.mem_univ plumbing, which is exactly the intended simplification given the Fintype hypothesis.

ℹ️ Advisory (non-blocking)

The closing term exact fun i => congrFun ((Fintype.sum_eq_zero_iff_of_nonneg hf).mp hsum_zero) i is eta-expanded; exact congrFun ((Fintype.sum_eq_zero_iff_of_nonneg hf).mp hsum_zero) would suffice against the ∀ i, f i = 0 goal. Purely cosmetic — acceptable as written.

@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 Summary — APPROVE

This is a clean proof refactor of eq_zero_of_nonneg_of_sum_le_zero replacing Finset-scoped lemmas (Finset.sum_nonneg, Finset.sum_eq_zero_iff_of_nonneg) with the corresponding Fintype-scoped lemmas (Fintype.sum_nonneg, Fintype.sum_eq_zero_iff_of_nonneg). The lemma statement and all callers are unchanged.

Assessment by category

Category Result
🔴 Proof integrity ✅ No issues — no sorry/admit/axiom introduced; build passes
🔴 Proof correctness ✅ Sound — le_antisymm hsum (Fintype.sum_nonneg hf) yields ∑ f = 0, then Fintype.sum_eq_zero_iff_of_nonneg + congrFun gives each f i = 0
🟡 Mathlib style ✅ IdIomatic — Fintype lemmas are the natural choice given the [Fintype ι] hypothesis; proof is shorter and eliminates Finset.mem_univ boilerplate
🔴 Type safety ✅ No issues — congrFun is correctly applied to the function-equality result of Fintype.sum_eq_zero_iff_of_nonneg
🟡 Performance ✅ Trivial two-step proof, no timeout risk
🟡 Modularity ✅ No duplication; leverages existing Mathlib Fintype API
🟡 Documentation ✅ Existing docstring preserved; no new definitions
🟡 Paper-gap notes ✅ N/A — no paper-gap files changed

Caller check

The sole caller at TNLean/Channel/Determinant/HeisenbergDual.lean:180 uses eq_zero_of_nonneg_of_sum_le_zero _ hgap_trace_nonneg hgap_trace_sum_le expecting ∀ ij, … = 0. The statement is unchanged, so the caller is unaffected.

No issues found. This is ready to merge.

@LionSR LionSR marked this pull request as ready for review June 21, 2026 02:57
@LionSR LionSR merged commit bc2e4d8 into main Jun 21, 2026
27 checks passed
@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.

Category A — Blueprint ↔ Lean equivalence and status: No .tex files changed. The sole modified declaration, eq_zero_of_nonneg_of_sum_le_zero, has only its proof body rewritten; the public signature is unchanged. No \lean{...}, \leanok, or \uses{...} tags are affected. Nothing to flag.

Category B — Prose quality: No blueprint prose, Lean docstrings, or comments were modified. Nothing to flag.

0 equivalence mismatches, 0 stale status tags, 0 prose issues.

@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

Scope. A 2-line proof refactor of eq_zero_of_nonneg_of_sum_le_zero in TNLean/Channel/Determinant/HilbertSchmidt.lean, swapping the Finset.sum_nonneg / Finset.sum_eq_zero_iff_of_nonneg steps (which threaded explicit Finset.mem_univ membership) for the Fintype.* variants that match the [Fintype ι] hypothesis directly. Statement and callers (HeisenbergDual.lean) unchanged.

1. Proof integrity 🔴 — pass

No sorry/admit/axiom/native_decide/unsafeCast in the file. Verified the file builds: lake build TNLean.Channel.Determinant.HilbertSchmidt → 8651 jobs, exit 0.

2. Proof correctness 🔴 — pass

The new proof is well-structured and the logic is sound:

  • Fintype.sum_nonneg hf : 0 ≤ ∑ i, f i together with hsum : ∑ i, f i ≤ 0 gives hsum_zero : ∑ i, f i = 0 via le_antisymm.
  • (Fintype.sum_eq_zero_iff_of_nonneg hf).mp hsum_zero : f = 0, and congrFun … i : f i = 0 discharges the ∀ i, f i = 0 goal.

Both Fintype.sum_nonneg and Fintype.sum_eq_zero_iff_of_nonneg are genuine Mathlib lemmas (e.g. used in Mathlib/LinearAlgebra/Matrix/DotProduct.lean, Mathlib/LinearAlgebra/Matrix/PosDef.lean), and both take the membership-free ∀ i, 0 ≤ f i hypothesis, so the refactor is a faithful simplification — strictly fewer steps, identical content. This is exactly the kind of Mathlib reuse the contributing guide asks for.

3–7. Style / type safety / performance / modularity / documentation 🟡 — pass

  • Naming and tactic style follow Mathlib conventions; the docstring is retained and explains the mathematical meaning.
  • No type-safety, coercion, or universe concerns (the lemma is polymorphic over a Fintype ι, unchanged).
  • No performance impact; the proof is shorter and term-mode.
  • No duplication introduced; this removes locally-reproved bookkeeping in favor of library lemmas.

8. Paper-gap notes — N/A

No files under docs/paper-gaps/ touched.

ℹ️ Advisory (non-blocking): exact fun i => congrFun ((Fintype.sum_eq_zero_iff_of_nonneg hf).mp hsum_zero) i can be eta-reduced to exact congrFun ((Fintype.sum_eq_zero_iff_of_nonneg hf).mp hsum_zero), since congrFun already yields ∀ i, f i = 0 (with (0 : ι → ℝ) i defeq 0). Purely cosmetic; the current form is perfectly fine.

No 🔴 or 🟡 issues found. Approving.

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

Labels

formalization Lean 4 formalization task tracking Tracking issue for a formalization area wolf-ch6 Wolf Lecture Notes — Chapter 6: Spectral Properties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants