[英]How to prove antisymmetric in coq
Define relation [<=] on natural numbers by saying that [m <= n] holds if there is a number [k] such that [m = k + n]. 通过说[m <= n]成立自然数上的关系[<=],如果存在一个[k]使得[m = k + n]。
Reflexive and transitive have been proved. 反身和传递已被证明。
reflexive: ref: forall n:nat, n <= n.
transitive: trans: forall l m n:nat, l <= m -> m <= n -> l <= n
Now, how to prove forall lm : nat, l <= m -> m <= l -> m = l
? 现在,如何证明所有
forall lm : nat, l <= m -> m <= l -> m = l
?
I think you meant " m <= n
holds if there is k
such that n = m + k
". 我认为您的意思是“如果存在
k
使得n = m + k
,则m <= n
成立”。
The only additional lemma I needed to prove antisymmetry is: 我需要证明反对称性的唯一其他引理是:
Lemma le_S_n : forall m n, le (S m) (S n) -> le m n.
Then my proof of antisymmetry goes by induction. 然后我的反对称证明是归纳法。 Here is the full script:
这是完整的脚本:
Require Import Arith.
Definition le (m n :nat) := exists k, n = m + k.
Lemma le_refl : forall m, le m m.
Proof.
intro m; exists 0.
now rewrite <- plus_n_O.
Qed.
Lemma le_trans: forall m n p, le m n -> le n p -> le m p.
Proof.
intros m n p [k1 hk1] [k2 hk2]; exists (k1 + k2).
now rewrite plus_assoc, <- hk1.
Qed.
Lemma le_S_n : forall m n, le (S m) (S n) -> le m n.
Proof.
intros m n [k hk]; exists k.
simpl in hk.
now injection hk; intros.
Qed.
Lemma le_antisym: forall m n, le m n -> le n m -> m = n.
Proof.
induction m as [ | m hi]; destruct n as [ | n ]; simpl in *; intros h1 h2.
- reflexivity.
- destruct h2 as [k hk].
simpl in hk; discriminate hk.
- destruct h1 as [k hk].
simpl in hk; discriminate hk.
- now rewrite (hi n); [ reflexivity | apply le_S_n | apply le_S_n ].
Qed.
Here is a short solution: 这是一个简短的解决方案:
Require Omega.
Definition le (n m:nat) := exists k, n + k = m.
Theorem le_nm_mn_eq: forall n m, le n m -> le m n -> n = m.
Proof.
intros n m Hnm Hmn.
inversion Hnm; inversion Hmn.
omega.
Qed.
It uses omega so that I don't have to do all the fiddling with nat
equalities. 它使用欧米茄(Omega),这样我就不必摆弄
nat
平等了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.