@@ -4,7 +4,7 @@ import Batteries.Tactic.GeneralizeProofs
44import Mathlib.Tactic.NthRewrite
55import Mathlib.Tactic.RewriteSearch
66
7- inductive Vec (α: Type ): Nat -> Type where
7+ inductive Vec (α: Type u ): Nat -> Type u where
88 | nil : Vec α 0
99 | cons {n: Nat} (x: α) (xs: Vec α n): Vec α (n + 1 )
1010 deriving DecidableEq, Ord, Repr, Hashable
@@ -121,6 +121,10 @@ def head (xs: Vec α (Nat.succ l)): α :=
121121 match xs with
122122 | Vec.cons x _ => x
123123
124+ def foldl {α : Type u} {β : Type v} (f : α → β → α) : (init : α) → Vec β l → α
125+ | a, nil => a
126+ | a, cons b l => foldl f (f a b) l
127+
124128theorem eq (xs ys: Vec α n) (h: Vec.toList xs = Vec.toList ys): xs = ys := by
125129 induction xs with
126130 | nil =>
@@ -138,11 +142,11 @@ theorem eq (xs ys: Vec α n) (h: Vec.toList xs = Vec.toList ys): xs = ys := by
138142 -- aesop?
139143 simp_all only [List.cons.injEq, forall_const]
140144
141- theorem cast_rfl {α: Type } (xs: Vec α n) (h: n = n):
145+ theorem cast_rfl {α: Type u } (xs: Vec α n) (h: n = n):
142146 cast xs h = xs := by
143147 rfl
144148
145- theorem cast_toList_nil {α: Type } (h: 0 = n):
149+ theorem cast_toList_nil {α: Type u } (h: 0 = n):
146150 (cast (@Vec.nil α) h).toList = [] := by
147151 cases n with
148152 | zero =>
@@ -233,7 +237,7 @@ theorem toList_map (xs: Vec α n) (f: α -> β):
233237 rewrite [List.map]
234238 rfl
235239
236- theorem cons_cast {α: Type } {l n: Nat} (x: α) (xs: Vec α l) (h: l = n):
240+ theorem cons_cast {α: Type u } {l n: Nat} (x: α) (xs: Vec α l) (h: l = n):
237241 (Vec.cons x (Vec.cast xs h)) = Vec.cast (Vec.cons x xs) (by omega) := by
238242 subst h
239243 rfl
@@ -377,7 +381,7 @@ theorem snoc_append (xs: Vec α l):
377381 rw [ih]
378382 rfl
379383
380- theorem snoc_get {n: Nat} {α: Type } (xs: Vec α n) (y: α):
384+ theorem snoc_get {n: Nat} {α: Type u } (xs: Vec α n) (y: α):
381385 Vec.get (Vec.snoc xs y) (Fin.mk n (by omega)) = y := by
382386 induction xs with
383387 | nil =>
@@ -398,7 +402,7 @@ theorem snoc_map (xs: Vec α l) (f: α -> β):
398402 simp only [snoc, map]
399403 rw [ih]
400404
401- theorem get_map {β : Type } (xs : Vec α n) (f : α → β) (i : Fin n) :
405+ theorem get_map {β : Type v } (xs : Vec α n) (f : α → β) (i : Fin n) :
402406 (Vec.map xs f).get i = f (xs.get i) := by
403407 induction xs with
404408 | nil =>
@@ -591,7 +595,7 @@ def smallest [DecidableEq α] [LT α] [DecidableLT α] (xs: Vec α l) (y: α): O
591595 simp only [Nat.add_lt_add_iff_right, Fin.is_lt]
592596 ⟩
593597
594- theorem zip_map {α: Type } {β: Type } (f: α -> β) (xs: Vec α l):
598+ theorem zip_map {α: Type u } {β: Type v } (f: α -> β) (xs: Vec α l):
595599 (Vec.map xs (fun x => (x, f x))) =
596600 (Vec.zip xs (Vec.map xs f)) := by
597601 induction xs with
0 commit comments