Conceptually, when we prove something by induction on $x$, we lose any hypotheses we had on the particular value of $x$ that we wanted to apply this to.
Otherwise here is the kind of nonsensical reasoning you could do:
We prove by induction that for all $n ≥ 10$ we have $n ≥ 100$.
- For $n = 0$ we are done by contradiction with $n ≥ 10$,
- If $n ≥ 100$ then clearly $n + 1 ≥ 100$.
What is correct is to move the assumptions to what you're proving by induction. Here's how it makes the previous "proof" fail:
We prove that for all $n ≥ 10$, we have $n ≥ 100$. It suffices to prove that for all $n$, we have $n ≥ 10 ⇒n ≥ 100$.
- For $n = 0$, it is true that $n ≥ 10 ⇒ n ≥ 100$ because $n ≥ 10$ is false.
- Assume $n ≥ 10 ⇒ n ≥ 100$. Assume $n + 1 ≥ 10$ and let's prove $n + 1 ≥ 100$. ⟵ Here we are stuck (fortunately!) because we cannot deduce $n ≥ 10$ from $n + 1 ≥ 10$.
In your case, you are trying to do induction on $s$ while preserving the assumption that $s = n + n'$, which doesn't work for the same reason. Instead, what you should do is to move $n, n'$ into the goal that you prove by induction.
Additionally, what you want is induction on $<$, not structural induction on $s$, and also note that your base
assumption is redundant because it is subsumed by ind
.
Require Import Wf_nat.
Lemma add_2nat_induction
(f : nat -> nat -> Type)
(ind : forall z w, (forall x y, x + y < z + w -> f x y) -> f z w) :
(forall n n', f n n').
Proof.
enough (forall s n n', s = n + n' -> f n n') as H. {
intros. apply (H (n + n')). reflexivity.
}
induction s as [s IH] using (well_founded_induction_type Wf_nat.lt_wf).
intros n n' E. apply ind. intros x y Hlt.
apply (IH (x + y)).
- rewrite E. exact Hlt.
- reflexivity.
Qed.
Alternatively, you can use the lemma that the inverse image of a well-founded relation by any function is well-founded, which is in the standard library. The only issue is that your function is nat -> nat -> Type
and not (nat*nat) -> Type
, so you have to do a bit of currying/uncurrying to actually reach the form you were looking for:
Require Import Wf_nat Wellfounded.Inverse_Image.
Lemma add_2nat_induction
(f : nat -> nat -> Type)
(ind : forall z w, (forall x y, x + y < z + w -> f x y) -> f z w) :
(forall n n', f n n').
Proof.
assert (wf_pairs := wf_inverse_image (nat*nat) nat lt (fun '(x, y) => x + y) Wf_nat.lt_wf).
set (g := fun '(x, y) => f x y).
enough (forall p, g p) as H. { intros. exact (H (n, n')). }
induction p as [p IH] using (well_founded_induction_type wf_pairs).
destruct p as [z w]. apply ind. intros x y. specialize (IH (x, y)). exact IH.
Qed.
induction s eqn:Enn.
or, more directly,induction (n + n') eqn:Enn.
(whether that gets you to the bottom of the proof I haven't checked). And, do you know how to useSearch
, e.g.Search (_ + _ = 0).
? Indeed, if you haven't already, I'd suggest you go through the SF/LF book at least. $\endgroup$Coq.Init.Wf
and maybe evenCoq.Wellfounded.Wellfounded
in the StdLib, unless a point of the exercise is defining things from scratch. $\endgroup$