Skip to content

Commit cdfde63

Browse files
authored
feat: tree map toArray/keysArray lemmas (#12481)
This PR provides lemmas about `toArray` and `keysArray` on tree maps and tree sets that are analogous to the existing `toList` and `keys` lemmas.
1 parent 2e06fb5 commit cdfde63

File tree

11 files changed

+1666
-2
lines changed

11 files changed

+1666
-2
lines changed

src/Init/Data/Array/Basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ end List
148148

149149
namespace Array
150150

151+
@[simp, grind =] theorem getElem!_toList [Inhabited α] {xs : Array α} {i : Nat} : xs.toList[i]! = xs[i]! := by
152+
rw [List.getElem!_toArray]
153+
151154
theorem size_eq_length_toList {xs : Array α} : xs.size = xs.toList.length := rfl
152155

153156
/-! ### Externs -/

src/Init/Data/List/Lemmas.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,12 @@ theorem getElem_zero_eq_head {l : List α} (h : 0 < l.length) :
936936
| nil => simp at h
937937
| cons _ _ => simp
938938

939+
theorem head!_eq_getElem! [Inhabited α] {l : List α} : head! l = l[0]! := by
940+
cases l <;> rfl
941+
942+
theorem headD_eq_getD {l : List α} {fallback} : headD l fallback = l.getD 0 fallback := by
943+
cases l <;> rfl
944+
939945
theorem head_eq_iff_head?_eq_some {xs : List α} (h) : xs.head h = a ↔ xs.head? = some a := by
940946
cases xs with
941947
| nil => simp at h

src/Std/Data/DTreeMap/Internal/Lemmas.lean

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

src/Std/Data/DTreeMap/Internal/Model.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ theorem minKey?_eq_minEntry?_map_fst {l : Impl α β} : l.minKey? = l.minEntry?.
661661
theorem minKey_eq_minEntry_fst {l : Impl α β} {he} : l.minKey he = (l.minEntry he).fst := by
662662
induction l, he using minKey.induct_unfolding <;> simp only [minEntry] <;> trivial
663663

664-
theorem minKey!_eq_get!_minKey? [Inhabited α] {l : Impl α β} :
664+
theorem minKey!_eq_getElem!_minKey? [Inhabited α] {l : Impl α β} :
665665
l.minKey! = l.minKey?.get! := by
666666
induction l using minKey!.induct_unfolding <;> simp only [minKey?] <;> trivial
667667

src/Std/Data/DTreeMap/Internal/WF/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ theorem minKey_eq_minKey [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α] {l :
22962296
theorem minKey!_eq_minKey! [Ord α] [TransOrd α] [Inhabited α] [BEq α] [LawfulBEqOrd α]
22972297
{l : Impl α β} (hlo : l.Ordered) :
22982298
l.minKey! = List.minKey! l.toListModel := by
2299-
simp [Impl.minKey!_eq_get!_minKey?, List.minKey!_eq_get!_minKey?, minKey?_eq_minKey? hlo]
2299+
simp [Impl.minKey!_eq_getElem!_minKey?, List.minKey!_eq_get!_minKey?, minKey?_eq_minKey? hlo]
23002300

23012301
theorem minKeyD_eq_minKeyD [Ord α] [TransOrd α] [BEq α] [LawfulBEqOrd α] {l : Impl α β}
23022302
(hlo : l.Ordered) {fallback} :

0 commit comments

Comments
 (0)