[lean-squad] feat(fv): BlockStats Lean implementation + computeMaxSpeedFromDistance informal spec#134
Merged
dsyme merged 1 commit intoMay 19, 2026
Conversation
…e informal spec
Task 2: informal spec for math::trajectory::computeMaxSpeedFromDistance (target 56).
- specs/computemaxspeed_informal.md: full pre/postconditions, kinematic
derivation of the quadratic formula, discriminant non-negativity, edge cases,
examples, and Lean modelling plan.
Task 4: Lean implementation and proofs for BlockStats<Type,M> (target 57).
- lean/FVSquad/BlockStats.lean: scalar Int model of the running-sum accumulator.
- 10 theorems, 0 sorry, lake build PASSED.
Theorems proved:
bsUpdate_count, bsUpdate_sum, bsUpdate_sumSq, bsUpdate_sumSq_nonneg,
bsUpdate_mono_count, bsReset_zero, bsFold_count, bsFold_sum,
bsFold_sumSq_nonneg, bsMean_single.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔬 Lean Squad — automated formal verification, run 137.
Summary
This PR completes two tasks:
Task 2 (Informal Spec):
computeMaxSpeedFromDistanceinformal specificationTask 4 (Implementation Extraction):
BlockStatsLean implementation model + 10 proved theoremsTask 2:
computeMaxSpeedFromDistanceInformal Spec (target 56)File:
formal-verification/specs/computemaxspeed_informal.mdDocuments the kinematic quadratic formula used by PX4's velocity smoother to compute the maximum initial approach speed for a braking manoeuvre:
b = 4a2/j,c = -2ad - vf2,result = max(0.5(-b + √(b2-4c)), vf)b2 - 4c ≥ 0whena, d ≥ 0)accel=0,dist=0, large distance), worked examplesReal.sqrtfrom MathlibTask 4:
BlockStatsLean Implementation + Proofs (target 57)File:
formal-verification/lean/FVSquad/BlockStats.leanScalar
Intmodel ofcontrol::BlockStats<Type,M>— the running-sum/sum-of-squares/count accumulator. Proves the fundamental correctness invariants:Theorems Proved (10, 0 sorry)
bsUpdate_countbsUpdate_sumuto running sumbsUpdate_sumSqu2to sum-of-squaresbsUpdate_sumSq_nonnegbsUpdate_mono_countbsReset_zerobsFold_countbsFold_sumbsFold_sumSq_nonnegbsMean_singleApproximations
The model specialises to
M=1(scalar) withIntarithmetic. Floating-point rounding, theBlockclass hierarchy, and dimension-genericVector<Type,M>operations are abstracted away.Verification Status
Files Changed
formal-verification/specs/computemaxspeed_informal.md— new informal spec (target 56 → phase 2)formal-verification/lean/FVSquad/BlockStats.lean— new Lean file (target 57 → phase 5)formal-verification/lean/FVSquad.lean— added import for BlockStats