So, I am trying to learn Coq using the "Introduction to Computational Logic" script and I have been given an excercise. It is to prove the following: "forall a b, a + S b = S (a + b)". I am given a definition of "nat_ind":
(p : nat -> Prop)
(basis : p 0)
(step : forall n, p n -> p (S n)) :
forall n, p n := fix f n :=
match n return p n with
| 0 => basis
| S n => step n (f n)
end.
I have had an attempt at this and solved the issue using this method and it worked:
intros a b. revert a.
apply (nat_ind(fun a => a + S b = S (a+b))); simpl.
-reflexivity.
-intros. f_equal. exact H.
The problem comes now that i have to solve the same issue, but I need to apply the induction lemma immediatelly and can't use intros or induction tactics before i have done that. How do I go about this?
I have tried to remove the first line from my first attempt, but it throws an error: "The reference b was not found in the current environment."
Update: I have gotten somewhere. This is my current code:
Goal forall a b, a + S b = S (a + b).
Proof.
apply nat_ind.
- intros a b. revert a.
apply (nat_ind (fun a => a + S b = S (a + b)));simpl.
+ reflexivity.
+ intros. f_equal. exact H.
-intros. revert a. apply (nat_ind (fun a => a + S b = S (a + b))); simpl.
+ reflexivity.
+ intros. f_equal. exact H0.
The last subgoal is just nat, and I don't know how to go about it at all.