Created
October 13, 2024 11:33
-
-
Save thelissimus/9581fab693522770ca4fc3d9fd08ffcd to your computer and use it in GitHub Desktop.
Reversing a Vec in Lean 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inductive Vec (α : Type u) : Nat → Type u where | |
| | nil : Vec α 0 | |
| | cons : α → Vec α n → Vec α (n + 1) | |
| deriving Repr | |
| def Vec.reverse {α : Type u} {n : Nat} (xs : Vec α n) : Vec α n := loop xs nil | |
| where | |
| loop {n m : Nat} : Vec α n → Vec α m → Vec α (n + m) | |
| | nil, acc => by rwa [Nat.zero_add] | |
| | @cons _ n x xs, acc => by | |
| have := loop xs (cons x acc) | |
| rwa [Nat.add_comm, Nat.add_left_comm] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment