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

+50 -38
View File
@@ -150,7 +150,8 @@ theorem high_witness_compatible_clamp_low {r : RangeRead} {res : Result}
have hdbkeys : db.keys = res.keys := rfl
have hgt : ∀ k ∈ res.keys, r.end_.key < ((k : Key) : WithTop Key) :=
high_reported_gt_end hsort hne hEH
have hcE : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key)) = 0 := by
have hcE : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key)) = 0
:= by
rw [hdbkeys, List.countP_eq_zero]
intro k hk
rw [decide_eq_true_eq]
@@ -184,7 +185,7 @@ theorem high_witness_compatible_clamp_low {r : RangeRead} {res : Result}
have hhi : resolve db r.end_ = (⊤ : WithTop Key) := resolve_eq_top hEi0 hlen
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
rw [RangeRead.completeKeys, hrev]
simp only [Bool.false_eq_true, if_false]
simp only [Bool.false_eq_true, ite_false]
rw [hlo, hhi]
exact (RangeRead.inRange_unbounded res.keys).symm
@@ -197,9 +198,9 @@ theorem countP_orderedInsert_begin {l : List Key} {B : WithTop Key} (hs : l.Sort
(if ((k : Key) : WithTop Key) < B then 1 else 0) := by
rw [orderedInsert_eq_insertIdx hs hk]
by_cases hkB : ((k : Key) : WithTop Key) < B
· rw [if_pos hkB]
· rw [ite_eq_left hkB]
exact countP_insertIdx_of_lt hs hkB
· rw [if_neg hkB]
· rw [ite_eq_right hkB]
exact countP_insertIdx (fun a : Key => decide (((a : Key) : WithTop Key) < B))
(l.countP (fun a => decide (a < k))) k (by simp [hkB])
@@ -299,7 +300,7 @@ is the full range.** -/
theorem minimal_fullRange_of_negCrossHigh_clamp_low {r : RangeRead} {res : Result}
(hread : Readable r res) (hrev : r.reverse = false) (hbegin : r.begin.offset < 0)
(hmore : res.more = false) (hne : res.keys ≠ [])
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
(_hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
(hclamp : reportedBelowBegin r res ≤ beginSlack r)
(hlow : res.keys.length < (r.end_.offset - 1).toNat) :
@@ -332,7 +333,6 @@ theorem minimal_closedForm_of_negCrossCompleteHigh_clampLow {r : RangeRead} {res
exact hmin
open scoped Classical
variable {r : RangeRead} {res : Result}
@@ -437,7 +437,7 @@ theorem high_length_le_end {r : RangeRead} {res : Result}
have hcnt_hi' : cnt db hi =
min (cnt db r.end_.key + (r.end_.offset - 1).toNat) db.keys.length := by
rw [hhi]
show db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
change db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
resolve db r.end_)) = min (cnt db r.end_.key + (r.end_.offset - 1).toNat)
db.keys.length
rw [countP_lt_resolve (db := db) (s := r.end_),
@@ -572,7 +572,8 @@ theorem high_between_end_head_eq_nil {db : DB} {r : RangeRead} {res : Result}
have hsplit := cnt_eq_add_between db (le_of_lt hEH)
rw [hcnt, between] at hsplit
have hlen : (db.keys.filter (fun k : Key => decide (r.end_.key ≤ ((k : Key) : WithTop Key) ∧
((k : Key) : WithTop Key) < ((res.keys.headD ([] : Key) : Key) : WithTop Key)))).length = 0 := by
((k : Key) : WithTop Key) < ((res.keys.headD ([] : Key) : Key) : WithTop Key)))).length = 0
:= by
omega
exact List.length_eq_zero_iff.mp hlen
@@ -592,12 +593,13 @@ above `keyAfter last`, no stored key lies in `[keyAfter last, begin.key)`. -/
theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Result}
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
(hmore : res.more = false) (hne : res.keys ≠ [])
(hbegin : r.begin.offset < 0) (hend : 2 ≤ r.end_.offset)
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
(hbegin : r.begin.offset < 0) (_hend : 2 ≤ r.end_.offset)
(_hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
(hnonclamp : beginSlack r < reportedBelowBegin r res)
(hKleB : ((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key) ≤ r.begin.key) :
between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) r.begin.key = [] := by
between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) r.begin.key = []
:= by
set H : Key := res.keys.headD ([] : Key) with hH
set L : Key := res.keys.getLastD ([] : Key) with hL
set K : Key := keyAfter L with hK
@@ -628,7 +630,8 @@ theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Resu
rw [WithTop.coe_le_coe]; exact le_trans hHleL (le_of_lt (keyAfter_self_lt L))
-- All reported keys below `begin.key` are stored in `[H, K)`.
have hsub : ∀ k ∈ res.keys.filter (fun k : Key =>
decide (((k : Key) : WithTop Key) < r.begin.key)), k ∈ between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key) := by
decide (((k : Key) : WithTop Key) < r.begin.key)), k ∈ between db ((H : Key) : WithTop Key)
((K : Key) : WithTop Key) := by
intro k hk
rw [List.mem_filter] at hk
have hkres := hk.1
@@ -641,7 +644,8 @@ theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Resu
exact List.mem_filter.mpr ⟨RangeRead.compatible_keys_subset hcomp hkres,
by rw [decide_eq_true_eq]; exact ⟨hkH, hkK⟩⟩
-- Hence `[H, K)` holds at least `beginSlack + 1` stored keys.
have hlenHK_ge : beginSlack r + 1 ≤ (between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key)).length := by
have hlenHK_ge : beginSlack r + 1 ≤ (between db ((H : Key) : WithTop Key) ((K : Key) : WithTop
Key)).length := by
have hfin : (res.keys.filter (fun k : Key =>
decide (((k : Key) : WithTop Key) < r.begin.key))).toFinset ⊆
(between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key)).toFinset := by
@@ -786,8 +790,8 @@ theorem filter_eq_filter_filter_of_imp {α : Type*} {l : List α} {p q : α →
apply List.filter_congr
intro a _
cases hp : p a with
| false => simp [hp]
| true => simp [hp, h a hp]
| false => simp []
| true => simp [ h a hp]
/-- Backward direction: in the crossed negative-begin complete high cell with a finite
end and a nonclamping begin, equality of the stored keys in `[end.key, M)` with the
@@ -899,7 +903,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
exact hr
have hhhead : res.keys.head hne ∈ db.keys := by rw [← hHhead]; exact hHmem_db
have hresB : resolve db r.begin = ((H : Key) : WithTop Key) := by
have hlenFilter' : (db.keys.filter (fun k : Key => decide (((res.keys.head hne : Key) : WithTop Key) ≤
have hlenFilter' : (db.keys.filter (fun k : Key => decide (((res.keys.head hne : Key) :
WithTop Key) ≤
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < r.begin.key))).length =
beginSlack r + 1 := by
simpa only [hHhead] using hlenFilter
@@ -930,7 +935,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
rw [hstep, hkeysHM]
have htake : (db.keys.drop (cnt db r.end_.key)).take (res.keys.length) = res.keys := by
have hsorted : (db.keys.drop (cnt db r.end_.key)).SortedLT :=
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key) db.sorted.pairwise)
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key)
db.sorted.pairwise)
have hcount : (db.keys.drop (cnt db r.end_.key)).countP (fun k : Key =>
decide (((k : Key) : WithTop Key) < M)) = res.keys.length := by
rw [List.countP_eq_length_filter, hfilterM]
@@ -984,7 +990,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
have hcountTake : (db.keys.take (cnt db r.end_.key)).countP (fun k : Key =>
decide (((k : Key) : WithTop Key) < resolve db r.end_)) = cnt db r.end_.key := by
rw [htakeE]
have hlen : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).countP
have hlen : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
r.end_.key))).countP
(fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) =
(db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).length :=
List.countP_eq_length.mpr (by
@@ -1003,7 +1010,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
omega
have hwindow : between db ((H : Key) : WithTop Key) (resolve db r.end_) = res.keys := by
have hsorted : (db.keys.drop (cnt db r.end_.key)).SortedLT :=
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key) db.sorted.pairwise)
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key)
db.sorted.pairwise)
have hstep : between db ((H : Key) : WithTop Key) (resolve db r.end_) =
(db.keys.drop (cnt db r.end_.key)).filter (fun k : Key =>
decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
@@ -1050,7 +1058,7 @@ theorem minimal_closedForm_of_negCrossCompleteHigh_nonclamp_finite {r : RangeRea
(hnonclamp : beginSlack r < reportedBelowBegin r res)
(hfinite : res.keys.length = (r.end_.offset - 1).toNat) :
Minimal r res ⟨r.end_.key, negCrossCompleteHighM r res⟩ :=
minimal_of_compatible_iff_filter hread (fun db =>
minimal_of_compatible_iff_filter hread (fun _db =>
high_nonclamp_finite_compatible_iff_filter hread hrev hmore hne hbegin hend hEH hcrossD
hnonclamp hfinite)
@@ -1172,7 +1180,8 @@ theorem high_nonclamp_low_aboveH_iff {db : DB} {r : RangeRead} {res : Result}
(hlow : res.keys.length < (r.end_.offset - 1).toNat)
(hno : ¬ (((r.end_.offset - 1).toNat - res.keys.length : ℕ) : ℕ∞) ≤
intervalCard r.end_.key ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
RangeRead.Compatible db r res ↔ above db ((res.keys.headD ([] : Key) : Key) : WithTop Key) = res.keys := by
RangeRead.Compatible db r res ↔ above db ((res.keys.headD ([] : Key) : Key) : WithTop Key) =
res.keys := by
set H : Key := res.keys.headD ([] : Key) with hH
set E : WithTop Key := r.end_.key with hE
set t : ℕ := res.keys.length with ht
@@ -1262,10 +1271,10 @@ theorem high_nonclamp_low_aboveH_iff {db : DB} {r : RangeRead} {res : Result}
rw [hanchor]; omega
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
rw [RangeRead.completeKeys, hrev]
simp only [Bool.false_eq_true, if_false]
simp only [Bool.false_eq_true, ite_false]
rw [hL, htop]
-- between H top = above H = res.keys
show res.keys = List.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
change res.keys = List.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < (⊤ : WithTop Key))) db.keys
exact haboveH.symm.trans (filter_le_top_eq_above_aux db ((H : Key) : WithTop Key)).symm
@@ -1298,7 +1307,7 @@ interval `[end_.key, begin.key)`, the begin resolution (negative offset). The c
window then starts at the reported head, which lies at or above `end_.key`, so it too is
fixed. -/
theorem sound_topRange_endKey_nonclamp_low {r : RangeRead} {res : Result}
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
(_hread : Readable 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))
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
@@ -1427,7 +1436,7 @@ theorem high_nonclamp_low_base_compatible {r : RangeRead} {res : Result}
have : (0 : ℤ) ≤ r.end_.offset - 1 := by omega
simpa using this
· rw [hanchor]
show res.keys.length ≤ e
change res.keys.length ≤ e
rw [← ht]
omega
have hbetween : between (⟨res.keys, hsort⟩ : DB) ((H : Key) : WithTop Key)
@@ -1442,7 +1451,7 @@ theorem high_nonclamp_low_base_compatible {r : RangeRead} {res : Result}
exact head_le_of_sortedLT' hsort hne hk)
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
rw [RangeRead.completeKeys, hrev]
simp only [Bool.false_eq_true, if_false]
simp only [Bool.false_eq_true, ite_false]
rw [hL, htop]
exact hbetween.symm
@@ -1714,7 +1723,8 @@ theorem necessary_gap_nonclamp_low_lt_cap {r : RangeRead} {res : Result} {k : Ke
simpa [Nat.cast_add, Nat.cast_one] using h
set H : Key := res.keys.headD ([] : Key) with hH
set E : WithTop Key := r.end_.key with hE
have hcap' : (((negCrossHighD r res + 1 : ℕ) : ℕ∞)) ≤ intervalCard E ((H : Key) : WithTop Key) := by
have hcap' : (((negCrossHighD r res + 1 : ℕ) : ℕ∞)) ≤ intervalCard E ((H : Key) : WithTop Key)
:= by
simpa [negCrossHighGapCap, hE, hH] using hcap
obtain ⟨dbPad, hdbPadIn, hkpad, hpadlen⟩ :=
exists_db_keysIn_avoid (B := E) (E := ((H : Key) : WithTop Key)) (k := k)
@@ -1733,7 +1743,7 @@ theorem necessary_gap_nonclamp_low_lt_cap {r : RangeRead} {res : Result} {k : Ke
rw [hdb0]
simp only
rw [List.mem_append]
push_neg
push Not
exact ⟨hkpad, hknot⟩
refine necessary_of_toggle ⟨db0, hcomp0, ?_⟩
rw [toggle_eq_insert_of_not_mem hknot0]
@@ -1941,7 +1951,8 @@ theorem high_nonclamp_low_tail_compatible {r : RangeRead} {res : Result}
rw [RangeRead.inRange, hRbeg, hRend]
rw [hkeys, List.filter_append, List.filter_append]
have hpadf : pad.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = [] := by
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = []
:= by
rw [List.filter_eq_nil_iff]
intro x hx
rw [decide_eq_true_eq]
@@ -1958,7 +1969,8 @@ theorem high_nonclamp_low_tail_compatible {r : RangeRead} {res : Result}
exact WithTop.coe_le_coe.mpr (head_le_of_sortedLT' hsort hne hx),
WithTop.coe_lt_coe.mpr (hys x hx)⟩
have hyf : [y].filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = [] := by
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = []
:= by
rw [List.filter_eq_nil_iff]
intro x hx
rw [List.mem_singleton] at hx
@@ -2060,13 +2072,13 @@ theorem necessary_gap_nonclamp_low_eq_cap {r : RangeRead} {res : Result} {k : Ke
have hLm : L ≤ m := by
rw [hm]
by_cases h : L ≤ b
· rw [if_pos h]; exact h
· rw [if_neg h]
· rw [ite_eq_left h]; exact h
· rw [ite_eq_right h]
have hbm : b ≤ m := by
rw [hm]
by_cases h : L ≤ b
· rw [if_pos h]
· rw [if_neg h]; exact le_of_lt (lt_of_not_ge h)
· rw [ite_eq_left h]
· rw [ite_eq_right h]; exact le_of_lt (lt_of_not_ge h)
set y : Key := keyAfter m with hy
have hLy : L < y := lt_of_le_of_lt hLm (by rw [hy]; exact keyAfter_self_lt m)
have hby : b < y := lt_of_le_of_lt hbm (by rw [hy]; exact keyAfter_self_lt m)
@@ -2092,7 +2104,7 @@ theorem necessary_gap_nonclamp_low_eq_cap {r : RangeRead} {res : Result} {k : Ke
have hks0 : db0.keys = pad ++ res.keys ++ [y] := rfl
have hkrest : k ∉ res.keys ++ [y] := by
rw [List.mem_append, List.mem_singleton]
push_neg
push Not
exact ⟨hknot, hk_ne_y⟩
have hpadErase : pad.erase k = padk := by
have h := DB.erase_insert_keys (⟨padk, hpadks⟩ : DB) k hkpadk
@@ -2377,9 +2389,9 @@ theorem high_nonclamp_low_aboveH_iff_top {db : DB} {r : RangeRead} {res : Result
exact hlenEnd
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
rw [RangeRead.completeKeys, hrev]
simp only [Bool.false_eq_true, if_false]
simp only [Bool.false_eq_true, ite_false]
rw [hL, htop]
show res.keys = between db ((H : Key) : WithTop Key) (⊤ : WithTop Key)
change res.keys = between db ((H : Key) : WithTop Key) (⊤ : WithTop Key)
rw [between_top_eq_above]
exact habove.symm
@@ -2387,7 +2399,7 @@ theorem high_nonclamp_low_aboveH_iff_top {db : DB} {r : RangeRead} {res : Result
crossed negative-begin complete high cell when `end.key` is the chosen lower endpoint. -/
theorem necessary_topRange_endKey_nonclamp_low {r : RangeRead} {res : Result} {k : Key}
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0) (hend : 2 ≤ r.end_.offset)
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0) (_hend : 2 ≤ r.end_.offset)
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
(hnonclamp : beginSlack r < reportedBelowBegin r res)