Skip to content

Commit 00193fb

Browse files
committed
feat: add theorems for tutorial
1 parent b5a434d commit 00193fb

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Init/Data/List/Basic.lean

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
119127
theorem 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+
421439
def maximum? [LT α] [DecidableRel (@LT.lt α _)] : List α → Option α
422440
| [] => none
423441
| a::as => some <| as.foldl max a

src/Init/Data/Nat/Basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ protected theorem mul_assoc : ∀ (n m k : Nat), (n * m) * k = n * (m * k)
143143
have h₆ : n * (m * k + m) = n * (m * succ k) := Nat.mul_succ m k ▸ rfl
144144
((((h₁.trans h₂).trans h₃).trans h₄).trans h₅).trans h₆
145145

146+
protected theorem mul_left_comm (n m k : Nat) : n * (m * k) = m * (n * k) := by
147+
rw [← Nat.mul_assoc, Nat.mul_comm n m, Nat.mul_assoc]
148+
146149
/- Inequalities -/
147150

148151
theorem succ_lt_succ {n m : Nat} : n < m → succ n < succ m :=

0 commit comments

Comments
 (0)