refactor(PEPS): use subtype product equivalence for incidence swap#3136
refactor(PEPS): use subtype product equivalence for incidence swap#3136LionSR wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Blueprint ↔ Lean & Prose Review
Category A — Blueprint ↔ Lean equivalence and status: no issues.
sigmaSwap has no blueprint entry (the PEPS/ module is exploratory and carries no \lean{...} tags). No .tex files were changed, no \leanok/\notready tags are affected, and no declaration with a blueprint counterpart was modified.
Category B — Prose quality: no issues.
The only reader-facing text in scope is the unchanged docstring for sigmaSwap (lines 66–67). It contains no Lean jargon, no banned software-engineering terms, and no LLM writing patterns.
Summary: 0 equivalence mismatches, 0 stale status tags, 0 prose issues.
|
PR cleanup
No issue number was found in the branch name ( Conventions: CONTRIBUTING.md |
There was a problem hiding this comment.
Review: refactor(PEPS): use subtype product equivalence for incidence swap
Verdict: Approve. No 🔴 or 🟡 issues found. One ℹ️ advisory below.
Scope
The PR rewrites the single definition sigmaSwap in TNLean/PEPS/EdgeScalarSolve.lean:68-74, replacing the explicit toFun/invFun/left_inv/right_inv record (with rfl inverse proofs) by a composition of three Mathlib equivalences. No other declaration changes.
Proof integrity 🔴 — pass
No sorry/axiom/admit/native_decide/unsafeCast introduced (the only project sorry remains the unrelated, known MPS/Periodic/Overlap/Case3.lean). This is a proof-only refactor of an Equiv definition.
Correctness 🔴 — pass (verified)
The new sigmaSwap is mathematically identical to the original. Tracing the forward map of
((Equiv.subtypeProdEquivSigmaSubtype p).symm.trans ((Equiv.prodComm V (Edge G)).subtypeEquiv …)).trans (Equiv.subtypeProdEquivSigmaSubtype q):
subtypeProdEquivSigmaSubtype p |>.symm:⟨v, ⟨e, h⟩⟩ ↦ ⟨(v, e), h⟩(prodComm V (Edge G)).subtypeEquiv (fun _ => Iff.rfl):⟨(v, e), h⟩ ↦ ⟨(e, v), h⟩— the predicate is preserved byIff.rflbecause bothp (v, e)andq (e, v)are literallye.1.1 = v ∨ e.1.2 = vsubtypeProdEquivSigmaSubtype q:⟨(e, v), h⟩ ↦ ⟨e, ⟨v, h⟩⟩
Composite: ⟨v, ⟨e, h⟩⟩ ↦ ⟨e, ⟨v, h⟩⟩, identical to the deleted toFun p := ⟨p.2.1, ⟨p.1, p.2.2⟩⟩. The downstream consumer prod_orientedIncidence_eq_one (lines 96-112) closes the inner Finset.prod_congr … rfl (line 109) by definitional unfolding of (sigmaSwap).symm ⟨e, x⟩ to ⟨x.1, ⟨e, x.2⟩⟩. I confirmed this still holds by building the module locally:
lake build TNLean.PEPS.EdgeScalarSolve → Build completed successfully
The only warnings emitted are pre-existing and on unrelated lines (v0Inc_subsingleton unused-section-var at 226-228, header copyright linter); none touch the changed definition.
Type safety 🔴 — pass
Both predicate arguments are spelled out explicitly (fun (v : V) (e : Edge G) => … and fun (e : Edge G) (v : V) => …), so the two subtypeProdEquivSigmaSubtype instantiations and the subtypeEquiv transport unify without relying on elaboration order. Build confirms.
Style / performance / docs 🟡 — pass
Naming (sigmaSwap, camelCase def) and the docstring are preserved; noncomputable is retained as before. No performance concern (term-mode definition).
ℹ️ Advisory (non-blocking)
The original explicit form was already a one-glance-verifiable Equiv with rfl inverse laws. The composed version is more "library-idiomatic" but requires the reader to unfold subtypeProdEquivSigmaSubtype, the subtypeEquiv transport, and prodComm to re-derive the map. This is a readability/transparency tradeoff, not a defect — either form is acceptable. No action required.
Note: PR is currently in draft state.
There was a problem hiding this comment.
Review Summary: ✅ APPROVE
This PR refactors sigmaSwap in TNLean/PEPS/EdgeScalarSolve.lean, replacing a manually-defined equivalence with a composition of standard Mathlib equivalences (Equiv.subtypeProdEquivSigmaSubtype + Equiv.prodComm.subtypeEquiv). The mathematical content is unchanged.
Detailed analysis
🔴 Proof integrity: Pass. No sorry, axiom, admit, native_decide, or unsafeCast in the changed file. The build succeeds with only pre-existing warnings unrelated to this change.
🔴 Proof correctness: Pass. The chain of equivalences is mathematically correct:
Equiv.subtypeProdEquivSigmaSubtype.symmconverts(Σ v, IncidentEdge G v)to{p : V × Edge G // …}(Equiv.prodComm …).subtypeEquiv (fun _ => Iff.rfl)swaps the pair toEdge G × VEquiv.subtypeProdEquivSigmaSubtypeconverts to the target(Σ e, incVertex e)
The downstream proof prod_orientedIncidence_eq_one (line 109) uses rfl to equate the reindexed edgeScalarUnit term with (if e.1.1 = x.1 then s e else (s e)⁻¹). This rfl holds definitionally because:
Equiv.subtypeProdEquivSigmaSubtype.invFunis structurally transparent (explicit⟨⟨x.1, x.2⟩, x.2.property⟩)subtypeEquivwith(fun _ => Iff.rfl)gives definitionally transparentinvFun— the▸term collapses atrfl(sinceprodComm.apply_symm_applyisrfl)Equiv.transuses∘forinvFun, which reduces compositionally- The resulting
(sigmaSwap.symm ⟨e, x⟩).1and.2reduce to exactlyx.1and⟨e, x.2⟩, matching the old explicit definition
The edgeScalarUnit function only inspects .1.1.1 and .1 of the IncidentEdge argument, which are independent of the proof term in .2, so the rfl is robust.
🟡 Mathlib style: Pass. The definition uses standard Mathlib equivalence combinators (subtypeProdEquivSigmaSubtype, prodComm, subtypeEquiv) rather than a custom manual construction. Line length, naming, and formatting follow conventions. The Iff.rfl pattern is correct and idiomatic when predicates are definitionally equal under the equivalence (as they are here, due to the symmetric form e.1.1 = v ∨ e.1.2 = v).
🔴 Type safety: Pass. No universe issues, missing instances, or coercion problems. The noncomputable attribute is preserved.
🟡 Performance: Pass. The rfl proofs are fast. No decide, simp with unbounded lemma sets, or deep rw chains.
🟡 Modularity & duplication: Pass. This is an improvement — using standard library components instead of a bespoke equivalence definition.
🟡 Documentation: Pass. The existing docstring is preserved and accurately describes the equivalence.
🟡 Paper-gap notes: N/A — no changes to docs/paper-gaps/.
Motivation
sigmaSwapinPEPS/EdgeScalarSolve.leanwas defined by explicittoFun/invFunfields with manual inverse proofs. Replacing this construction with Mathlib'sEquiv.subtypeProdEquivSigmaSubtype, composed withEquiv.prodCommviaEquiv.subtypeEquiv, reduces bespoke proof obligations and aligns the construction with the library (arXiv:1804.04964, Section 3).Description
TNLean/PEPS/EdgeScalarSolve.lean(6 additions, 5 deletions):sigmaSwapis now built as a chain of Mathlib equivalences —(Equiv.subtypeProdEquivSigmaSubtype).symm,Equiv.prodCommtransported through subtypes viaEquiv.subtypeEquiv, andEquiv.subtypeProdEquivSigmaSubtype— replacing the previous explicittoFun/invFundefinition with manual inverse lemmas.(Σ v : V, IncidentEdge v)to(Σ e : Edge G, IncVertex e).prod_orientedIncidence_eq_one(which appliesEquiv.prod_comp (sigmaSwap).symm) is unchanged; the refactor is definitionally compatible.Testing
lake env lean TNLean/PEPS/EdgeScalarSolve.leanlake build TNLean.PEPS.EdgeScalarSolve -q --log-level=inforg -n "sorry|axiom|admit|native_decide|unsafeCast" TNLean/PEPS/EdgeScalarSolve.lean || truelake build TNLean -q --log-level=info): passes with only pre-existing warnings (including the known sorry inMPS/Periodic/Overlap/Case3.lean).lean_action_ci.yml) to validate the build.Note
Low Risk
Proof-only refactor in one combinatorial lemma; behavior is intended to stay definitionally compatible for the existing product-cancellation proof.
Overview
sigmaSwapinEdgeScalarSolve.leanis no longer defined by explicittoFun/invFunandrflinverse lemmas. It is built as a chain of Mathlib equivalences:Equiv.subtypeProdEquivSigmaSubtype(sym),Equiv.prodCommonV × Edge GviasubtypeEquiv, and anothersubtypeProdEquivSigmaSubtype.The equivalence still reindexes
(Σ v, IncidentEdge)to(Σ e, incVertex e);prod_orientedIncidence_eq_oneis unchanged and still usesEquiv.prod_comp (sigmaSwap).symm.Reviewed by Cursor Bugbot for commit 82754cf. Bugbot is set up for automated code reviews on this repo. Configure here.