Skip to content

[lean-squad] feat(fv): BlockStats Lean implementation + computeMaxSpeedFromDistance informal spec#134

Merged
dsyme merged 1 commit into
mainfrom
lean-squad/run-137-blockstats-impl-computemaxspeed-spec-d88d5cd352ff1c5a
May 19, 2026
Merged

[lean-squad] feat(fv): BlockStats Lean implementation + computeMaxSpeedFromDistance informal spec#134
dsyme merged 1 commit into
mainfrom
lean-squad/run-137-blockstats-impl-computemaxspeed-spec-d88d5cd352ff1c5a

Conversation

@github-actions
Copy link
Copy Markdown

🔬 Lean Squad — automated formal verification, run 137.

Summary

This PR completes two tasks:

Task 2 (Informal Spec): computeMaxSpeedFromDistance informal specification
Task 4 (Implementation Extraction): BlockStats Lean implementation model + 10 proved theorems


Task 2: computeMaxSpeedFromDistance Informal Spec (target 56)

File: formal-verification/specs/computemaxspeed_informal.md

Documents the kinematic quadratic formula used by PX4's velocity smoother to compute the maximum initial approach speed for a braking manoeuvre:

  • Full derivation of b = 4a2/j, c = -2ad - vf2, result = max(0.5(-b + √(b2-4c)), vf)
  • Discriminant non-negativity proof (b2 - 4c ≥ 0 when a, d ≥ 0)
  • Pre/postconditions, edge cases (accel=0, dist=0, large distance), worked examples
  • Lean modelling plan: structural properties (result ≥ final_speed, accel=0 case) are provable without sqrt; full correctness requires Real.sqrt from Mathlib

Task 4: BlockStats Lean Implementation + Proofs (target 57)

File: formal-verification/lean/FVSquad/BlockStats.lean

Scalar Int model of control::BlockStats<Type,M> — the running-sum/sum-of-squares/count accumulator. Proves the fundamental correctness invariants:

Theorems Proved (10, 0 sorry)

Theorem Description
bsUpdate_count Each update increments count by 1
bsUpdate_sum Each update adds u to running sum
bsUpdate_sumSq Each update adds u2 to sum-of-squares
bsUpdate_sumSq_nonneg sumSq ≥ 0 invariant under update
bsUpdate_mono_count Count strictly increases each update
bsReset_zero Reset returns the zero state
bsFold_count Count after fold = initial count + list length
bsFold_sum Sum after fold = initial sum + List.sum of inputs
bsFold_sumSq_nonneg sumSq ≥ 0 is inductive over any input list
bsMean_single Mean after one update from zero = that input

Approximations

The model specialises to M=1 (scalar) with Int arithmetic. Floating-point rounding, the Block class hierarchy, and dimension-generic Vector<Type,M> operations are abstracted away.


Verification Status

✅ Proofs verified: lake build passed with Lean 4.29.1. 0 sorry remain. Full build: 54 jobs completed successfully (784 theorems total across 53 files).


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

Generated by 📐 Lean Squad, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/lean-squad.md@c7d030cd6d4607b90d9ac3ffc8b24aff4f251632

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant