Functional programming “如何证明”~(nat=False)“&引用~(nat=bool)“;及~(nat=True)“;在coq中
以下两个命题很容易证明Functional programming “如何证明”~(nat=False)“&引用~(nat=bool)“;及~(nat=True)“;在coq中,functional-programming,logic,coq,dependent-type,type-theory,Functional Programming,Logic,Coq,Dependent Type,Type Theory,以下两个命题很容易证明 Theorem nat_eq_nat : nat = nat. Proof. trivial. Qed. Theorem True_neq_False : ~(True = False). Proof. unfold not. intros. symmetry in H. rewrite H. trivial. Qed. 但是当我试图证明一个稍微不同的命题时,我发现重写策略不起作用。它报告 错误:为精简程序提供了类型为“Set”的参数“fun
Theorem nat_eq_nat : nat = nat.
Proof.
trivial.
Qed.
Theorem True_neq_False : ~(True = False).
Proof.
unfold not.
intros.
symmetry in H.
rewrite H.
trivial.
Qed.
但是当我试图证明一个稍微不同的命题时,我发现重写策略不起作用。它报告
错误:为精简程序提供了类型为“Set”的参数“fun x:Set=>x”
->“设置”而不是“设置->道具”
所以我试着写一个引理
Lemma Type_eq_prod : forall (a : Type) (b : Type), a = b -> (a -> b).
Proof.
intros.
rewrite <- H.
trivial.
Qed.
Theorem nat_neq_False : ~(nat = False).
Proof.
unfold not.
intros.
apply (Type_eq_prod nat False) in H.
inversion H.
apply 0. (*no subgoals left*)
下面是另外两个让我陷入困境的命题
Theorem nat_neq_bool : ~(nat = bool).
Proof.
unfold not.
intros.
Abort.
Theorem nat_neq_true : ~(nat = True).
Proof.
unfold not.
intros.
Abort.
我的问题是:
1.Why the rewrite tactic doesn't work with proposition ~(nat = False).
2.Why can't I Qed it when there is no subgoals.
3.How to prove the aborted propositions above or is it possible to prove or prove the negates of them in coq.
Prop
、Set
和Type
。有一种包容的概念,它允许人们使用道具
,就好像它是集合
或类型
。这就是为什么首先允许您编写nat=False
,因为只有相同类型的事物之间才允许相等。问题是,对于Coq,False:Prop
与False:Set
不同not
是用False:Prop
定义的,这意味着重写将产生不匹配,这解释了您收到的错误消息
这里有一些类似的方法可以起作用。请注意对集的显式强制
Lemma nat_neq_False_2 : (nat = False) -> (False : Set).
Proof.
intros H.
rewrite <- H.
apply 0.
Qed.
Lemma nat_neq_False_3 : ~(nat = False).
Proof.
intros H.
destruct (nat_neq_False_2 H).
Qed.
在这里,我们可以看到问题是,再次出现了宇宙不匹配:一个等式在类型
中,而另一个等式在集合
中。有几种方法可以解决这个问题;最简单的方法可能是将第一个定理改为:
Lemma Type_eq_prod : forall (a : Set) (b : Set), a = b -> (a -> b).
nat
和bool
等简单类型不同的方法是通过基数参数。因此,nat bool
,因为bool
只有两个元素,而nat
有更多元素。因此,通过显示bool
有两个元素,可以重写等式nat=bool
,以发现nat
也应该有两个元素,然后利用这一点得到矛盾。类似的参数将显示nat True
谢谢你的详细回答。但是如何证明布尔有两个要素呢?如果这两个集合是nat和正的,并且在理论上有相等的元素,那么如何证明nat是正的呢?证明bool只有两个元素是很容易的:一个人可以证明一个语句,例如
存在b1 b2:bool,对于所有的b3:bool,b3=b1\/b3=b2。
通过执行存在true。存在错误。简介[];自动。
。然而,不可能在Coq中显示nat阳性。事实证明,这与理论无关,这意味着可以将nat=positive
和nat-positive
分别添加为公理。
Set Printing All.
Lemma Type_eq_prod : forall (a : Type) (b : Type), a = b -> (a -> b).
Proof.
intros.
rewrite <- H.
trivial.
Qed.
Theorem nat_neq_False : ~(nat = False).
Proof.
unfold not.
intros.
apply (Type_eq_prod nat False) in H.
inversion H.
apply 0. (*no subgoals left*)
Qed.
(* Error: Illegal application (Type Error): *)
(* The term "Type_eq_prod" of type "forall a b : Type, @eq Type a b -> a -> b" *)
(* cannot be applied to the terms *)
(* "nat" : "Set" *)
(* "False" : "Prop" *)
(* "H" : "@eq Set nat False" *)
(* "O" : "nat" *)
(* The 3rd term has type "@eq Set nat False" which should be coercible to *)
(* "@eq Type nat False". *)
Lemma Type_eq_prod : forall (a : Set) (b : Set), a = b -> (a -> b).