feat(Units): parameterise Dimension and its unit twin over a basis (Stacked on #1445)#1447
Conversation
Bump lean-toolchain, mathlib, and doc-gen4 to v4.32.0 (tracker leanprover-community#1437) and repair the source breakages from the Mathlib 4.31->4.32 API drift across Physlib, QuantumInfo, and PhyslibAlpha. Proofs, instances, and imports only; no lemma/definition statement or mathematical content was changed. Breakage classes fixed: - Hand-rolled AddMonoid/AddCommMonoid/AddCommGroup instances whose nsmul/zsmul field proofs relied on `ring` closing scalar-multiplication (smul) goals, which it no longer does in 4.32. - Structure refactors: MonoidAlgebra and MvPolynomial are now wrapper structs (no longer defeq to their coefficient Finsupp); ContRepresentation gained a toMonoidHom field; Mathlib.Meta.Positivity.Strictness gained an Option PartialOrder index (13 positivity extensions); LeftOrdContinuous gained an s.Nonempty hypothesis. - Tactic drift in fun_prop / measurability (metavariable goals), simp / simpa / convert normal forms. - Deprecation renames: PiTensorProduct import, IsOpen.locallyPathConnectedSpace, Finset.le_eq_subset, TwoSidedIdeal.mem_ofRingCon, and the removed simpVarHead linter; def -> lemma for the propositions flagged by the defProp linter. `lake build` (Physlib + QuantumInfo + PhyslibAlpha) is green; `lake exe lint_all` and the version-bump scripts (TODO_to_yml, stats, informal, make_tag) pass. Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
Apply @nateabr's review suggestions, which simplify the migration in three places and, for the spectral measure, identify a cleaner root-cause fix: - SpaceAndTime/Space/Module.lean: define `zsmul` via `•` (`z • p.val i`), so the default `zsmul_zero'`/`zsmul_succ'`/`zsmul_neg'` proofs discharge and those blocks are dropped. - StringTheory/FTheory/SU5/Fluxes/Basic.lean: define `nsmul` via `•` and close `nsmul_zero`/`nsmul_succ` with `zero_nsmul`/`succ_nsmul`. - QuantumMechanics/Operators/SpectralTheory/SpectralMeasure.lean: the 4.32 breakage was the `CoeFun` coercion, not the composition lemmas; use `⇑μS.toVectorMeasure` and revert `comp_of_disjoint`, `comp_eq_of_inter`, and `commute` to their original form. Thanks to @nateabr for the careful and constructive review. Co-authored-by: nateabr <135662056+nateabr@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
|
Thank you for this PR, which will now be reviewed. If submitting to ./Physlib or ./QuantumInfo, please see our review guidelines if you are not familiar with the process. You should expect a back and forth with a reviewer before your PR is merged. See also that link for how to add appropriate labels to your PR. The PR will also go through a number of automated checks. You can learn more about these here, including how to run them locally. If you are submitting to ./PhyslibAlpha there will be a lighter review process, though your PR must still pass the automated checks. If you want to bring attention to this PR, please write a message on this thread of the Lean Zulip. Important: If a reviewer adds an |
|
Note on dependencies and review order. This PR is stacked on #1445 (the v4.32.0 toolchain bump). Since it targets master, the first two commits — 48fad30 and 978ce09 — belong to #1445 and will drop out of this diff automatically once #1445 merges. The substantive change here is the final commit, 97c70b5 (feat(Units): parameterise Dimension and its unit twin over a basis); that's the one to review. Because of that dependency:
Since the original issue arose in the context of my metrology work which depends on Caltech's TorchLean that already migrated to 4.32.0, I chose to stack this PR on top of #1445. |
…ilation The `unusedArguments` alpha-linter (`runPhyslibAlphaLinters`) fails under the v4.32.0 toolchain on `StinespringDilation`. The file is unchanged since the v4.31.0 bump and the same linter is green on master, so the reports are a consequence of the 4.31 -> 4.32 Mathlib bump: the matrix operations these lemmas call (`tr₂`, `stinespringOp`, `Matrix.one`) no longer thread the flagged instances through their elaborated proof terms, so the arguments are now genuinely dead. Verified against each definition's signature: - `tr₂_e₀Xe₀`: `[Zero w]` — `tr₂` needs only `[Fintype n]` on the traced index. - `tracefree_version`: `[Zero r]`, `[DecidableEq m]` — `(1 : Matrix r r R)` needs `[DecidableEq r]` (index) and `Zero/One R` (from `RCLike R`), not `Zero r`; `stinespringForm` needs `[Fintype r] [DecidableEq r] [Fintype m]`, not `[DecidableEq m]`. - `stinespringOp_apply`: `[Fintype m]`, `[DecidableEq m]` — `stinespringOp` needs only `[Fintype r] [DecidableEq r]`. - `heisenberg_schrõdinger`: `[Zero r]`, `[DecidableEq m]` — same two; these were live only because its proof (`rw [tracefree_version]`) threaded them into `tracefree_version`. CI reported only the first three; removing them from `tracefree_version` exposes this caller, which the local linter then flags. Removing instance-implicit arguments is safe for callers (they are inferred, never passed positionally). `runPhyslibAlphaLinters` is now clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ions
Toolchain collateral from the v4.32.0 bump — not a source change.
## Symptom
The `runLinter on Physlib` CI step (`env LEAN_ABORT_ON_PANIC=1 lake exe
runPhyslibLinters`, build.yml) fails on this PR with 5 errors, while the
*identical* step is green on `master`. `master` still runs Lean/Mathlib
v4.31.0; this PR is the v4.32.0 bump. The v4.32.0 `#lint` linters
(`unusedArguments`, `checkType`) are stricter than v4.31.0's and now flag
code that predates this PR.
## These are not our edits
None of the 5 flagged declarations is changed by this bump:
- Physlib/Relativity/Tensors/LeviCivita/Basic.lean (untouched file)
- Physlib/Relativity/.../Vector/Causality/LightLike.lean (untouched file)
- Physlib/SpaceAndTime/Space/Integrals/Basic.lean (untouched file)
- Physlib/StatisticalMechanics/CanonicalEnsemble/Basic.lean (untouched file)
- Physlib/Particles/.../SU5/ChargeSpectrum/Basic.lean (this PR only
edits `subset_trans` at L187; the flagged `min_exists_inductive` at L333
is unchanged)
## The 5 findings and the fix
1. checkType — `leviCivita_contract_self`: whnf on its tensor-notation
statement now exceeds the linter's 200k-heartbeat budget (v4.31.0 stayed
under it). Statement unchanged. → `@[nolint checkType]`.
2-5. unusedArguments — `min_exists_inductive` (`hn`),
`lightlike_spatial_parallel_implies_proportional` (`hv`, `hw`),
`integrable_spherical_of_integrable` (`NormedSpace ℝ F`),
`probability_nonneg` (`IsFiniteMeasure`, `NeZero`): each argument is part
of the intended interface / goal statement but unused by the proof term.
→ `@[nolint unusedArguments]` (matching 17 existing uses in the tree).
Consistent with this PR's charter (a toolchain bump: no lemma/definition
statement or signature is added, removed, or changed), these are *silenced*,
not restructured. Dropping the now-"unused" binders would alter public
signatures and risk downstream breakage; that is out of scope for a bump.
## Why local `lake exe lint_all` did not catch it
`scripts/lint_all.lean`'s `main` ends in an unconditional `pure 0` — it prints
linter output but never sets a non-zero exit code, so it cannot gate a PR. CI
does not use it; it invokes `lake exe runPhyslibLinters` directly, which *does*
exit 1 on findings. Reproduce the CI gate locally with:
env LEAN_ABORT_ON_PANIC=1 lake exe runPhyslibLinters Physlib
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address the parametric-basis API requested in leanprover-community#1441. `Dimension` gains a basis parameter `B`; PhysLib's current charge-based five-generator basis is recovered as `Dimension PhyslibBase`, whose named projections and `@[simp]` lemmas are preserved so all existing results build unchanged. Dimension core (generic in `B`): - `structure Dimension (B)`, with `CommGroup` and `ℚ`-power for every `B`; - `DecidableEq (Dimension B)` for finite `B`; - generic base vectors `Dimension.single b` (with `L𝓭 = single .length`, …); - change of basis `Dimension.extend` along an embedding `B ↪ B'`. Unit twin (generic in `B`) — the second hardwired copy leanprover-community#1441 flags: - `UnitScale B` (a positive-real magnitude per base) and `UnitScale.dimScale : UnitScale B → UnitScale B → Dimension B →* ℝ≥0`, the fold `d ↦ ∏ b, (u₁ b / u₂ b) ^ d.exponent b`; - `UnitChoices.toScale` exhibits the current five-field `UnitChoices` as the `PhyslibBase` instance. Worked instantiations (`Physlib/Units/BasisExamples.lean`): the ISQ seven base quantities (current-based, with amount of substance and luminous intensity), Gaussian–CGS (charge derived `M^(1/2)·L^(3/2)·T^(-1)`), natural units (`c = ħ = 1`), and an angle-augmented basis (`sr = rad²`). `WithDim` is parametric over the basis, and `WithDim.cast` resolves the comparison of propositionally-equal dimensions (see `Physlib/Units/ParametricDimensionExamples.lean`). Co-authored-by: Claude Opus 4.8 <no-reply+claude-opus-4-8@anthropic.com>
b07d0f0 to
8d8ab24
Compare
|
-awaiting-author Separate from the toolchain fix — a naming question raised in review. It came to me by email and I couldn't find it in the PR comments, so I'm recording it here for visibility:
For context: this is I named it after its provenance rather than generically because this basis is a specific, deliberate choice, not a neutral or canonical one. It is charge-based with five generators, so it is not the SI/ISQ base-quantity set (which takes electric current as base and adds amount of substance and luminous intensity); ISQ, Gaussian–CGS, natural units, and the angle-augmented system are other instantiations of The previous unparameterised That said, I'm very open to renaming it. My one constraint is that the name should still signal "a specific, non-ISQ choice of base quantities" rather than implying a canonical basis. If there's a preferred convention — or a good descriptive name for this charge-based, five-generator set — I'll gladly adopt it. Suggestions welcome. |
|
Thanks @nateabr for the retitle (and the Stacked on #1445 note — that's the right base). Want to confirm scope before I build anything further, since "and its unit twin" could mean two things. What's in the PR today is additive: The existing five-field The open question is whether you also want to parameterise A — Keep the bridge (status quo).
B — Consolidate the proofs, keep the API.Leave the
C — Make
|
Closes #1441 — makes
Dimension's base-dimension set parametric, and moves the unit-side twin (UnitChoices/dimScale) with it, as the issue requires.Thanks to Daniel Morrison for a very useful and constructive design discussion on the Physlib Zulip that shaped this.
This builds on #1445 (the v4.32.0 bump); the substantive change is the final commit,
feat(Units): parameterise Dimension and its unit twin over a basis.Requirements coverage (from the issue)
Already satisfied — preserved by the generic API
exponent : B → ℚ,Pow (Dimension B) ℚinstance : CommGroup (Dimension B)for everyB@[ext] Dimension.extCore — parametrise the generating set
Dimensionparametric in a basisB—structure Dimension (B)CommGroup/ℚ-power derived generically for everyBDecidableEq (Dimension B)for finiteB—instance [Fintype B] : DecidableEq (Dimension B)b : B—Dimension.single b, withL𝓭 = single .length, … (*_eq_single)dimScalefolds overB—UnitScale BandUnitScale.dimScale : UnitScale B → UnitScale B → Dimension B →* ℝ≥0(d ↦ ∏ b, (u₁ b / u₂ b) ^ d.exponent b);UnitChoices.toScaleexhibits the current five-fieldUnitChoicesas thePhyslibBaseinstanceBackward compatibility
Dimension PhyslibBaseoverPhyslibBase = {length, time, mass, charge, temperature}(neutrally named; charge-based, i.e. not the SI/ISQ set).length, …) and@[simp]lemmas preserved — every existingUnits/result builds unchanged (full build: 9238 jobs)Coverage — the motivating quantity systems (
Physlib/Units/BasisExamples.lean)M^(1/2)·L^(3/2)·T^(-1)c = ħ = 1, a single generator (length = time =mass⁻¹)sr = rad²)Optional / stretch
B ↪ B'—Dimension.extend(exponent-preserving on an embedding), with aPhyslibBase ↪angle-augmented demoDesign decisions on the issue's open questions
B → ℚvsB →₀ ℚ— total function (structure Dimension (B) where exponent : B → ℚ);Fintype Bis required only where a fold is taken (dimScale,DecidableEq). This keeps the dimension-comparison cast (below) ergonomic.Dimension; the current type is recovered asDimension PhyslibBasewith the projections re-exposed (the issue's "thin wrapper" path), so nothing downstream changes.PhyslibBase) for theHasDim/CarriesDimensioncarrier layer, with parametricity available to separate developments and to the other bases above. (So the unit-scaling carrier still shares one basis; per-type mixed bases are not introduced.)c = ħ = 1) — modelled by choosing a smaller basis and deriving the rest (seeNatural), the first option the issue lists.Dimension comparison
WithDimis parametric over the basis. A quantity of dimensionlengthand a product of quantities of dimensionlength/timeandtimehave propositionally but not definitionally equal dimensions (rflanddecideboth fail — the equality is group cancellation over ℚ exponents).WithDim.castbridges the two types, discharging the equality automatically; seePhyslib/Units/ParametricDimensionExamples.lean.Checks
lake build(Physlib + QuantumInfo): 9238 jobs, 0 errors / 0 warnings / 0sorry.lint-style.pyandlake exe lint_allclean on all changed files. No new axioms beyondpropext/Classical.choice/Quot.sound; nosorryAx.AI-assisted per the repository's AI policy; commits carry the
Co-authored-bytrailer.