import Mathlib.Data.Fin.VecNotation
open Lean
partial def matchVecLit (e : Expr) : Option (List Expr) :=
match_expr e with
| Matrix.vecEmpty _ => some []
| Matrix.vecCons _ _ x xs => (x :: ·) <$> matchVecLit xs
| _ => none
dsimproc Matrix.cons_val (Matrix.vecCons _ _ _) := fun e => do
let_expr Matrix.vecCons _ _ x xs' n := e | return .continue
let some n := n.int? | return .continue -- The docstring claims only nat or int, but works fine for Fin
let some xs' := matchVecLit xs' | return .continue
let xs := x :: xs'
let n' := (n % xs.length).toNat
return .continue (xs.get! n')
lemma foo {a b c d : ℕ} : ![a, b, c, d, a, b, c, d, a, b, c, d] (-3) = b := by dsimp
lemma bar {a b c d : ℕ} : ![a, b, c, d, a, b, c, d, a, b, c, d] (-1) = d := by simp