Using induction starting from 1 in Coq
Question
I am trying to use induction starting from 1 in a Coq proof. From this question I got a proof of the induction principle I need:
Require Import Coq.micromega.Lia. Section induction_at_1. Variable P : nat -> Prop. Hypothesis p1 : P 1. Hypothesis pS : forall n, P n -> P (S n).P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)forall n : nat, n > 0 -> P nP: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)forall n : nat, n > 0 -> P nP: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
H: 0 > 0P 0P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
n: nat
IHn: n > 0 -> P n
H: S n > 0P (S n)P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
H: 0 > 0P 0lia.P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
H: 0 > 0FalseP: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
n: nat
IHn: n > 0 -> P n
H: S n > 0P (S n)P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
IHn: 0 > 0 -> P 0
H: 1 > 0P 1P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
n: nat
IHn: S n > 0 -> P (S n)
H: S (S n) > 0P (S (S n))apply p1.P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
IHn: 0 > 0 -> P 0
H: 1 > 0P 1P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
n: nat
IHn: S n > 0 -> P (S n)
H: S (S n) > 0P (S (S n))intuition. Qed. End induction_at_1.P: nat -> Prop
p1: P 1
pS: forall n : nat, P n -> P (S n)
n: nat
IHn: S n > 0 -> P (S n)
H: S (S n) > 0
H0: S n > 0P (S (S n))
What I get looks structurally very similar to standard induction. In fact, Check nat_ind yields
while Check induction_at_1 yields
The issue arises when I try to apply this induction principle. For instance, I would like to prove by induction
forall a b c : nat, a > 0 -> a * b = a * c -> b = c
This seems exactly suited to the kind of induction I have above, but when I start my proof like this
a, b, c: nat
H0: a > 0
H1: a * b = a * cb = c
I get the above error, which I cannot interpret. Since the two induction principles look almost identical to me, I am not sure why this does not work. Any ideas?
Answer
I also find this behavior puzzling, but there are a few ways around it. One is to use the ssreflect induction tactic, called elim:
From Coq Require Import ssreflect.forall a b c : nat, a > 0 -> a * b = a * c -> b = cforall a b c : nat, a > 0 -> a * b = a * c -> b = ca, b, c: nat
H: a > 0a * b = a * c -> b = c(* ... *) Abort.b, c: nat1 * b = 1 * c -> b = cb, c: natforall n : nat, (n * b = n * c -> b = c) -> S n * b = S n * c -> b = c
The second line is telling Coq to perform induction on H (not a) while generalizing a and using the induction principle induction_at_1. I couldn't get something similar to work using the regular Coq induction.
An alternative is to use plain natural number induction. In this case, I believe that the lemma follows by induction on b while generalizing c (I am not sure that induction on a works). If you do need to show something of the form m <= n -> P n for all n, you can replace n by n - m + m (which should be possible with the m <= n hypothesis), and then prove P (n - m + m) by induction on n - m.