Fix all Lean build warnings

- Update deprecated lemmas (ite_eq_left/right, ENat casts, List.Sublist, ...)
- Replace push_neg with push Not and resolve unused-variable warnings
- Convert flexible simp/simp_all calls to explicit simp only lists
- Remove unscoped maxHeartbeats options, open scoped Classical, and unused tactics
- Add missing module docstrings and clean up style linter hits
- Wrap over-long lines and flatten the deeply nested
  minimal_conflictRangeClosedForm_total proof

`lake build` now completes with zero warnings.
This commit is contained in:
andrew committed 2026-11-17 10:04:35 -05:00
1 parent a54a5f82f8
commit af318a7d32
51 files changed
+2542 -1357

No files matched your search

+44 -45
View File
@@ -29,7 +29,6 @@ soundness. Necessity inside `[K, begin.key)` is shown by inserting one more gap
namespace FormalConflictRange
open scoped Classical
variable {db db₁ db₂ : DB} {r : RangeRead} {res : Result}
@@ -38,8 +37,8 @@ resolution is either the empty key or the reported head. -/
theorem clamp_begin_resolve_bot_or_head
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
(hmore : res.more = false) (hne : res.keys ≠ [])
(hbegin : r.begin.offset < 0)
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key) :
(_hbegin : r.begin.offset < 0)
(_hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key) :
resolve db r.begin = (([] : Key) : WithTop Key) ∨
resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key) := by
set H : Key := res.keys.headD ([] : Key) with hH
@@ -59,7 +58,8 @@ theorem clamp_begin_resolve_bot_or_head
by_cases hneg : r.begin.anchor db < 0
· left; exact resolve_eq_nil hneg
· have h0 : 0 ≤ r.begin.anchor db := le_of_not_gt hneg
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hnil | htop | ⟨k, hkdb, hresk⟩
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hnil | htop | ⟨k, hkdb,
hresk⟩
· left; exact hnil
· rw [htop] at hHin
exact absurd hHin.2.1 (not_le.mpr (WithTop.coe_lt_top H))
@@ -226,7 +226,7 @@ theorem clampHigh_thresh_gt_facts
exact ⟨le_of_lt hlt', Or.inl hlt'⟩
/-- Every reported key lies strictly below `keyAfter (last reported)`. -/
theorem clampHigh_reported_lt_keyAfter {r : RangeRead} {res : Result}
theorem clampHigh_reported_lt_keyAfter {_r : RangeRead} {res : Result}
(hsort : res.keys.SortedLT) (hne : res.keys ≠ []) :
∀ k ∈ res.keys, ((k : Key) : WithTop Key) <
((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key) := by
@@ -286,7 +286,7 @@ theorem clamp_keys_HK_eq {db : DB} {r : RangeRead} {res : Result}
rw [hH, headD_eq_head_of_ne hne]
exact head_le_of_sortedLT' hsort hne hk)
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) :=
clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
exact ⟨hkdb, by rw [decide_eq_true_eq]; exact ⟨hHle, hkK⟩⟩
/-- No stored key lies in `[keyAfter last, resolve end)` in the crossed negative-begin
@@ -371,7 +371,7 @@ theorem clamp_cnt_begin_split {db : DB} {r : RangeRead} {res : Result}
/-- If the begin resolution is the reported head, the begin count below `begin.key`
equals the count below the head plus the slack plus one. -/
theorem clamp_anchor_eq_cnt_head_of_resolve {db : DB} {r : RangeRead} {res : Result}
(hbegin : r.begin.offset < 0) (hne : res.keys ≠ [])
(hbegin : r.begin.offset < 0) (_hne : res.keys ≠ [])
(hHne : res.keys.headD ([] : Key) ≠ [])
(hhead : resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
cnt db r.begin.key = cnt db (((res.keys.headD ([] : Key) : Key) : WithTop Key)) +
@@ -411,7 +411,7 @@ theorem clamp_anchor_eq_cnt_head_of_resolve {db : DB} {r : RangeRead} {res : Res
the reported head: that would require at least `clampHighC` gap keys, hence capacity at
least the threshold. -/
theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
(hread : Readable r res) (hcomp : RangeRead.Compatible db r res)
(_hread : Readable r res) (hcomp : RangeRead.Compatible db r res)
(hcell : negCrossCompleteHighClampFinite r res)
(hnotcap : ¬ ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res))
(hEbot : r.end_.key ≠ (([] : Key) : WithTop Key)) :
@@ -465,7 +465,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
have hCpos := clampHigh_C_pos (r := r) (res := res) hclamp
omega
· -- `K < B`: `t + gap = q + 1`, so `cap ≥ C`
push_neg at hBK
push Not at hBK
have hKleB : ((K : Key) : WithTop Key) ≤ r.begin.key := le_of_lt hBK
have hsplit := clamp_cnt_begin_split hcomp hrev hmore hne hcrossD (by rw [← hK]; exact hKleB)
have hrb : reportedBelowBegin r res = res.keys.length := by
@@ -474,7 +474,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
intro k hk
rw [decide_eq_true_eq]
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) := by
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
exact lt_trans hkK hBK
have hgap : (between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key))
r.begin.key).length = clampHighC r res := by
@@ -497,7 +497,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
-- `thresh = C` since `E ≠ ⊥`
have hth : clampHighThresh r res = clampHighC r res := by
unfold clampHighThresh
rw [if_neg hEbot]
rw [ite_eq_right hEbot]
exact Nat.add_zero _
apply hnotcap
rw [hth]
@@ -573,7 +573,8 @@ theorem clampHigh_K_filter_of_compatible {db : DB} {r : RangeRead} {res : Result
(by rw [← hH]; exact hcrossD) with hab | hah
· exact hab
· exact absurd hah
(clampHigh_begin_resolve_ne_head hread hcomp hcell hnotcap (by rw [← hE]; exact hEbot))
(clampHigh_begin_resolve_ne_head hread hcomp hcell hnotcap (by rw [← hE]; exact
hEbot))
-- with `a = ⊥`, `k` lies in the window
have hxwin : k ∈ between db (resolve db r.begin) (resolve db r.end_) := by
rw [between, List.mem_filter]
@@ -590,7 +591,7 @@ theorem clampHigh_K_filter_of_compatible {db : DB} {r : RangeRead} {res : Result
rw [List.mem_filter]
exact ⟨RangeRead.compatible_keys_subset hcomp hk,
by rw [decide_eq_true_eq]
exact clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk⟩
exact clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk⟩
/-- Filtering at `⊥` is the same as dropping the lower-bound conjunct. -/
theorem clampHigh_filter_bot_eq (db : DB) (U : WithTop Key) :
@@ -631,7 +632,7 @@ exactly the reported keys. -/
theorem clampHigh_between_head_keyAfter_of_filter {db : DB} {res : Result} {H K : Key}
(hsort : res.keys.SortedLT) (hne : res.keys ≠ [])
(hH : H = res.keys.headD ([] : Key))
(hHltK : ((H : Key) : WithTop Key) < ((K : Key) : WithTop Key))
(_hHltK : ((H : Key) : WithTop Key) < ((K : Key) : WithTop Key))
(hfilter : db.keys.filter (fun k : Key => decide
(((k : Key) : WithTop Key) < ((K : Key) : WithTop Key))) = res.keys) :
between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key) = res.keys := by
@@ -725,7 +726,7 @@ theorem clampHigh_cnt_begin_le_of_filter {db : DB} {r : RangeRead} {res : Result
rw [hsplit, hcntH, hlen]; omega
omega
· -- `keyAfter last < begin.key`: the gap keys plus the reported keys.
push_neg at hBK
push Not at hBK
have hKleB : ((K : Key) : WithTop Key) ≤ r.begin.key := le_of_lt hBK
have hcntK : cnt db ((K : Key) : WithTop Key) = res.keys.length := by
rw [cnt_eq_add_between db (le_of_lt hHltK), hcntH, hbetweenHK]
@@ -739,7 +740,7 @@ theorem clampHigh_cnt_begin_le_of_filter {db : DB} {r : RangeRead} {res : Result
intro k hk
rw [decide_eq_true_eq]
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) := by
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
exact lt_trans hkK hBK
have hcapC : (between db ((K : Key) : WithTop Key) r.begin.key).length ≤
clampHighC r res := by
@@ -942,7 +943,7 @@ theorem minimal_clampHigh_K {r : RangeRead} {res : Result}
(hnotcap : ¬ ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res)) :
Minimal r res ⟨(([] : Key) : WithTop Key),
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key))⟩ :=
minimal_of_compatible_iff_filter hread (fun db =>
minimal_of_compatible_iff_filter hread (fun _db =>
clampHigh_K_compatible_iff_filter hread hcell hnotcap)
/-- A database splits into its keys below a threshold and those at or above it. -/
@@ -961,7 +962,7 @@ theorem clampHigh_K_lt_begin {r : RangeRead} {res : Result}
(hcap : ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res)) :
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) < r.begin.key := by
by_contra hcon
push_neg at hcon
push Not at hcon
have hzero : clampHighCap r res = 0 := by
unfold clampHighCap
exact intervalCard_eq_zero_of_le hcon
@@ -991,7 +992,6 @@ theorem clampHigh_reported_lt_begin {r : RangeRead} {res : Result}
section BeginKeyBranch
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1089,7 +1089,7 @@ theorem clampHigh_B_head_pad_lt_end
rw [List.mem_filter] at hx
have hxH : ((x : Key) : WithTop Key) < ((H : Key) : WithTop Key) := of_decide_eq_true hx.2
by_contra hcon
push_neg at hcon
push Not at hcon
have hcntsplit := cnt_eq_add_between db (le_of_lt hEH)
rw [← hcH, ← hcE, hceq] at hcntsplit
have hlen0 : (between db r.end_.key ((H : Key) : WithTop Key)).length = 0 := by
@@ -1105,8 +1105,8 @@ theorem clampHigh_B_head_pad_lt_end
/-- In the `U = begin.key` branch, if the begin selector resolves to the empty key,
then at most `beginSlack + 1` stored keys lie below `begin.key`. -/
theorem clampHigh_B_bot_cnt_le {db : DB} {r : RangeRead} {res : Result}
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
(hmore : res.more = false) (hne : res.keys ≠ [])
(_hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
(_hmore : res.more = false) (_hne : res.keys ≠ [])
(hbegin : r.begin.offset < 0)
(hbot : resolve db r.begin = (([] : Key) : WithTop Key)) :
cnt db r.begin.key ≤ beginSlack r + 1 := by
@@ -1117,10 +1117,10 @@ theorem clampHigh_B_bot_cnt_le {db : DB} {r : RangeRead} {res : Result}
rfl
rw [hanchor] at hneg
omega
· push_neg at hneg
· push Not at hneg
have hlt : (r.begin.anchor db).toNat < db.keys.length := by
by_contra hcon
push_neg at hcon
push Not at hcon
rw [resolve_eq_top hneg hcon] at hbot
exact absurd hbot (by simp)
have hget : db.keys[(r.begin.anchor db).toNat] = ([] : Key) := by
@@ -1146,7 +1146,6 @@ end BeginKeyBranch
section BeginKeyDecomp
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1154,8 +1153,8 @@ variable {db : DB} {r : RangeRead} {res : Result}
negative-begin complete high cell, the number of stored keys below `begin.key` is the
number below the head plus `beginSlack + 1`. -/
theorem clampHigh_B_head_cnt_begin
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
(hmore : res.more = false) (hne : res.keys ≠ [])
(_hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
(_hmore : res.more = false) (_hne : res.keys ≠ [])
(hbegin : r.begin.offset < 0)
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
(hhead : resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
@@ -1203,7 +1202,7 @@ stored keys split as a (possibly empty) pad below `end.key`, the reported keys,
`C` when the begin selector resolves onto the reported head, and the pad is empty with a
shorter gap when it clamps. -/
theorem clampHigh_B_decomp_of_compatible
(hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res)
(_hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res)
(hcap : ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res))
(hcomp : RangeRead.Compatible db r res) :
∃ pad gap rest : List Key,
@@ -1253,7 +1252,8 @@ theorem clampHigh_B_decomp_of_compatible
have hfB : db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
r.begin.key)) =
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
((H : Key) : WithTop Key))) ++ res.keys ++ between db ((K : Key) : WithTop Key) r.begin.key := by
((H : Key) : WithTop Key))) ++ res.keys ++ between db ((K : Key) : WithTop Key)
r.begin.key := by
rw [filter_lt_eq_filter_lt_append_between db.sorted (le_of_lt hKLB), hfK]
rfl
-- split the database into below and at-or-above `begin.key`
@@ -1341,7 +1341,7 @@ theorem clampHigh_B_decomp_of_compatible
rw [hq, hr]
rw [hC]
rw [hcBsplit] at hcnt
simp only [List.length_append, ht] at hcnt
simp only [ ht] at hcnt
omega
end BeginKeyDecomp
@@ -1394,7 +1394,6 @@ end BetweenTools
section BeginKeyConverse
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
/-- The `U = begin.key` branch, converse direction: a database whose keys below
@@ -1451,7 +1450,8 @@ theorem clampHigh_B_compatible_of_shape
have hres_sub : ∀ k ∈ res.keys, k ∈ db.keys := by
intro k hk
rw [hkeys]
exact List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inr hk)))))
exact List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inr
hk)))))
-- filters below `E` and `B`
have hfiltE : db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < E)) = pad := by
rw [hkeys, List.filter_append, List.filter_append, List.filter_append]
@@ -1573,8 +1573,7 @@ theorem clampHigh_B_compatible_of_shape
have hsub : gap.Sublist db.keys := by
rw [hkeys]
exact (List.sublist_append_left gap rest).trans
(by simpa [List.append_assoc] using
(List.sublist_append_right (pad ++ res.keys) (gap ++ rest)))
(by simp [List.append_assoc])
have hgapSorted : gap.SortedLT :=
List.sortedLT_iff_pairwise.mpr
(List.Pairwise.sublist hsub (List.sortedLT_iff_pairwise.mp db.sorted))
@@ -1643,7 +1642,8 @@ theorem clampHigh_B_compatible_of_shape
have hbetween : between db (resolve db r.begin) (resolve db r.end_) = res.keys := by
rw [haresolve]
have hbot : between db (([] : Key) : WithTop Key) (resolve db r.end_) =
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_))
:= by
unfold between
apply List.filter_congr
intro k _
@@ -1674,7 +1674,6 @@ end BeginKeyConverse
section BeginKeySound
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1715,7 +1714,6 @@ end BeginKeySound
section BeginKeyNecessary
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1775,7 +1773,6 @@ end BeginKeyNecessary
section BeginKeyNecessaryTools
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1784,28 +1781,29 @@ theorem clampHigh_thresh_of_ne_bot
(hE : r.end_.key ≠ (([] : Key) : WithTop Key)) :
clampHighThresh r res = clampHighC r res := by
unfold clampHighThresh
rw [if_neg hE]
rw [ite_eq_right hE]
exact Nat.add_zero _
theorem clampHigh_thresh_of_bot
(hE : r.end_.key = (([] : Key) : WithTop Key)) :
clampHighThresh r res = clampHighC r res + 1 := by
unfold clampHighThresh
rw [if_pos hE]
rw [ite_eq_left hE]
/-- Away from the gap, a key above the last reported key is at or above
`keyAfter (last reported)`. -/
theorem clampHigh_B_gap_of_not_le_last {k : Key}
(hkL : ¬ ((k : Key) : WithTop Key) ≤
((res.keys.getLastD ([] : Key) : Key) : WithTop Key)) :
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) ≤ ((k : Key) : WithTop Key) := by
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) ≤ ((k : Key) : WithTop Key)
:= by
exact le_of_not_gt (fun h => hkL (WithTop.coe_le_coe.mpr
((lt_keyAfter_iff (k := k) (l := res.keys.getLastD ([] : Key))).mp
(WithTop.coe_lt_coe.mp h))))
/-- The begin anchor of the reported-keys database is negative in the clamping branch. -/
theorem clampHigh_B_keys_anchor_neg {hsort : res.keys.SortedLT}
(hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res) :
(_hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res) :
r.begin.anchor (⟨res.keys, hsort⟩ : DB) < 0 := by
obtain ⟨hrev, hbegin, hmore, hne, hend, hcrossD, hEH⟩ := hcell.1
have hclamp := hcell.2.1
@@ -1819,7 +1817,6 @@ end BeginKeyNecessaryTools
section BeginKeyGapNecessary
open scoped Classical
variable {db : DB} {r : RangeRead} {res : Result}
@@ -1895,7 +1892,9 @@ theorem clampHigh_B_necessary_gap_bot {r : RangeRead} {res : Result} {k : Key}
· exact hkB
· rw [List.mem_append] at hx
rcases hx with hx | hx
· exact by simpa [hB] using clampHigh_reported_lt_begin (r := r) (res := res) hsort hne hcell hcap x hx
· have hlt :=
clampHigh_reported_lt_begin (r := r) (res := res) hsort hne hcell hcap x hx
simpa [hB] using hlt
· exact hJhi x hx
have hcnt1 : db1.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < B)) =
t + (C + 1) := by
@@ -2169,7 +2168,7 @@ theorem clampHigh_B_necessary_gap_ne_bot {r : RangeRead} {res : Result} {k : Key
List.countP_eq_length.mpr (by
intro x hx; rw [decide_eq_true_eq]; exact hGrange x hx)
rw [hall, hGlen]
rw [if_pos ⟨hkG, by rw [decide_eq_true_eq]; exact ⟨hkK, hkB⟩⟩]
rw [ite_eq_left ⟨hkG, by rw [decide_eq_true_eq]; exact ⟨hkK, hkB⟩⟩]
rw [hnil, hres, hG]
omega
have hcnt_decomp : (dbA.erase k).keys.countP (fun x : Key => decide