The task.
Suppose we give Coq the following definition:
Inductive R2 : nat -> list nat -> Prop :=
| c1 : R2 0 []
| c2 : forall n l, R2 n l -> R2 (S n) (n :: l)
| c3 : forall n l, R2 (S n) l -> R2 n l.
Which of the following propositions are provable?
I proved 2 out of 3.
Example Example_R21 : R2 2 [1;0].
Proof.
apply c2. apply c2. apply c1.
Qed.
Example Example_R22 : R2 1 [1;2;1;0].
Proof.
repeat constructor.
Qed.
The 3-rd is not provable, because c3 will only increase n, and it will never be equal to the head of list + 1. But how to formally prove that it is not provable?
Example Example_R23 : not (R2 6 [3;2;1;0]).
Proof.
Qed.
Update 1
Fixpoint gen (n: nat) : list nat :=
match n with
| 0 => []
| S n' => (n' :: gen n')
end.
Lemma R2_gen : forall (n : nat) (l : list nat), R2 n l -> l = gen n.
Proof.
intros n l H. induction H.
- simpl. reflexivity.
- simpl. rewrite IHR2. reflexivity.
- simpl in IHR2. ?
You have to proceed by induction on the
R2. Basically, if you haveR2 6 (3 :: _), then it must be ac3(no other constructor fits), so it contains anR2 7 (3 :: _), which must also bec3, which containsR2 8 (3 :: _), etc. This chain is infinite, so you'll never reach the end. Therefore, you can useFalseas the goal of the induction and you will never reach the base case where you actually have to produceFalse. It is not enough to just useinversion. Inversion is really just one step of the needed induction, and induction on any of the other things in the context doesn't help.During the induction, the first parameter will vary. Specifically, it will always be more than
S 3(that's what lets us rule out the other constructors), so we need to generalize with respect tokwhere the first parameter is always5 + k(starting withk = 1for our case where we have6).We can reduce this proof immensely by using the experimental
dependent inductiontactic, which replaces the middle,inversiony part.Another form of cleanup would be extracting the generalized proof out into a lemma: