I was trying to solve the following theorem and got stuck at the last simpl.
:
Lemma nonzeros_app : forall l1 l2 : natlist,
nonzeros (l1 ++ l2) = (nonzeros l1) ++ (nonzeros l2).
Proof.
intros l1 l2. induction l1 as [| n' l' IHl'].
-simpl. reflexivity.
-simpl.
Qed.
at that point Coq changes the goal from:
1 subgoal (ID 170)
n' : nat
l', l2 : natlist
IHl' : nonzeros (l' ++ l2) = nonzeros l' ++ nonzeros l2
============================
nonzeros ((n' :: l') ++ l2) = nonzeros (n' :: l') ++ nonzeros l2
to:
1 subgoal (ID 185)
n' : nat
l', l2 : natlist
IHl' : nonzeros (l' ++ l2) = nonzeros l' ++ nonzeros l2
============================
match n' with
| 0 => nonzeros (l' ++ l2)
| S _ => n' :: nonzeros (l' ++ l2)
end =
match n' with
| 0 => nonzeros l'
| S _ => n' :: nonzeros l'
end ++ nonzeros l2
which seems completely mysterious to me. What does it mean when Coq just copy pastes the definition of a function into my goal? What do I even do with this?
Context of Question:
Someone told me that the solution is:
Lemma nonzeros_app : forall l1 l2 : natlist,
nonzeros (l1 ++ l2) = (nonzeros l1) ++ (nonzeros l2).
Proof.
intros l1 l2. induction l1.
- simpl. reflexivity.
- simpl. { induction n.
- ...
- ... }
Qed.
which made me want to understand why they use induction on n
since it feels it would never occur to me to use induction there. So I am asking, why? But I realized that before I could ask that why I didn't even understand the proof state before that since it just seemed to copy paste a function to a proof state (which makes no sense to me). So before I asked why use induction there I have to ask what does the proof state before that, maybe that would yield light into why induction on n
.