假设我有一个关于自然数的存在命题P
Definition P (n : nat) : Prop
:= exists k:nat, True.
还假设我已经证明了P
的所有数字,
Lemma allP : forall n : nat, P n.
Proof.
intros. exists 0. trivial.
Defined.
然后我为所有k
有一个见证人n
(在上一个示例中k
始终为0),我想断言所有k
的东西,例如
Definition allWitnessesBelowOne : Prop
:= forall n : nat,
match allP n with
| ex_intro _ k _ => k <= 1
end.
除非无法编译,否则出现以下错误:
Incorrect elimination of "allP n" in the inductive type "ex":
the return type has sort "Type" while it should be "Prop".
Elimination of an inductive object of sort Prop
is not allowed on a predicate in sort Type
because proofs can be eliminated only to build proofs.
我不明白这里是什么Type
,所有内容都在Prop
中。我只是想建立一个证明,Coq为什么不开心?在我的完整问题中,P
要复杂得多,证明所有证人的某些东西确实有意义。
答案 0 :(得分:3)
撰写时详细说明@eponier的评论
data <- tbl(conn, in_schema("Person", "Person"))
您实际上是在写作
Definition allWitnessesBelowOne : Prop
:= forall n : nat,
match allP n with
| ex_intro _ k _ => k <= 1
end.
当您拥有Definition allWitnessesBelowOne : Prop
:= forall n : nat,
match allP n return Prop with
| ex_intro _ k _ => k <= 1
end.
时,返回类型return Prop
的类型为Prop
,而返回类型必须为Type
才能满足消除限制。基本上,如果取消此限制,则会使Coq与经典逻辑不一致。例如,请参见the official documentation of Prop
,Incorrect elimination of X in the inductive type "or":或CPDT on universes。
另一种查看方式是,如果您没有任何公理,则必须有可能将所有Prop
解释为单例集(如果为true)或空集(如果为true)他们是错误的)。单例集合中没有非常数函数,因此您无法通过Prop
的证明来定义任何有趣的属性。
解决此问题的最简单方法是停止使用exists k : nat, True
。而是使用sigma(Prop
)类型来表示:
sig
最后一个的替代定义是
Definition P (n : nat)
:= { k : nat | True }.
Lemma allP : forall n : nat, P n.
Proof.
intros. exists 0. trivial.
Defined.
Definition allWitnessesBelowOne : Prop
:= forall n : nat,
match allP n with
| exist _ k _ => k <= 1
end.
您可以做的另一件事是,您可以做所有延续传递样式的事情:
Definition allWitnessesBelowOne : Prop
:= forall n : nat,
proj1_sig (allP n) <= 1.
在这里,Definition P (n : nat) : Prop
:= exists k:nat, True.
Lemma allP : forall n : nat, P n.
Proof.
intros. exists 0. trivial.
Defined.
Lemma allWitnessesBelowOne_cps
(n : nat)
(Result : P n -> Prop)
: (forall k pf, k <= 1 -> Result (ex_intro _ k pf))
-> Result (allP n).
Proof.
unfold allP; intro H.
apply H; repeat constructor.
Defined.
确定您最终将要证明的Result
。这个引理说,每当您尝试证明有关Prop
的{{1}}时,都可以假定您证明有关Result
的值的allP n
。不过,这相当复杂,因此我建议您在可以管理的情况下仅删除Result
。