Skip to content

Commit

Permalink
long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em committed Sep 10, 2024
1 parent 4dc6beb commit 41bb40b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
9 changes: 6 additions & 3 deletions Batteries/Data/Array/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ theorem forIn_eq_forIn_toList [Monad m]
theorem toList_zipWith (f : α → β → γ) (as : Array α) (bs : Array β) :
(as.zipWith bs f).toList = as.toList.zipWith f bs.toList := by
let rec loop : ∀ (i : Nat) cs, i ≤ as.size → i ≤ bs.size →
(zipWithAux f as bs i cs).toList = cs.toList ++ (as.toList.drop i).zipWith f (bs.toList.drop i) := by
(zipWithAux f as bs i cs).toList =
cs.toList ++ (as.toList.drop i).zipWith f (bs.toList.drop i) := by
intro i cs hia hib
unfold zipWithAux
by_cases h : i = as.size ∨ i = bs.size
Expand Down Expand Up @@ -67,7 +68,8 @@ theorem toList_zipWith (f : α → β → γ) (as : Array α) (bs : Array β) :
let i_bs : Fin bs.toList.length := ⟨i, hbs⟩
rw [h₁, List.append_assoc]
congr
rw [← List.zipWith_append (h := by simp), getElem_eq_toList_getElem, getElem_eq_toList_getElem]
rw [← List.zipWith_append (h := by simp), getElem_eq_toList_getElem,
getElem_eq_toList_getElem]
show List.zipWith f (as.toList[i_as] :: List.drop (i_as + 1) as.toList)
((List.get bs.toList i_bs) :: List.drop (i_bs + 1) bs.toList) =
List.zipWith f (List.drop i as.toList) (List.drop i bs.toList)
Expand Down Expand Up @@ -122,7 +124,8 @@ theorem mem_join : ∀ {L : Array (Array α)}, a ∈ L.join ↔ ∃ l, l ∈ L

/-! ### erase -/

@[simp] proof_wanted toList_erase [BEq α] {l : Array α} {a : α} : (l.erase a).toList = l.toList.erase a
@[simp] proof_wanted toList_erase [BEq α] {l : Array α} {a : α} :
(l.erase a).toList = l.toList.erase a

/-! ### shrink -/

Expand Down
3 changes: 2 additions & 1 deletion Batteries/Data/Array/Pairwise.lean
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ theorem pairwise_append {as bs : Array α} :
theorem pairwise_push {as : Array α} :
(as.push a).Pairwise R ↔ as.Pairwise R ∧ (∀ x ∈ as, R x a) := by
unfold Pairwise
simp [← mem_toList, push_toList, List.pairwise_append, List.pairwise_singleton, List.mem_singleton]
simp [← mem_toList, push_toList, List.pairwise_append, List.pairwise_singleton,
List.mem_singleton]

theorem pairwise_extract {as : Array α} (h : as.Pairwise R) (start stop) :
(as.extract start stop).Pairwise R := by
Expand Down
8 changes: 4 additions & 4 deletions Batteries/Data/HashMap/WF.lean
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ theorem WF.update [BEq α] [Hashable α] {buckets : Buckets α β} {i d h} (H :
| .inl hl => H.1 _ hl
| .inr rfl => h₁ (H.1 _ (Array.getElem_mem_toList ..))
· revert hp
simp only [Array.getElem_eq_toList_getElem, toList_update, List.getElem_set, Array.toList_length,
update_size]
simp only [Array.getElem_eq_toList_getElem, toList_update, List.getElem_set,
Array.toList_length, update_size]
split <;> intro hp
· next eq => exact eq ▸ h₂ (H.2 _ _) _ hp
· simp only [update_size, Array.toList_length] at hi
Expand Down Expand Up @@ -171,8 +171,8 @@ where
· match List.mem_or_eq_of_mem_set hl with
| .inl hl => exact hs₁ _ hl
| .inr e => exact e ▸ .nil
· simp only [Array.toList_length, Array.size_set, Array.getElem_eq_toList_getElem, Array.toList_set,
List.getElem_set]
· simp only [Array.toList_length, Array.size_set, Array.getElem_eq_toList_getElem,
Array.toList_set, List.getElem_set]
split
· nofun
· exact hs₂ _ (by simp_all)
Expand Down
5 changes: 3 additions & 2 deletions Batteries/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ def splitOnP (P : α → Bool) (l : List α) : List (List α) := go l [] where

@[csimp] theorem splitOnP_eq_splitOnPTR : @splitOnP = @splitOnPTR := by
funext α P l; simp [splitOnPTR]
suffices ∀ xs acc r, splitOnPTR.go P xs acc r = r.toList ++ splitOnP.go P xs acc.toList.reverse from
(this l #[] #[]).symm
suffices ∀ xs acc r,
splitOnPTR.go P xs acc r = r.toList ++ splitOnP.go P xs acc.toList.reverse from
(this l #[] #[]).symm
intro xs acc r; induction xs generalizing acc r with simp [splitOnP.go, splitOnPTR.go]
| cons x xs IH => cases P x <;> simp [*]

Expand Down

0 comments on commit 41bb40b

Please sign in to comment.