什么';在Coq中应用定理的确切规则是什么?
我在大学学习软件基金会。逻辑部分指出,定理可以像函数一样使用。我尝试了一些例子,但没有找到共同的规则 第一次尝试:什么';在Coq中应用定理的确切规则是什么?,coq,Coq,我在大学学习软件基金会。逻辑部分指出,定理可以像函数一样使用。我尝试了一些例子,但没有找到共同的规则 第一次尝试: Example xxx: (0 = 2) -> (0 = 3). Proof. Admitted. Example yyy: (0 = 2) -> (0 = 3). Proof. intros H. apply (xxx H). (* this works *) apply (xxx (0 = 2)). (* this fails. *) Qed.
Example xxx:
(0 = 2) -> (0 = 3).
Proof. Admitted.
Example yyy:
(0 = 2) -> (0 = 3).
Proof.
intros H.
apply (xxx H). (* this works *)
apply (xxx (0 = 2)). (* this fails. *)
Qed.
Coq给我一个失败版本的错误,如下所示。除了失败之外,我仍然无法理解为什么需要奇怪的类型0=2
而不是Prop
The term "0 = 2" has type "Prop" while it is expected to have type "0 = 2".
如果我在xxx
中使用关系
而不是->
,(xxx H)
也会失败
Example xxx:
(0 = 2) <-> (0 = 3).
Proof. Admitted.
Example yyy:
(0 = 2) -> (0 = 3).
Proof.
intros H.
apply (xxx H). (* this fails either *)
Qed.
正如那一章所解释的,定理或引理的类型是它所证明的陈述。比如说,
Check xxx.
(* 0 = 2 -> 0 = 3 *)
在证明定理时,假设也是如此:
Example yyy:
(0 = 2) -> (0 = 3).
Proof.
intros H.
Check H. (* 0 = 2 *)
您看到的第一条错误消息是,您需要将命题的证明作为参数传递,而不是命题本身。0=2
的类型是Prop
,而不是0=2
本身。类似地,使用plus
函数时,参数的类型必须为nat
,但nat
本身不起作用:
Check plus 1 2. (* nat *)
Check plus nat nat.
(* Error: The term "nat" has type "Set"
while it is expected to have type "nat". *)
编辑
请注意,应用程序语法仅适用于隐含语句和通用量化。以这种方式使用ab
类型的定理时会出现错误,因为此语句的意思是(a->B)/\(B->a)
,但不属于这些情况。但是,您可以使用proj1:forall A B,A/\B->A
引理来提取等价的第一个方面,并将其应用于某些东西。例如,在您提到的示例中,我们可以填写proj1\uj1…
的隐式参数:
proj1 (In n (map (fun m => m * 0) ns))
(exists x, (fun m => m * 0) x = n)
(In_map_iff nat nat (fun m => m * 0) ns n)
H
如果删除H
部分,则此应用程序的类型为
In n (map (fun m => m * 0) ns) ->
exists x, (fun m => m * 0) x = n
它可以应用于n(map..ns)中的H:In,以得到存在性陈述的证明。如该章所述,定理或引理的类型就是它证明的陈述。比如说,
Check xxx.
(* 0 = 2 -> 0 = 3 *)
在证明定理时,假设也是如此:
Example yyy:
(0 = 2) -> (0 = 3).
Proof.
intros H.
Check H. (* 0 = 2 *)
您看到的第一条错误消息是,您需要将命题的证明作为参数传递,而不是命题本身。0=2
的类型是Prop
,而不是0=2
本身。类似地,使用plus
函数时,参数的类型必须为nat
,但nat
本身不起作用:
Check plus 1 2. (* nat *)
Check plus nat nat.
(* Error: The term "nat" has type "Set"
while it is expected to have type "nat". *)
编辑
请注意,应用程序语法仅适用于隐含语句和通用量化。以这种方式使用ab
类型的定理时会出现错误,因为此语句的意思是(a->B)/\(B->a)
,但不属于这些情况。但是,您可以使用proj1:forall A B,A/\B->A
引理来提取等价的第一个方面,并将其应用于某些东西。例如,在您提到的示例中,我们可以填写proj1\uj1…
的隐式参数:
proj1 (In n (map (fun m => m * 0) ns))
(exists x, (fun m => m * 0) x = n)
(In_map_iff nat nat (fun m => m * 0) ns n)
H
如果删除H
部分,则此应用程序的类型为
In n (map (fun m => m * 0) ns) ->
exists x, (fun m => m * 0) x = n
它可以应用于
H:In n(map..ns)
以获得存在性陈述的证明。只是添加了更多细节。只是添加了更多细节。堆栈溢出不会鼓励无关的讨论或回复,但我仍然想说,非常感谢,它解决了我的困惑:)。堆栈溢出不会鼓励无关的讨论或回复,但我仍然想说,非常感谢,它解决了我的困惑:)。