簡體   English   中英

教會數字與宇宙不一致

[英]Church numerals and universe inconsistency

在以下代碼中,Coq接受語句add'_commut ,但由於Universe不一致而拒絕add_commut

Set Universe Polymorphism.

Definition nat : Type := forall (X : Type), X -> (X -> X) -> X.

Definition succ (n : nat) : nat := fun X z s => s (n X z s).

Definition add' (m n : nat) : nat := fun X z s => m X (n X z s) s.

Definition nat_rec (z : nat) (s : nat -> nat) (n : nat) : nat := n nat z s.
Definition add (m n : nat) : nat := nat_rec n succ m.

Definition equal (A : Type) (a : A) : A -> Type := fun a' => forall (P : A -> Type), P a -> P a'.

Lemma add'_commut (m n : nat) : equal nat (add' m n) (add' n m).
Admitted.

Lemma add_commut (m n : nat) : equal nat (add m n) (add n m).
(*
In environment
m : nat
n : nat
The term "add n (fun X : Type => m X)" has type
 "nat@{Top.1078 Top.1079}"
while it is expected to have type
 "nat@{Top.1080 Top.1078}" (universe inconsistency).
*)

如何讓它通過?

教堂數字僅在打開impredicative Set時才有效,方法是將-arg -impredicative-set放入_CoqProject文件或使用-impredicative-set命令行選項。 然后將nat定義為:

Definition nat : Set := forall (X : Set), X -> (X -> X) -> X.

Impredicative Set允許nat具有與其量化的完全相同的類型Set 如果沒有不可預測性, nat必須具有比它量化的更高的宇宙級別,盡管這些級別對你來說是隱藏的,直到你得到類似問題的錯誤。

請注意,impredicative Set與經典邏輯不兼容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM