簡體   English   中英

如何在coq中證明“〜(nat = False)”,“〜(nat = bool)”和“〜(nat = True)”

[英]How to prove “~(nat = False)”, “~(nat = bool)” and “~(nat = True)” in coq

以下兩個命題很容易證明。

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.

但是當我試圖證明一個稍微不同的命題~(nat = False) ,我發現重寫策略不起作用。 它報道

錯誤:Refiner被賦予了一個參數“fun x:Set => x”,類型為“Set - > Set”而不是“Set - > Prop”。

所以我試着寫一個引理。

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, a = b -> a -> b"
cannot be applied to the terms
 "nat" : "Set"
 "False" : "Prop"
 "H" : "nat = False"
 "0" : "nat"
The 3rd term has type "nat = False" which should be coercible to
 "nat = False".

以下是另外兩個讓我陷入困境的命題。

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.
  1. 由於Coq處理其Universe, PropSetType ,重寫策略不起作用。 有一種包含概念允許人們使用Prop ,就像它是SetType 這就是為什么你被允許首先編寫nat = False ,因為只允許在相同類型的事物之間進行相等。 問題在於,對於Coq, False : PropFalse : Set不同。 notFalse : Prop定義False : Prop ,這意味着重寫會產生不匹配,這解釋了你得到的錯誤信息。

    以下是可行的類似方法。 注意顯式強制Set

     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. 
  2. 當你使用策略編寫證明時,Coq實際上是在內部構建一個證明術語,但實際上並沒有對它進行類比檢查。 從這個意義上講,它有點像元編程。 一旦你擊中Qed ,由策略構建的術語將發送給類型檢查器,以確保它沒問題。 大多數時候,策略會產生正確的證據,但每隔一段時間就會發現一些不被接受的證據,而你的案例就是一個例子。

    打印的錯誤消息不是很清楚,但可以通過使用命令Set Printing All更好地了解正在發生的事情,這會導致Coq打印所有不帶符號的術語和語句並顯示隱式參數。 執行此操作時,這是您的錯誤消息:

     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 ab : Type, @eq Type ab -> 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". *) 

    在那里,我們可以看到問題是宇宙不再存在不匹配:一個等式在Type ,而另一個在Set 有幾種方法可以解決這個問題; 最簡單的可能是將你的第一個定理改為:

     Lemma Type_eq_prod : forall (a : Set) (b : Set), a = b -> (a -> b). 
  3. 兩個命題都可以在Coq中證明。 在Coq的基礎理論中,唯一可以證明natbool等簡單類型不同的方法是基數論證。 因此, nat <> bool因為bool只有兩個元素,而nat有更多。 因此,通過顯示bool有兩個元素,可以重寫等式nat = bool以找出nat也應該有兩個元素,然后利用它來獲得矛盾。 類似的參數會顯示nat <> True

暫無
暫無

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

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