I’m trying to prove a simple lemma in Agda, which I think is true.
If a vector has more than two elements, taking its
headfollowing taking theinitis the same as taking itsheadimmediately.
I have formulated it as follows:
lem-headInit : ∀{l} (xs : Vec ℕ (suc (suc l)))
-> head (init xs) ≡ head xs
lem-headInit (x ∷ xs) = ?
Which gives me;
.l : ℕ
x : ℕ
xs : Vec ℕ (suc .l)
------------------------------
Goal: head (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) ≡ x
as a response.
I do not entirely understand how to read the (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) component. I suppose my questions are; is it possible, how and what does that term mean.
Many thanks.
This tells you that the value
init (x ∷ xs)depends on the value of everything to the right of the|. When you prove something about in a function in Agda your proof will have to have the structure of the original definition.In this case you have to case on the result of
initLastbecause the definition ofinitLastdoes this before producing any results.So here is how we write the lemma.
I took the liberty of generalizing your lemma to
Vec Asince the lemma doesn’t depend on the contents of the vector.