Skip to content

refactor(Channel/Semigroup): reuse finite-dimensional Choi CLM#3092

Merged
LionSR merged 1 commit into
mainfrom
codex/choi-clm-finite-dimensional
Jun 20, 2026
Merged

refactor(Channel/Semigroup): reuse finite-dimensional Choi CLM#3092
LionSR merged 1 commit into
mainfrom
codex/choi-clm-finite-dimensional

Conversation

@LionSR

@LionSR LionSR commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Motivation

  • choiCLM in Channel/Semigroup/CPClosure was built with an anonymous ContinuousLinearMap structure constructor, manually specifying toLinearMap := choiLinearOnCLM and cont := choiLinearOnCLM.continuous_of_finiteDimensional. Mathlib's LinearMap.toContinuousLinearMap provides exactly this construction for linear maps on finite-dimensional spaces, removing the need to spell out both fields.

Description

  • TNLean/Channel/Semigroup/CPClosure.lean: choiCLM is now LinearMap.toContinuousLinearMap choiLinearOnCLM (+2 / −3 lines). The underlying linear map choiLinearOnCLM is unchanged, and all downstream uses (e.g. isClosed_setOf_isCPMap via choiCLM.continuous) are unaffected. No declarations added or removed; no mathematical content altered.

Testing

  • lake build TNLean.Channel.Semigroup.CPClosure -q --log-level=info
  • python3 scripts/check_reader_facing_prose.py --root . --diff-base origin/main
  • python3 scripts/blueprint_lean_sync.py --root . --ci
  • Relies on Lean CI (lean_action_ci.yml) to validate build.

Note

Low Risk
Single definitional refactor with no API or proof changes; continuity still comes from finite-dimensionality via Mathlib.

Overview
choiCLM in CPClosure.lean no longer uses an explicit ContinuousLinearMap constructor with separate toLinearMap and continuous_of_finiteDimensional fields. It is now LinearMap.toContinuousLinearMap choiLinearOnCLM, aligning with the usual Mathlib pattern for finite-dimensional linear maps.

choiLinearOnCLM is unchanged. Call sites such as isClosed_setOf_isCPMap (continuity for the PSD preimage) and choiRCLM in Lindblad Euler-step arguments still use the same choiCLM API; this is a definitional cleanup only.

Reviewed by Cursor Bugbot for commit 0826166. 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 sync & prose review — 0 issues found.

Category A — Blueprint ↔ Lean equivalence and status
choiCLM has no blueprint entry (grep of blueprint/src/ returns nothing for choiCLM, choiLinearOnCLM, or CPClosure). No .tex files were changed in this PR. There are no \lean{...}, \leanok, or \notready tags to audit.

Category B — Prose quality
The only changed text is the definition body; the docstring /-- The Choi matrix as a continuous linear map on continuous endomorphisms. -/ is unmodified and contains no Lean jargon, banned software-engineering terms, or LLM writing patterns.

Summary: 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 Summary

Verdict: APPROVE

This is a one-definition refactor in TNLean/Channel/Semigroup/CPClosure.lean that replaces the manual ContinuousLinearMap construction of choiCLM with the standard Mathlib LinearMap.toContinuousLinearMap.

Category-by-category check

Category Result
🔴 Proof integrity No sorry, admit, axiom, or other blocked patterns. The change removes a manual cont proof and delegates to Mathlib's standard infrastructure.
🔴 Proof correctness The old construction (cont := choiLinearOnCLM.continuous_of_finiteDimensional) is definitionally equivalent to what LinearMap.toContinuousLinearMap provides. No mathematical change.
🟡 Mathlib style Using LinearMap.toContinuousLinearMap is the preferred Mathlib idiom. The docstring is preserved.
🔴 Type safety The type signature is unchanged. No instance or coercion issues.
🟡 Performance The construction is simplified, not complicated. No performance risk.
🟡 Modularity & duplication Removes manual duplication of the Mathlib pattern — a net improvement.
🟡 Documentation Existing docstring preserved.
🟡 Paper-gap notes No paper-gap files changed.

Downstream compatibility verified

  • .continuous projection at line 221
  • simpa [choiCLM] at line 217
  • Both work identically with the new definition.

No issues to flag. Clean refactor, ready to merge.

🤖 Generated with Claude Code

@claude claude Bot added cleanup Code cleanup and style fixes wolf-ch7 Wolf Lecture Notes — Chapter 7: Semigroup Structure labels Jun 19, 2026
@claude

claude Bot commented Jun 19, 2026

Copy link
Copy Markdown

PR cleanup

Field Before After
Title refactor(Channel/Semigroup): reuse finite-dimensional Choi CLM unchanged
Body ## Summary / ## Validation headings restructured to ### Motivation / ### Description / ### Testing template; Cursor Bugbot note preserved
Labels (none) added: cleanup, wolf-ch7
Issue no issue found — branch codex/choi-clm-finite-dimensional contains no issue-{N} pattern, PR body has no Refs/Addresses/Closes reference, and no commit message or open issue matches. Please link an issue manually if one exists.

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/Semigroup): reuse finite-dimensional Choi CLM

Verdict: Approve. No 🔴 or 🟡 issues found.

This is a faithful, semantics-preserving simplification of the choiCLM definition in TNLean/Channel/Semigroup/CPClosure.lean. The hand-rolled ContinuousLinearMap structure

toLinearMap := choiLinearOnCLM
cont := choiLinearOnCLM.continuous_of_finiteDimensional

is replaced by LinearMap.toContinuousLinearMap choiLinearOnCLM.

Correctness / type safety. The two forms are definitionally equal: LinearMap.toContinuousLinearMap packages exactly the same underlying LinearMap (choiLinearOnCLM) with the continuity witness drawn from finite-dimensionality of the domain MatrixCLM (Fin D), and the cont field is a Prop (proof-irrelevant). Hence choiCLM's action (choiCLM T = choiMatrix T.toLinearMap) and its .continuous projection are unchanged.

Downstream impact — checked, none.

  • isClosed_setOf_isCPMap (CPClosure.lean:210) unfolds choiCLM via simpa [ChoiJamiolkowski.choiCLM] and uses (choiCLM (D := D)).continuous — both remain valid.
  • EulerStep.lean consumers (choiCLM.restrictScalars ℝ at line 59 and the congrArg/change at lines 104–106) are unaffected.

Build. lake build TNLean.Channel.Semigroup.CPClosure TNLean.Channel.Semigroup.LindbladForm.EulerStep succeeds (exit 0). No new sorry/axiom/integrity blockers (docs/PROOF_INTEGRITY.md), no style, performance, modularity, or documentation concerns. The retained docstring on choiCLM is accurate.

@LionSR LionSR force-pushed the codex/choi-clm-finite-dimensional branch from 42d8f03 to 0826166 Compare June 20, 2026 02:31
@LionSR LionSR marked this pull request as ready for review June 20, 2026 02:31

@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 & prose review — 0 issues found.

Category A — Blueprint ↔ Lean equivalence and status

No .tex files were changed. choiCLM and choiLinearOnCLM have no blueprint entries (blueprint/src/ contains no references to either). There are no \lean{...}, \leanok, or \notready tags to audit. The change is a purely definitional refactor with no added or removed declarations, so no new blueprint entries are required.

Category B — Prose quality

The only reader-facing text in scope is the docstring on choiCLM (line 198), which is unchanged: /-- The Choi matrix as a continuous linear map on continuous endomorphisms. -/. 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.

@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/Semigroup): reuse finite-dimensional Choi CLM

Verdict: APPROVE — no 🔴 or 🟡 issues found.

Summary

This is a one-line definitional refactor of ChoiJamiolkowski.choiCLM in TNLean/Channel/Semigroup/CPClosure.lean. The anonymous ContinuousLinearMap constructor

{ toLinearMap := choiLinearOnCLM
  cont := choiLinearOnCLM.continuous_of_finiteDimensional }

is replaced by the idiomatic Mathlib wrapper LinearMap.toContinuousLinearMap choiLinearOnCLM, which is exactly the construction "promote a linear map on a finite-dimensional space to a continuous linear map." Good reuse — it removes the manual cont field while sourcing continuity from the same continuous_of_finiteDimensional fact internally.

Checks performed

  • Proof integrity 🔴: No sorry/axiom/native_decide/kernel bypass introduced. The underlying linear map choiLinearOnCLM is untouched.
  • Proof correctness 🔴: The only subtle point is that isClosed_setOf_isCPMap (lines 213–218) uses change ... ↔ (choiMatrix T.toLinearMap).PosSemidef followed by simpa [choiCLM], which depends on choiCLM T being definitionally choiMatrix T.toLinearMap. LinearMap.toContinuousLinearMap preserves this defeq (its coercion reduces to the underlying linear map's toFun), and the continuity argument at line 221 (choiCLM.continuous) is unaffected.
  • Build 🔴: Verified locally — lake build TNLean.Channel.Semigroup.CPClosure completes successfully (3004 jobs). The only warnings are pre-existing copyright-header linter messages on unrelated files.
  • Style / type safety / docs: Docstring on choiCLM retained; type signature unchanged; no new declarations; no API surface change.

Clean, minimal, mathematically inert cleanup. Nice.

@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

This is a clean, minimal refactor (+2/−3 lines) that replaces an explicit ContinuousLinearMap structure constructor with LinearMap.toContinuousLinearMap. The change is definitionally equivalent and verified by a successful lake build.

Category-by-category assessment

🔴 Proof integrity — ✅ Pass.
No sorry, axiom, admit, or other blockers introduced or affected.

🔴 Proof correctness — ✅ Pass.
LinearMap.toContinuousLinearMap (Mathlib Topology/Algebra/Module/FiniteDimension.lean:299) is defined as ⟨f, f.continuous_of_finiteDimensional⟩ — exactly the same construction the old code performed manually. The underlying linear map choiLinearOnCLM is unchanged. All downstream uses (choiCLM T application, choiCLM.continuous, simpa [choiCLM], .restrictScalars ℝ) are verified compatible.

🟡 Mathlib style — ✅ Pass.
Using LinearMap.toContinuousLinearMap is the standard Mathlib idiom for promoting a linear map on a finite-dimensional space. The old field-by-field construction was unnecessarily verbose. No naming or style issues.

🔴 Type safety — ✅ Pass.
No type changes, universe issues, or instance requirements altered. The [FiniteDimensional ℂ (MatrixCLM (Fin D))] instance was already required (and available) for continuous_of_finiteDimensional in the old code.

🟡 Performance — ✅ Pass.
No algorithmic or proof-search changes. The @[simps] attribute on LinearMap.toContinuousLinearMap may even improve simp unfolding behavior.

🟡 Modularity & duplication — ✅ Pass.
This change reduces duplication by reusing Mathlib's existing LinearMap.toContinuousLinearMap instead of manually inlining the structure fields.

🟡 Documentation — ✅ Pass.
The existing docstring /-- The Choi matrix as a continuous linear map on continuous endomorphisms. -/ remains present.

🟡 Paper-gap notes — N/A. No paper-gap files changed.

Verdict: APPROVE

No 🔴 or 🟡 issues found. This is a textbook definitional cleanup.

@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/Semigroup): reuse finite-dimensional Choi CLM

Verdict: Approve. No 🔴 or 🟡 issues.

Summary

This is a single, well-scoped definitional cleanup. The continuous linear map choiCLM in TNLean/Channel/Semigroup/CPClosure.lean is rebuilt from the anonymous ContinuousLinearMap constructor ({ toLinearMap := choiLinearOnCLM, cont := choiLinearOnCLM.continuous_of_finiteDimensional }) to the idiomatic LinearMap.toContinuousLinearMap choiLinearOnCLM. The underlying linear map choiLinearOnCLM is untouched, and no declarations are added or removed.

Correctness verification

I checked that the definitional behaviour relied upon by both call sites is preserved:

  • isClosed_setOf_isCPMap (CPClosure.lean:210) uses simpa [ChoiJamiolkowski.choiCLM] ... and (choiCLM (D := D)).continuous. The simpa discharge goes through LinearMap.coe_toContinuousLinearMap', which is @[simp] and proven by rfl in Mathlib/Topology/Algebra/Module/FiniteDimension.lean:314, so choiCLM T still reduces to choiLinearOnCLM T = choiMatrix T.toLinearMap. .continuous is available on any CLM.
  • EulerStep.lean:104–108 uses a change that depends on choiCLM T being definitionally equal to choiMatrix T.toLinearMap. Because coe_toContinuousLinearMap' is rfl, (LinearMap.toContinuousLinearMap choiLinearOnCLM) T reduces by rfl to choiLinearOnCLM T, exactly as the old structure-projection form did. Definitional equality is preserved, so the change and restrictScalars/choiRCLM uses remain valid.

Categories

  • Proof integrity: No sorry/axiom/kernel bypasses introduced. ✅
  • Proof correctness: No mathematical content changed; continuity still derives from finite-dimensionality, now via the standard Mathlib equiv. ✅
  • Mathlib style: The change moves toward the canonical idiom. ✅
  • Type safety / Performance / Modularity / Documentation: Unaffected; the docstring on choiCLM is retained. ✅

Note: the PR description lists a build check for TNLean.Channel.Semigroup.CPClosure only, while EulerStep.lean also consumes choiCLM. The defeq analysis above indicates EulerStep should be unaffected, and CI (lean_action_ci.yml) covers it — worth confirming that run is green before merge.

@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/Semigroup): reuse finite-dimensional Choi CLM

Verdict: APPROVE — no 🔴 or 🟡 issues found.

Summary

This replaces the manual ContinuousLinearMap structure constructor for choiCLM with LinearMap.toContinuousLinearMap choiLinearOnCLM (+2/−3 lines). The Mathlib definition (Topology/Algebra/Module/FiniteDimension.lean:299) is:

def toContinuousLinearMap : (E →ₗ[𝕜] F') ≃ₗ[𝕜] E →L[𝕜] F' where
  toFun f := ⟨f, f.continuous_of_finiteDimensional⟩

This is definitionally identical to the old { toLinearMap := choiLinearOnCLM; cont := choiLinearOnCLM.continuous_of_finiteDimensional }.

Category-by-category

Category Result
🔴 Proof integrity ✅ Pass. No sorry/axiom/admit introduced or affected.
🔴 Proof correctness ✅ Pass. Definitionally equivalent to the old construction. All downstream uses (choiCLM T application, choiCLM.continuous, simpa [choiCLM]) verified compatible.
🟡 Mathlib style ✅ Pass. LinearMap.toContinuousLinearMap is the standard Mathlib idiom.
🔴 Type safety ✅ Pass. No type signature or instance changes.
🟡 Performance ✅ Pass. No algorithmic changes.
🟡 Modularity & duplication ✅ Pass. Reduces manual duplication of a Mathlib pattern.
🟡 Documentation ✅ Pass. Existing docstring retained.
🟡 Paper-gap notes N/A. No paper-gap files changed.

Build

lake build TNLean.Channel.Semigroup.CPClosure completes successfully (3004 jobs).

Clean refactor, ready to merge.

@LionSR LionSR merged commit f1e6297 into main Jun 20, 2026
19 of 20 checks passed
@LionSR LionSR deleted the codex/choi-clm-finite-dimensional branch June 20, 2026 02:50
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 wolf-ch7 Wolf Lecture Notes — Chapter 7: Semigroup Structure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants