[英]a + b = 0 -> a = 0 and b = 0 in Coq
I want to prove the following : 我想证明以下内容:
1 subgoals
a : nat
b : nat
H0 : a + b = 0
______________________________________(1/1)
a = 0 /\ b = 0
It seems very easy, even trivial, but I dont know how to do it. 看起来很容易,甚至琐碎,但我不知道该怎么做。 I tried
induction
, case
, unsuccessfully. 我尝试了
induction
, case
,失败。 Any idea ? 任何想法 ?
Thanks for your help. 谢谢你的帮助。
You can prove forall n1 n2, n1 + n2 = 0 -> n1 = 0
by case analysis on n1
. 通过对
n1
进行个案分析,可以证明所有forall n1 n2, n1 + n2 = 0 -> n1 = 0
。
If n1
is 0
, the conclusion is 0 = 0
, which you can prove because =
is reflexive. 如果
n1
为0
,则结论为0 = 0
,您可以证明,因为=
是自反的。
If there's an n3
such that n1 = S n3
, then the hypothesis S n3 + n2 = 0
reduces to S (n3 + n2) = 0
and implies False
because 0
and S
are different constructors. 如果存在
n3
使得n1 = S n3
,则假设S n3 + n2 = 0
简化为S (n3 + n2) = 0
并暗示False
因为0
和S
是不同的构造函数。 False
implies anything so you're done. False
表示任何事情,因此您已完成。
You can prove forall n1 n2, n1 + n2 = 0 -> n2 = 0
by using the previous fact and commutativity of addition. 通过使用加法的先前事实和可交换性,可以证明所有
forall n1 n2, n1 + n2 = 0 -> n2 = 0
。 Then you're able to prove forall n1 n2, n1 + n2 = 0 -> n1 = 0 /\\ n2 = 0
. 这样就可以证明所有
forall n1 n2, n1 + n2 = 0 -> n1 = 0 /\\ n2 = 0
。
Check eq_refl.
Check O_S.
Check False_rect.
Conjecture plus_comm : forall n1 n2, n1 + n2 = n2 + n1.
Check conj.
It's probably better to try to automate the proof as much as possible though. 不过,尝试尽可能自动执行证明可能更好。
Require Import Coq.Setoids.Setoid.
Set Firstorder Depth 0.
Create HintDb Hints.
Ltac simplify := firstorder || autorewrite with Hints in *.
Conjecture C1 : forall t1 (x1 : t1), x1 = x1 <-> True.
Conjecture C2 : forall n1, S n1 = 0 <-> False.
Conjecture C3 : forall n1, 0 = S n1 <-> False.
Conjecture C4 : forall n1 n2, S n1 = S n2 <-> n1 = n2.
Conjecture C5 : forall n1, 0 + n1 = n1.
Conjecture C6 : forall n1 n2, S n1 + n2 = S (n1 + n2).
Hint Rewrite C1 C2 C3 C4 C5 C6 : Hints.
Theorem T1 : forall n1 n2, n1 + n2 = 0 <-> n1 = 0 /\ n2 = 0.
Proof. destruct n1; repeat simplify. Qed.
Hint Rewrite T1 : Hints.
Either way, this fact has already been proved in the standard library. 无论哪种方式,这个事实都已经在标准库中得到了证明。
Require Import Coq.Arith.Arith.
Check plus_is_O.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.