Skip to content

[Lean Squad] feat(formal-verification): math::lerp Lean spec + 9 proofs (run13)#18

Merged
dsyme merged 1 commit intomainfrom
lean-squad/lerp-spec-run13-f90bacca7d-95edc83e2df99886
Apr 6, 2026
Merged

[Lean Squad] feat(formal-verification): math::lerp Lean spec + 9 proofs (run13)#18
dsyme merged 1 commit intomainfrom
lean-squad/lerp-spec-run13-f90bacca7d-95edc83e2df99886

Conversation

@github-actions
Copy link
Copy Markdown

@github-actions github-actions Bot commented Apr 6, 2026

Summary

This PR adds a formal Lean 4 specification and proofs for PX4's math::lerp function from src/lib/mathlib/math/Functions.hpp.

🔬 Lean Squad automated formal verification (run13).


New files

  • formal-verification/specs/lerp_informal.md — informal specification covering purpose, preconditions, postconditions, edge cases, and open questions
  • formal-verification/lean/FVSquad/Lerp.lean — Lean 4 spec and proofs
  • formal-verification/TARGETS.md — updated to advance math::lerp to phase 5

C++ source

// src/lib/mathlib/math/Functions.hpp
template<typename T>
const T lerp(const T &a, const T &b, const T &s) {
    return (static_cast<T>(1) - s) * a + s * b;
}

Used throughout PX4 for flight-task setpoint blending, RC stick processing, and gain scheduling.


Theorems proved (9 proved, 1 sorry)

Theorem Property Status
lerp_zero lerp(a, b, 0) = a
lerp_one lerp(a, b, 1) = b
lerp_const lerp(a, a, s) = a
lerp_alt_form lerp(a,b,s) = a + s*(b-a)
lerp_lower s∈[0,1], a≤b ⊢ a ≤ lerp(a,b,s)
lerp_upper s∈[0,1], a≤b ⊢ lerp(a,b,s) ≤ b
lerp_in_range Combined range containment
lerp_comm lerp(a,b,s) = lerp(b,a,1-s)
lerp_mono_s Monotone non-decreasing in s when a≤b
lerp_half lerp(a,b,½) = (a+b)/2 🔄 sorry — 1/2 literal needs Rat.inv arithmetic

The no-overshoot safety property (lerp_in_range) is key for control systems: when s ∈ [0, 1] and a ≤ b, lerp stays strictly within [a, b], ruling out runaway setpoints.


Model

Over Rat (rational numbers); IEEE 754 NaN/infinity and integer truncation are excluded. No Mathlib dependency.


Verification status

🔄 Partial verification: lake build passed with Lean 4.29.0. 1 sorry remains (lerp_half).

Lean version: leanprover/lean4:v4.29.0
lake build: ✅ passed
Sorries: 1 (lerp_half — midpoint theorem, requires Rat.inv arithmetic for 1/2 literal)


Task 9 — CI audit

Reviewed .github/workflows/lean-ci.yml:

  • Toolchain pinned to lean-toolchain
  • Cache keyed on lake-manifest.json hash ✅
  • lake build with exit code propagation ✅
  • Upload artifacts on failure ✅

No changes needed. CI is healthy.

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

To install this agentic workflow, run

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

Add formal Lean 4 specification and proofs for PX4's math::lerp function
from src/lib/mathlib/math/Functions.hpp.

## New files
- formal-verification/specs/lerp_informal.md  — informal specification
- formal-verification/lean/FVSquad/Lerp.lean  — Lean spec + proofs

## Theorems proved (9/10, 1 sorry)
- lerp_zero     : lerp(a,b,0) = a
- lerp_one      : lerp(a,b,1) = b
- lerp_const    : lerp(a,a,s) = a  (for any s)
- lerp_alt_form : lerp(a,b,s) = a + s*(b-a)
- lerp_lower    : s∈[0,1], a≤b ⊢ a ≤ lerp(a,b,s)
- lerp_upper    : s∈[0,1], a≤b ⊢ lerp(a,b,s) ≤ b
- lerp_in_range : combined range containment (lower ∧ upper)
- lerp_comm     : lerp(a,b,s) = lerp(b,a,1-s)
- lerp_mono_s   : a≤b, s1≤s2 ⊢ lerp(a,b,s1) ≤ lerp(a,b,s2)
- lerp_half     : sorry — needs Rat.inv arithmetic for 1/2 literal

lake build passes. All proofs use Lean 4 stdlib only (no Mathlib).

## Task 9 CI audit
CI workflow (.github/workflows/lean-ci.yml) verified healthy: correct
toolchain pinning, cache key on lake-manifest.json, lake build step.
No changes needed.

🔬 Lean Squad automated formal verification (run13).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme merged commit 2aae128 into main Apr 6, 2026
github-actions Bot added a commit that referenced this pull request Apr 15, 2026
…, 0 sorry

Add formal verification of math::interpolateN (uniform-grid piecewise-linear
interpolation) for N=2 and N=3.

## New file: formal-verification/lean/FVSquad/InterpolateN.lean

14 public theorems, 0 sorry:

### N=2 (degenerate case — reduces to single interpolate call):
- interpN2_at_zero, interpN2_at_one: exact values at endpoints
- interpN2_le_high, interpN2_ge_low: range containment when y0 ≤ y1

### N=3 (two-segment model with breakpoint at 1/2):
- interpN3_at_zero, interpN3_at_half, interpN3_at_one: exact at all 3 nodes
- interpN3_continuity: both branch formulas agree at value=1/2
- interpN3_le_high, interpN3_ge_low, interpN3_in_range: output in [y0, y2]
- interpN3_mono_seg0, interpN3_mono_seg1: segment-wise monotonicity
- interpN3_const: constant output when all y equal

Also includes 15 concrete #eval examples verifying flat/linear/convex curves.

## New file: formal-verification/specs/interpolaten_informal.md
Informal specification: preconditions, postconditions, edge cases, examples.

## Updated: formal-verification/TARGETS.md
Added target #18 for interpolateN.

> ✅ Proofs verified: lake build passed with Lean 4.29.0. 0 sorry.

🔬 Lean Squad automated formal verification — run 40
(https://github.com/dsyme/PX4-Autopilot/actions/runs/24468137822)

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