Trying to prove following Lemma:
I have tried unfold nth_error and nth in the goal but I cannot figure out a way to tell Coq to break the Fixpoint definition of these two functions. I have also tried to induction on n and the lists but none of them was able to solve the problem since the items in list are irrelevant with each other. But this is obviously a correct Lemma, right now I feel it is un-provable, anyone can help me solve this problem? Much appreciated!
Lemma nth_error_nth :
forall nodes1 (node : node) n,
n < length nodes1 ->
nth_error nodes1 n = Some (nth n nodes1 node).
Your question should really be edited to include a Minimal, Reproducible Example so we don't need to guess what definitions you're using. I'm assuming you're using the standard library's
Listmodule and thatnodeis simply some type. Without any more information, I'll just assume it's something likeVariable node: Type.To prove this lemma, induction on the list itself should work. You'll probably also need to do case analysis on
n(trydestruct n) sincen_thand a few other things depend on whethernis0or not. If something seems like it might be impossible to prove, try strengthening the inductive hypothesis. This involves having more hypotheses in the goal when you useinduction. You can accomplish this withrevertor simply neverintrothe hypothesis in question.You'll likely get some absurd hypotheses, like n < 0. You can use some the lemmas in
PeanoNat.Natto derive a contradiction from this. It might be helpful to use theSearchvernacular. For example,Search (?n < 0).finds the lemma I referred to. There's also one step where you'll need to concludem < nfromS m < S n, which can be done withLt.lt_S_n.Just to get you started, here's the beginning of a proof.