feat(Units): add analytic structures and transport for WithDim - #1630
jstoobysmith merged 2 commits into
Conversation
AI-assisted implementation using ChatGPT.
|
t-units |
|
Thank you for this pull-request (PR). If this is your first PR, welcome to the community! Below is what will happen next. Please read carefully if you are not familiar with the process. You may open other PRs while this one is being reviewed, and can stack PRs on top of each other, so don't let these steps slow you down.
Tip: The easiest way to get have a fast review is to submit a PR that is small and self-contained, and has clear documentation explaining why things are the way they are in your chages. If you have any problems or questions, please reach out to the community on the Zulip. |
| /-- The coordinate time derivative is the existing oscillator theorem, not a new energy proof. -/ | ||
| lemma potentialEnergyWithDim_deriv_val (S : HarmonicOscillator) | ||
| (x : Time → WithDim L𝓭 (EuclideanSpace ℝ (Fin 1))) (hx : ContDiff ℝ ∞ x) : | ||
| ∂ₜ (fun t => (S.potentialEnergyWithDim (x t)).val) = |
There was a problem hiding this comment.
Do you need the .val here?
| -/ | ||
|
|
||
| /-- The existing potential energy with length input and energy output tags, in fixed units. -/ | ||
| noncomputable def potentialEnergyWithDim (S : HarmonicOscillator) : |
There was a problem hiding this comment.
Maybe we need a HarmonicOscillatorWithDim? then we could prove (I think) that the dimensions of this expression actually work! Which would be nice.
There was a problem hiding this comment.
I implemented this direction. The revised example now has a HarmonicOscillatorWithDim with dimension-tagged mass and spring constant, and the potential energy is constructed from those tagged quantities so that the energy dimension is checked by the type of the expression. I also added an explicit map back to the existing numerical HarmonicOscillator and proved that the potential energies agree in coordinates.
|
awaiting-author |
AI-assisted implementation using ChatGPT.
|
-awaiting-author |
|
Yes — I removed that coordinate-only derivative lemma rather than keeping the .val projection. The revised example now works directly with the dimension-tagged potential energy and uses HasFDerivAt on the tagged spaces. |
jstoobysmith
left a comment
There was a problem hiding this comment.
Approved. Will merge shortly
Summary
Refs #1628.
This PR adds an analytic foundation for
WithDimand applies it to a harmonic-oscillator example.WithDim d Mgains a real-module structure, induced normed-space structures, explicit coordinate equivalences, and generic transport operations for functions and Fréchet derivatives.Following review, the harmonic-oscillator example now uses a separate
HarmonicOscillatorWithDimwhose physical parameters themselves carry dimensions. The potential energy is assembled from dimension-tagged quantities, so its energy dimension is checked by the type of the expression. An explicit map back to the existing numericalHarmonicOscillatorshows that the tagged expression agrees with the existing potential-energy definition in coordinates.Scope
The norm and coordinate isometry remain tied to a fixed numerical unit representation; no claim is made that the norm is invariant under unit changes.
The derivative is still an ordinary continuous linear map between tagged coordinate spaces. A derivative value carrying the quotient of output and input dimensions remains follow-up work.
No fixed-dimension
RingorField, implicit coercion that discards tags, or unit-system redesign is introduced.Declarations
Physlib/Units/WithDim/Basic.leanWithDim.instModuleReal— real scalars act on tagged numerical values.WithDim.real_smul_val— projection of real scalar multiplication.Physlib/Units/WithDim/Analysis.leanWithDim.toValueAddEquivWithDim.toValueLinearEquivWithDim.instNormedAddCommGroupWithDim.instNormedSpaceWithDim.norm_eqWithDim.toValueLinearIsometryEquivWithDim.toValueLinearIsometryEquiv_applyWithDim.toValueLinearIsometryEquiv_symm_applyWithDim.transportWithDim.transport_valWithDim.transportLinearMapWithDim.transportLinearMap_valWithDim.hasFDerivAt_transportThese form the fixed-coordinate analytic layer and reuse Mathlib's continuous-linear-equivalence calculus.
Physlib/ClassicalMechanics/HarmonicOscillator/WithDim.leanHarmonicOscillatorWithDim— harmonic-oscillator parameters with physical dimensions.HarmonicOscillatorWithDim.toHarmonicOscillator— forget the tags and recover the existing numerical model.HarmonicOscillatorWithDim.positionNormSq/positionNormSq_val— squared position norm with dimensionL².HarmonicOscillatorWithDim.potentialEnergy— dimension-tagged1/2 k x²; its output type enforces the energy dimension.HarmonicOscillatorWithDim.potentialEnergy_val— coordinate agreement with the existing numerical potential energy.HarmonicOscillatorWithDim.potentialEnergy_eq_transport— identifies the typed expression with explicit transport of the existing function.HarmonicOscillatorWithDim.hasFDerivAt_potentialEnergy— reuses the generic derivative transport API.HarmonicOscillatorWithDim.continuous_potentialEnergy— continuity of the tagged potential energy.The earlier coordinate-only time-derivative lemma ending in
.valhas been removed rather than weakened.Existing example and registration
Physlib/Units/Examples.lean: the statement ofUnitExamples.energyMass_isDimensionallyCorrectis unchanged; its proof reuses the existing dimensional-correctness API.Physlib.lean: imports the two new modules.Physlib/Units/API-map.yaml: records the analytic layer and the dimension-checked harmonic-oscillator example.Validation
Passed locally with Lean 4.33.0:
git diff --checkPhyslib/ClassicalMechanics/HarmonicOscillator/WithDim.leanpython3 scripts/api_map_linter.py --repo .lake build -KCI Physlib.ClassicalMechanics.HarmonicOscillator.WithDimlake build -KCI(9359 jobs)lake exe check_file_importslake exe check_dup_tagslake exe sorry_lintlake exe runPhyslibLintersThe reviewed shared declarations inspected in the smoke test contain neither
sorryAxnorLean.ofReduceBool.Remote CI must validate the pushed review revision.
Reviewer map
Physlib/Units/WithDim/Basic.leanandPhyslib/Units/WithDim/Analysis.leanfor the general analytic layer.Physlib/ClassicalMechanics/HarmonicOscillator/WithDim.lean, especiallyHarmonicOscillatorWithDim.potentialEnergy, to see the dimension-checked physical example and its bridge to the existing model.Physlib/Units/Examples.leanfor the proof-only regression change.Physlib/Units/API-map.yamlandPhyslib.leanfor registration.AI-assisted implementation and PR description using ChatGPT.