@@ -112,10 +112,18 @@ theorem reverseAux_eq_append (as bs : List α) : reverseAux as bs = reverseAux a
112112 rw [ih (a :: bs), ih [a], append_assoc]
113113 rfl
114114
115- theorem reverse_cons (a : α) (as : List α) : reverse (a :: as) = reverse as ++ [a] := by
115+ @[simp] theorem reverse_nil : reverse ([] : List α) = [] :=
116+ rfl
117+
118+ @[simp] theorem reverse_cons (a : α) (as : List α) : reverse (a :: as) = reverse as ++ [a] := by
116119 simp [reverse, reverseAux]
117120 rw [← reverseAux_eq_append]
118121
122+ @[simp] theorem reverse_append (as bs : List α) : (as ++ bs).reverse = bs.reverse ++ as.reverse := by
123+ induction as generalizing bs with
124+ | nil => simp
125+ | cons a as ih => simp [ih]; rw [append_assoc]
126+
119127theorem mapTRAux_eq (f : α → β) (as : List α) (bs : List β) : mapTRAux f as bs = bs.reverse ++ map f as := by
120128 induction as generalizing bs with
121129 | nil => simp [mapTRAux, map]
@@ -127,7 +135,6 @@ theorem mapTRAux_eq (f : α → β) (as : List α) (bs : List β) : mapTRAux f a
127135@[csimp] theorem map_eq_mapTR : @map = @mapTR := by
128136 apply funext; intro α; apply funext; intro β; apply funext; intro f; apply funext; intro as
129137 simp [mapTR, mapTRAux_eq]
130- rfl
131138
132139@[specialize] def map₂ (f : α → β → γ) : List α → List β → List γ
133140 | [], _ => []
@@ -418,6 +425,17 @@ def dropLast {α} : List α → List α
418425 simp[dropLast, ih]
419426 rfl
420427
428+ @[simp] theorem length_append (as bs : List α) : (as ++ bs).length = as.length + bs.length := by
429+ induction as with
430+ | nil => simp
431+ | cons a as ih => simp [ih, Nat.succ_add]
432+
433+
434+ @[simp] theorem length_reverse (as : List α) : (as.reverse).length = as.length := by
435+ induction as with
436+ | nil => rfl
437+ | cons a as ih => simp [ih]
438+
421439def maximum? [LT α] [DecidableRel (@LT.lt α _)] : List α → Option α
422440 | [] => none
423441 | a::as => some <| as.foldl max a
0 commit comments