Prove conflict-range closed-form minimality

- Vendor the FormalConflictRange reference library needed by the proof
- Add Bridge.lean with simp lemmas connecting the Statement definitions
  to the reference library
- Prove Statement.closedFormMinimal in Proof.lean
- Register the new libraries in the Lake config
This commit is contained in:
andrew committed 2026-11-16 21:53:59 -05:00
1 parent 7a0826e873
commit a54a5f82f8
78 files changed
+91636 -2

No files matched your search

@@ -0,0 +1,78 @@
/-
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: FormalConflictRange contributors
-/
import FormalConflictRange.NegCrossTruncRevBeginTop
/-!
# Reversed crossed negative-begin truncated cells in the nonpositive-begin regime
This module wires two already-total reversed truncated rules into the closed-form
dispatcher. Both concern a reversed truncated result at a nonpositive begin offset
whose begin key lies at or below the least reported key, so the lower cut never rises
above the reported block.
* If the end overshoots (`2 ≤ end_.offset`) and every reported key is below `end_.key`,
the resolved end is the sentinel in every compatible database and the minimal range
is `[last, ⊤)`.
* If the end has offset one, the cut is exactly at `end_.key` and the minimal range is
the reversed truncated range `[last, end_.key)`.
The minimality proofs are the corresponding total theorems of `Sound.lean`.
-/
namespace FormalConflictRange
/-- The nonpositive-begin reversed truncated overshoot cell: the begin key is at or
below the least reported key, the end overshoots, and every reported key lies below
`end_.key`. -/
abbrev negCrossTruncRevNonposOvershoot (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧ r.reverse = true ∧ r.begin.offset ≤ 0 ∧ res.keys ≠ [] ∧
2 ≤ r.end_.offset ∧
r.begin.key ≤ ((res.keys.getLastD ([] : Key) : Key) : WithTop Key) ∧
∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key
/-- The closed form of the nonpositive-begin reversed truncated overshoot cell. -/
noncomputable def closedFormNegCrossTruncRevNonposOvershoot (_r : RangeRead)
(res : Result) : ConflictRange :=
topOfLast (res.keys.getLastD ([] : Key))
/-- **The nonpositive-begin reversed truncated overshoot closed form is minimal.** -/
theorem minimal_closedForm_of_negCross_trunc_rev_nonposOvershoot {r : RangeRead}
{res : Result} (hread : Readable r res) (h : negCrossTruncRevNonposOvershoot r res) :
Minimal r res (closedFormNegCrossTruncRevNonposOvershoot r res) := by
obtain ⟨hmore, hrev, hle, hne, hend, hlo, hhi⟩ := h
have hlast : res.keys.getLastD ([] : Key) = res.keys.getLast hne := by
rw [List.getLastD_eq_getLast?, List.getLast?_eq_some_getLast hne]; rfl
unfold closedFormNegCrossTruncRevNonposOvershoot
rw [hlast]
exact minimal_topOfLast_of_end_offset_ge_two_rev_nonpos hread hmore hrev hne hle hend
(by rw [hlast] at hlo; exact hlo) hhi
/-- The nonpositive-begin reversed truncated under-end cell at end offset one: the
begin key is at or below the least reported key and the end has offset one. -/
abbrev negCrossTruncRevNonposUnder (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧ r.reverse = true ∧ r.begin.offset ≤ 0 ∧ res.keys ≠ [] ∧
r.end_.offset = 1 ∧
r.begin.key ≤ ((res.keys.getLastD ([] : Key) : Key) : WithTop Key)
/-- The closed form of the nonpositive-begin reversed truncated under-end cell. -/
noncomputable def closedFormNegCrossTruncRevNonposUnder (r : RangeRead) (res : Result) :
ConflictRange :=
truncatedRangeRev r (res.keys.getLastD ([] : Key))
/-- **The nonpositive-begin reversed truncated under-end closed form is minimal.** -/
theorem minimal_closedForm_of_negCross_trunc_rev_nonposUnder {r : RangeRead} {res : Result}
(hread : Readable r res) (h : negCrossTruncRevNonposUnder r res) :
Minimal r res (closedFormNegCrossTruncRevNonposUnder r res) := by
obtain ⟨hmore, hrev, hle, hne, hend, hlo⟩ := h
have hlast : res.keys.getLastD ([] : Key) = res.keys.getLast hne := by
rw [List.getLastD_eq_getLast?, List.getLast?_eq_some_getLast hne]; rfl
unfold closedFormNegCrossTruncRevNonposUnder
rw [hlast]
exact minimal_truncatedRangeRev_of_end_offset_one_nonpos hread hmore hrev hne hle hend
(by rw [hlast] at hlo; exact hlo)
end FormalConflictRange