lean4-htt/tests/lean/run/1024.lean
Kim Morrison c3948cba24
feat: upstream definition of Vector from Batteries (#6197)
This PR upstreams the definition of `Vector` from Batteries, along with
the basic functions.
2024-11-24 23:01:32 +00:00

29 lines
905 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

inductive Vector' (α : Type u): Nat → Type u where
| nil : Vector' α 0
| cons (head : α) (tail : Vector' α n) : Vector' α (n+1)
namespace Vector'
def nth : ∀{n}, Vector' α n → Fin n → α
| n+1, cons x xs, ⟨ 0, _⟩ => x
| n+1, cons x xs, ⟨k+1, h⟩ => xs.nth ⟨k, sorry⟩
def snoc : ∀{n : Nat} (xs : Vector' α n) (x : α), Vector' α (n+1)
| _, nil, x' => cons x' nil
| _, cons x xs, x' => cons x (snoc xs x')
theorem nth_snoc_eq (k: Fin (n+1))(v : Vector' α n)
(h: k.val = n):
(v.snoc x).nth k = x := by
cases k; rename_i k hk
induction v generalizing k <;> subst h
· simp only [nth]
· simp! [*]
theorem nth_snoc_eq_works (k: Fin (n+1))(v : Vector' α n)
(h: k.val = n):
(v.snoc x).nth k = x := by
cases k; rename_i k hk
induction v generalizing k <;> subst h
· simp only [nth]
· simp[*,nth]
end Vector'