refactor(MPS/Core): use arrow congruence for word reversal#3133
Conversation
There was a problem hiding this comment.
Blueprint ↔ Lean review (categories A and B only)
Category A — Blueprint ↔ Lean equivalence and status
Theorem MPSTensor.sum_evalWord_mul_conjTranspose_evalWord
Blueprint entry: blueprint/src/chapter/ch13_parent_hamiltonian_block_diagonal.tex, lines 1176–1208.
-
Statement equivalence (A.1): blueprint hypothesis
$\sum_a A_a A_a^\dagger = I$ matcheshRight : ∑ i : Fin d, A i * (A i)ᴴ = 1; blueprint conclusion "for every length$M$ ,$\sum_\rho A_\rho A_\rho^\dagger = I$ " matches∀ L : ℕ, ∑ ρ : Fin L → Fin d, evalWord A (List.ofFn ρ) * (evalWord A (List.ofFn ρ))ᴴ = 1. No discrepancy. -
\leanokaccuracy (A.2): The PR is a pure proof-body refactor — the theorem signature is unchanged and nosorryis introduced. Both the statement\leanok(line 1179) and proof\leanok(line 1193) remain valid. -
No blueprint files were modified, so no stale tags, missing
\lean{...}tags, or\usesdrift to flag.
Category B — Prose quality
No blueprint .tex files, docstrings, or comments were modified by this PR. Nothing to flag.
0 equivalence mismatches · 0 stale \leanok · 0 prose issues
|
PR cleanup
Conventions: CONTRIBUTING.md |
There was a problem hiding this comment.
Review: refactor(MPS/Core): use arrow congruence for word reversal
I reviewed the single change to TNLean/MPS/Core/Blocking.lean against all required categories. No 🔴 Blocker or 🟡 Requires-changes issues found.
What changed
In the proof of sum_evalWord_mul_conjTranspose_evalWord, the local revEquiv (a hand-built (Fin L → Fin d) ≃ (Fin L → Fin d) carrying ρ ↦ ρ ∘ Fin.rev with explicit left_inv/right_inv proofs) is replaced by Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d)), and the hword step now closes via simpa [revEquiv, Equiv.arrowCongr, Function.comp_def] instead of the old unfolding.
Proof correctness ✅
The refactor is faithful. Equiv.arrowCongr e₁ e₂ sends f ↦ e₂ ∘ f ∘ e₁.symm, so here revEquiv ρ = ρ ∘ Fin.revPerm.symm. Since Fin.rev is an involution, Fin.revPerm.symm reduces to Fin.rev, giving revEquiv ρ = ρ ∘ Fin.rev — the same toFun as the deleted equivalence. The two downstream steps that depend on revEquiv (list_ofFn_comp_fin_rev rewriting List.ofFn (revEquiv ρ) to (List.ofFn ρ).reverse, and the Fintype.sum_equiv reindexing) are therefore unaffected, and _ = 1 still discharges via sum_evalWord_conjTranspose_mul_evalWord. No mathematical content changes; the theorem statement and its source citation (arXiv:quant-ph/0608197, Theorem 12) are untouched.
Proof integrity ✅
No sorry, admit, axiom, native_decide, or unsafeCast introduced. Net −8 lines.
Build verification ✅
lake build TNLean.MPS.Core.Blocking→Build completed successfully (2968 jobs).- The only warnings emitted are pre-existing header-style lints (
Copyright too short,Mathlib.Tacticimport) unrelated to this diff.
Type safety / Performance / Modularity / Documentation ✅
No type or coercion concerns (the equivalence types match exactly). The new form aligns with the existing rotateConfig idiom in MPS/MPDO/AreaLaw.lean. No performance regression (the simpa set is small and bounded). Documentation is unaffected.
ℹ️ Advisory (non-blocking)
The hword simplification manually unfolds Equiv.arrowCongr. A slightly more idiomatic alternative would lean on the Equiv.arrowCongr_apply simp lemma rather than unfolding the definition, but the current form is correct and compiles cleanly — acceptable as-is.
Approving. (Note: the PR is currently in draft state, so this approval does not enable merge until it is marked ready.)
There was a problem hiding this comment.
Review Summary
Verdict: ✅ APPROVE
This is a clean, focused refactor in TNLean/MPS/Core/Blocking.lean that replaces a hand-built reversal equivalence (revEquiv with explicit toFun/invFun/left_inv/right_inv proofs, 8 lines) with Mathlib's Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d)) (1 line). No mathematical content is changed.
Detailed findings
🔴 Proof integrity — PASS
- No
sorry,axiom,admit,native_decide, orunsafeCastintroduced. - No kernel bypasses or circular reasoning.
lake build TNLean.MPS.Core.Blockingsucceeds cleanly.
🔴 Proof correctness — PASS
- The new equivalence
Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d))is mathematically identical to the oldρ ↦ ρ ∘ Fin.rev.arrowCongr'stoFunmapsftoe₂ ∘ f ∘ e₁.symm; withe₂ = refl(identity) ande₁.symm = Fin.revPerm(self-inverse byrevPerm_symm), this reduces tof ∘ Fin.rev.Fin.revPermis extensionallyFin.rev(via@[simps! apply] revPerm_apply).
- All three uses of
revEquivin the proof remain valid:hwordsimplification (line 355): after unfoldingrevEquivandarrowCongr,list_ofFn_comp_fin_revstill applies to produceList.ofFn (ρ ∘ Fin.rev) = (List.ofFn ρ).reverse.Fintype.sum_equivreindexing (line 369):Fintype.sum_equivrequires only a validEquiv—arrowCongrproduces one.simpaon line 369: the goal andFintype.sum_equiv's conclusion are syntactically identical after thef/gabstractions; thesimpasucceeds gracefully.
🟡 Mathlib style — PASS
- Replacing hand-built equivalence machinery with
Equiv.arrowCongris idiomatic Mathlib style and matches patterns used elsewhere in this repository (e.g.,rotateConfig). Fin.revPermis available via the existing importMathlib.Data.Fin.Tuple.Basic, which publicly importsMathlib.Data.Fin.Rev.Equiv.arrowCongrandEquiv.reflare foundational and available transitively.- Line breaks and formatting conform to Mathlib conventions.
🔴 Type safety — PASS
Equiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d)) : (Fin L → Fin d) ≃ (Fin L → Fin d)— types align correctly.- No universe or coercion issues.
🟡 Performance — PASS
- No algorithmic change; the
simpaunfolds one additional definition (Equiv.arrowCongr), which is negligible. - No
decide,omega,norm_numon large types.
🟡 Modularity & duplication — PASS
- This refactor reduces duplication by replacing custom equivalence proofs with a standard Mathlib combinator.
🟡 Documentation — PASS
- No new definitions or theorems; no new docstrings required.
- The existing theorem docstring (with arXiv reference) is preserved.
🟡 Paper-gap notes — N/A
- No changes under
docs/paper-gaps/.
No issues found across any review category. The PR is ready to merge.
Motivation
Linsum_evalWord_mul_conjTranspose_evalWord(a localrevEquivwith explicit inverse proofs) can be replaced by Mathlib'sEquiv.arrowCongrapplied toFin.revPerm, matching patterns used elsewhere in the repository (e.g.rotateConfig).Description
TNLean/MPS/Core/Blocking.lean: in the proof ofsum_evalWord_mul_conjTranspose_evalWord, replaced the localrevEquivdefinition withEquiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d)).list_ofFn_comp_fin_rev; the only proof change is unfoldingrevEquiv,Equiv.arrowCongr, andFunction.comp_defin thehwordsimplification instead of the old local equivalence definition.sorrys are introduced.Testing
lake env lean TNLean/MPS/Core/Blocking.leanlake exe cache getlake build TNLean.MPS.Core.Blocking -q --log-level=inforg -n "sorry|axiom|admit|native_decide|unsafeCast" TNLean/MPS/Core/Blocking.lean || truelake build TNLean -q --log-level=infopython3 scripts/check_reader_facing_prose.py --root . --diff-base origin/mainpython3 scripts/blueprint_lean_sync.py --root . --ciNote
Low Risk
Proof-only refactor in one theorem; no API or runtime behavior change.
Overview
In
sum_evalWord_mul_conjTranspose_evalWord, the hand-built equivalence that reverses length-Lphysical words (ρ ↦ ρ ∘ Fin.revwith explicit inverse proofs) is replaced byEquiv.arrowCongr Fin.revPerm (Equiv.refl (Fin d)), matching patterns elsewhere in the repo (e.g.rotateConfig).The reversed-word step still goes through
list_ofFn_comp_fin_rev; the only proof tweak is unfoldingrevEquiv,Equiv.arrowCongr, andFunction.comp_defin thehwordsimplification instead of the old local equivalence definition.Reviewed by Cursor Bugbot for commit 92a0d72. Bugbot is set up for automated code reviews on this repo. Configure here.