解决这个问题的一种方法是对a
. 但是,如果你开始你的证明
intros a b C; induction a.
你会被卡住,因为上下文会有以下假设:
C : S a <> b
IHa : a <> b -> a - b <> b - a
您将无法使用归纳假设IHa
,因为无法从 推断IHa
( a <> b
)的前提S a <> b
:例如1 <> 0
不暗示0 <> 0
。
但是我们可以通过不将变量过早地引入上下文来使归纳假设更强:
Require Import Coq.Arith.Arith.
Lemma subtraction_does_not_commute :
forall a b : nat, a <> b -> a - b <> b - a.
Proof.
induction a; intros b C.
- now rewrite Nat.sub_0_r.
- destruct b.
+ trivial.
+ repeat rewrite Nat.sub_succ. auto.
Qed.
或者,或者,使用该omega
策略,我们得到一个单行证明:
Require Import Omega.
Lemma subtraction_does_not_commute :
forall a b : nat, a <> b -> a - b <> b - a.
Proof. intros; omega. Qed.