[Lean Squad] feat(fv): Tasks 6+8 — CORRESPONDENCE.md complete (34 targets) + bin_at_angle tests (run 70)#67
Closed
github-actions[bot] wants to merge 5 commits intomainfrom
Conversation
…re+SqrtLinear fully proved (run 66) Tasks 5 (Proof Assistance) and 10 (Project Report). ## Sorry count: 12 → 6 All 6 remaining sorry are in WrapAngle.lean (floor arithmetic, requires Mathlib). ### Atmosphere.lean: 3 sorry → 0 sorry Proved three previously sorry-guarded theorems using only Lean 4 stdlib: 1. **`densityRat_anti_mono_temp`**: added private helper `rat_inv_lt_inv_of_lt` that proves inverse reversal for positive rationals from first principles (`Rat.mul_lt_mul_right` + `Rat.inv_mul_cancel`), then used `Rat.mul_lt_mul_of_pos_left` and `Rat.add_lt_add_right`. 2. **`tempAtAlt_lapse_rate`**: manual Rat algebra using `Rat.mul_add`, `Rat.mul_neg`, `Rat.neg_add`, `Rat.add_assoc`, `Rat.add_comm`, `Rat.add_neg_cancel`. 3. **`tempAtAlt_strict_anti`**: rewrote `kTempGrad = -(13/2000)`, then used `Rat.neg_mul`, `Rat.neg_lt_neg`, `Rat.mul_lt_mul_of_pos_left`, and `Rat.add_lt_add_left`. ### SqrtLinear.lean: 3 sorry → 0 sorry (3 axioms added) Added three explicit axioms for `sqrtBranch` (the opaque model for `Real.sqrt`): - `sqrtBranch_zero : sqrtBranch 0 = 0` (models `Real.sqrt_zero`) - `sqrtBranch_nonneg x h : 0 ≤ sqrtBranch x` (models `Real.sqrt_nonneg`) - `sqrtBranch_lt_one x h0 h1 : sqrtBranch x < 1` (models `Real.sqrt_lt_one`) The three theorems (`sqrtLinear_zero`, `sqrtLinear_sqrt_nonneg`, `sqrtLinear_sqrt_lt_one`) now use these axioms and are sorry-free. ### WrapAngle.lean: inner `(by sorry)` fixed in `wrapRat_zero` The condition proof of `-P < P` (given `hP : 0 < P`) is now a proper proof: `Rat.neg_lt_neg hP` gives `-P < 0`, then `Std.lt_trans h1 hP` closes the goal. The outer sorry in `wrapRat_zero` body remains (needs `wrapRat_in_range` with Mathlib floor). Total sorry declaration count in WrapAngle stays at 6. ### REPORT.md updated - Status: 349 theorems, 6 sorry, 25 files - File inventory updated for Atmosphere, SqrtLinear, Crc16Sig, BrakingDist - Run 66 timeline entry added - stdlib note updated to reflect no more Atmosphere/SqrtLinear sorry ## Verification > 🔄 Partial verification: `lake build` passed with Lean 4.29.0. 6 `sorry` remain > (all in `WrapAngle.lean`, floor arithmetic pending Mathlib). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… 0 sorry (run 67) Adds formal verification of ObstacleMath::get_bin_at_angle and get_offset_bin_index from src/lib/collision_prevention/ObstacleMath.cpp. ## New files - formal-verification/lean/FVSquad/GetBinAtAngle.lean (13 theorems, 0 sorry) - formal-verification/specs/get_bin_at_angle_informal.md ## Theorems proved (all 0 sorry) ### getBinI (integer model of get_bin_at_angle) 1. getBinI_range — result always in [0, n) 2. getBinI_zero — angle 0 maps to bin 0 3. getBinI_in_range — identity for inputs already in [0, n) 4. getBinI_periodic — periodic with period n (360°) 5. getBinI_periodic_k — periodic with period k*n 6. getBinI_idempotent — applying twice = once ### getOffsetBinI (integer model of get_offset_bin_index) 7. getOffsetBinI_range — result always in [0, n) 8. getOffsetBinI_zero_offset — zero offset is identity 9. getOffsetBinI_eq_getBinI_sub — KEY: offset = subtraction mod n 10. getOffsetBinI_periodic_offset — periodic in offset 11. getOffsetBinI_periodic_bin — periodic in bin 12. getOffsetBinI_self — self-offset = 0 (bin meets its own offset) 13. getOffsetBinI_inverse — round-trip: offset then add back = original ## Key result getOffsetBinI_eq_getBinI_sub proves that get_offset_bin_index is a pure rotation on the n-bin circle: result = (b - k_offset) mod n. Combined with getOffsetBinI_inverse, this formally verifies the invertibility of the sensor frame rotation operation. ## Verification lake build passed with Lean 4.29.0. 0 sorry in new file. 6 sorry remain in WrapAngle.lean (floor arithmetic, needs Mathlib — unchanged). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔬 Lean Squad — run 68 Task 2: Informal spec for get_lower_bound_angle - formal-verification/specs/get_lower_bound_angle_informal.md - Integer model using half-bin units avoids floating-point arithmetic - Full circle = 2n half-bin units, lower bound = (2*(b%n)+a-1) % (2n) Task 5: Lean 4 formal verification with 8 theorems proved, 0 sorry - formal-verification/lean/FVSquad/GetLowerBoundAngle.lean - getLowerBoundI_range: result in [0, 2n) - getLowerBoundI_periodic_bin: periodicity over bin index - getLowerBoundI_periodic_offset: periodicity over angle offset - getLowerBoundI_zero_zero: bin 0, offset 0 → 2n-1 - getLowerBoundI_consecutive: consecutive bins differ by 2 half-bin units - getLowerBoundI_centre_relation: lower bound + 1 ≡ bin centre (mod 2n) - getLowerBoundI_offset_shift: offset+2 advances lower bound by 2 - getLowerBoundI_zero_offset2: bin 0, offset 2 → 1 lake build: PASSED with Lean v4.29.0, 0 sorry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e tests (run 70) Task 6 (Correspondence Review): - Add dedicated sections for WrapBin, BrakingDist, SqrtLinear, GetBinAtAngle, GetLowerBoundAngle, CollisionPrevComposition - Update summary table with 11 new entries (total: 34 C++ targets) - Update Last Updated timestamp and run notes Task 8 (Implementation Correspondence Validation — Route B): - Create formal-verification/tests/bin_at_angle/check_correspondence.py - 334 test cases: wrap_bin, get_bin_at_angle (4 bin widths), periodicity, get_offset_bin_index — all 334 passing - Demonstrates wrap_bin latent bug (negative result for bin <= -n-1) - Create README.md documenting scope, approach, and bug finding Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot
added a commit
that referenced
this pull request
Apr 26, 2026
Resolved Basic.lean conflict by merging all imports from diverging branches. Manually applied CollisionPrevComposition.lean, Hysteresis.lean, CORRESPONDENCE.md, and tests/ from branches that could not auto-merge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 26, 2026
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 for
fsprojects/PX4-Autopilot.Overview
Two tasks completed in run 70:
CORRESPONDENCE.mdextended to cover all 28 Lean files (34 C++ targets). Six files that existed only in the summary table or not at all now have dedicated sections.get_bin_at_angle,get_offset_bin_index, andwrap_bin— 334 test cases, all passing.Task 6: Correspondence Review — 6 new sections
FVSquad/WrapBin.leanDocuments the two-model approach:
wrapBin(Euclidean — intended semantics, always ≥ 0) andwrapBinCpp(truncation — exact C++ match, may return negative). Confirms that the correspondence tests demonstrate the latent negative-index bug forbin ≤ -n-1.FVSquad/BrakingDist.leanDocuments
computeBrakingDistanceFromVelocityfromTrajMath.hpp:107. Level: exact (rational arithmetic, exact transcription). Notes 9 proved theorems including the safety-criticalbrakingDist_nonneg.FVSquad/SqrtLinear.leanDocuments the three-branch model. Negative and identity branches are exact; the sqrt branch uses an axiom (
sqrtBranch). Explains the impact: three theorems are proved using the axiom and would be unconditionally verified if Mathlib becomes available.FVSquad/GetBinAtAngle.leanDocuments
getBinIandgetOffsetBinIas abstraction (integer-aligned exact, float rounding abstracted). Notes: 334/334 Route B correspondence tests pass.FVSquad/GetLowerBoundAngle.leanDocuments
getLowerBoundIin half-bin units as abstraction (exact for integer-multiple offsets). Lists all 8 proved theorems.FVSquad/CollisionPrevComposition.leanDocuments 8 cross-module composition theorems as abstraction. Highlights
lowerBound_of_offsetBinas a system-level correctness property that cannot be verified by looking at either function in isolation.Task 8: Route B Correspondence Tests —
tests/bin_at_angle/check_correspondence.pyPython script simulating both the C++ implementation and the Lean integer model on the same inputs:
wrap_bin(normal cases)wrap_bin(bug cases,bin ≤ -n-1)get_bin_at_angle(10° bins, n=36)get_bin_at_angle(5° bins, n=72)get_bin_at_angle(45° bins, n=8)get_bin_at_angle(2° bins, n=180)get_offset_bin_indexThe tests confirm:
getBinI n k = k % n) exactly matches the C++ implementation for integer-aligned angles.wrap_binlatent bug is demonstrated:cpp_wrap_bin(-37, 36) = -1(negative!) vslean_wrapBin(36, -37) = 35(correct).README.mdDocuments the test scope, approach, bug demonstration, and how to run the tests.
🔬 This PR was created by Lean Squad, an automated formal verification agent. See workflow run.