feat(Topology/Algebra/Order): regular grid helpers and piecewise linear interpolation#35753
feat(Topology/Algebra/Order): regular grid helpers and piecewise linear interpolation#35753Vilin97 wants to merge 18 commits intoleanprover-community:masterfrom
Conversation
Add four lemmas about regular grids `{[a + n * h, a + (n + 1) * h]}` with
step size `h > 0`, parameterized over a `Field K` with `FloorSemiring`:
- `Nat.floor_div_eq_of_mem_Ico`: `t ∈ Ico (a + n*h) (a + (n+1)*h) → ⌊(t-a)/h⌋₊ = n`
- `mem_Ico_Nat_floor_div`: `a ≤ t → t ∈ Ico (a + ⌊(t-a)/h⌋₊*h) ...`
- `locallyFinite_Icc_grid`: the grid `Icc (a+n*h) (a+(n+1)*h)` is locally finite
- `ContinuousOn.of_Icc_grid`: cell-wise continuity implies continuity on `Ici a`
These are used in the forward Euler convergence proof:
https://github.com/Vilin97/forward_euler
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Welcome new contributor!Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR. Thank you again for joining our community. |
PR summary 47ed25d3caImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ac46228 to
303151b
Compare
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
303151b to
cb4877a
Compare
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cb4877a to
6851566
Compare
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6851566 to
214758c
Compare
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds helper lemmas for working with regular grids and defines piecewise linear interpolation on such grids. It extends Topology/Algebra/Order/Floor.lean with four new theorems relating Nat.floor to membership in regular grid intervals, and introduces a new file Topology/Algebra/Order/PiecewiseLinear.lean containing definitions and lemmas for piecewise linear and piecewise constant interpolation.
Changes:
- Added grid-related helper lemmas to
Floor.leanthat characterize when points belong to regular grid intervals - Introduced
piecewiseLinearandpiecewiseConstfunctions with evaluation, continuity, and derivative results - Added new file to the module import list in
Mathlib.lean
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Mathlib/Topology/Algebra/Order/Floor.lean | Adds RegularGrid section with 4 theorems: Nat.floor_div_eq_of_mem_Ico, mem_Ico_Nat_floor_div, locallyFinite_Icc_grid, and ContinuousOn.of_Icc_grid |
| Mathlib/Topology/Algebra/Order/PiecewiseLinear.lean | New file defining piecewise linear/constant interpolation with 6 main theorems about evaluation, continuity, and derivatives |
| Mathlib.lean | Adds public import for the new PiecewiseLinear module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ar grids Add definitions and lemmas for piecewise linear and constant interpolation on regular grids with step size `h > 0`: - `piecewiseLinear`: piecewise linear interpolation of `y` with slopes `c` - `piecewiseConst`: piecewise constant function on grid cells - `piecewiseConst_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_apply_grid`: value at grid points - `piecewiseLinear_eq_on_Ico`: evaluation on grid cells - `piecewiseLinear_continuousOn`: continuity on `[a, ∞)` - `piecewiseLinear_hasDerivWithinAt`: right derivative is the piecewise constant slope Depends on leanprover-community#35753 (regular grid helpers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
214758c to
aa29e07
Compare
Define the forward Euler method for ODEs and prove convergence: - `ODE.EulerMethod.step`, `point`, `slope`: the Euler iteration - `ODE.EulerMethod.path`, `deriv`: piecewise linear/constant interpolation - `ODE.EulerMethod.dist_deriv_le`: local truncation error ≤ h*(L + K*M) - `ODE.EulerMethod.dist_path_le`: global error via Gronwall's inequality - `ODE.EulerMethod.tendsto_path`: convergence as h → 0⁺ The proof assumes v is K-Lipschitz in y, L-Lipschitz in t, and ‖v‖ ≤ M. Depends on leanprover-community#35753 and leanprover-community#35754. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Another high-level question: is it important to have regularly spaced grids, or do application also consider other grids? (I'm not a numerical analyst, but the answer will influence the PR!) If the latter, can you generalise your PR accordingly? |
|
@grunweg , good question! In my experience, regular grids are used 99.9% of the time. Many theorems in NA of ODEs are of the form "If |
…nterpolation Address review feedback on leanprover-community#35753: - Remove custom `Nat.floor_div_eq_iff_mem_Ico` from Floor.lean in favor of existing `toIcoDiv_eq_iff` / `sub_toIcoDiv_zsmul_mem_Ico` API - Switch from ℕ to ℤ indices, using `toIcoDiv` directly as the cell index function - Remove generic `cellOf`/`grid` abstraction; specialize `piecewiseLinear` to regular grids using `toIcoDiv` - Remove `piecewiseConst` (was just function composition) - FloorSemiring → FloorRing (gives Archimedean, enabling toIcoDiv) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Yan Yablonovskiy <yablonovskiy.yan@gmail.com>
|
Thank you, all. Claude and I
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@botbaki review |
j-loreaux
left a comment
There was a problem hiding this comment.
I understand that your motivation for this is numerical analysis, and I saw your response to @grunweg about regularity, but I would prefer if we did not require regularity here for two primary reasons:
- In some cases within numerical analysis, one does not require / need regular grids, and so this is an unnecessary assumption. Such unnecessary assumptions have a habit of coming back to bite you. Just imagine, someone wants irregular grids in the future, and they have to completely rework the definition of grids just to state their result.
- I would like to use
piecewiseLinearfor things other than numerical analysis (e.g., building piecewise linear functions for use with the continuous functional calculus), and in that case we will definitely not want them to be regular.
Co-authored-by: Jireh Loreaux <loreaujy@gmail.com>
Co-authored-by: Jireh Loreaux <loreaujy@gmail.com>
Co-authored-by: Jireh Loreaux <loreaujy@gmail.com>
Make API for piecewise linear interpolation on regular grids. I need these to for ODE time-stepping methods, like forward Euler, and later Runge–Kutta methods.
Follow-up PR: #35755 (forward Euler method convergence).
I don't know if these numerical analysis ODE-solving methods even belong in mathlib. If someone could advise me on it, I would appreciate it.
The initial proof was produced by Aristotle. The code was iteratively refined (factoring out lemmas, golfing, simplifying proofs) using Claude Code.