2016-03-26 17 views
2

我在一些證明中使用了幾個Inductive定義作爲反例。然而,我想將這些定義封裝在一個Section中。定期Definitions可以隱藏使用Let,但是這也可能爲Inductive的定義?那麼Theorem呢?局部歸納定義和定理

讓我給出我想要實現的實際事情,因爲我可能會在第一時間完全錯誤地解決這個問題。我想將羅伯特戈德布拉特的優秀着作「時間和計算邏輯」的所有證明和練習正式化爲Coq。

對於初學者,我們採用古典邏輯,因爲這本書也是如此。

Require Import Classical_Prop. 
Require Import Classical_Pred_Type. 

接下來我們在軟件基礎中定義標識符。

Inductive id : Type := Id : nat -> id. 

語法的定義。

Inductive modal : Type := 
| Bottom : modal 
| V : id -> modal 
| Imp : modal -> modal -> modal 
| Box : modal -> modal 
. 

Definition Not (f : modal) : modal := Imp f Bottom. 

使用Kripke幀定義語義。

(* Inspired by: www.cs.vu.nl/~tcs/mt/dewind.ps.gz 
*) 
Record frame : Type := 
{ Worlds : Type 
; WorldsExist : exists w : Worlds, True 
; Rel : Worlds -> Worlds -> Prop 
}. 

Record kripke : Type := 
{ Frame : frame 
; Label : (Worlds Frame) -> id -> Prop 
}. 

Fixpoint satisfies (M : kripke) (x : (Worlds (Frame M))) (f : modal) : Prop 
:= match f with 
| Bottom => False 
| V v => (Label M x v) 
| Imp f1 f2 => (satisfies M x f1) -> (satisfies M x f2) 
| Box f => forall y : (Worlds (Frame M)), (Rel (Frame M) x y) -> (satisfies M y f) 
end. 

第一個引理涉及模態Not與Coq之一。

Lemma satisfies_Not 
: forall M x f 
, satisfies M x (Not f) = ~ satisfies M x f 
. 
Proof. auto. 
Qed. 

接下來我們提升語義以完成模型。

Definition M_satisfies (M : kripke) (f : modal) : Prop 
:= forall w : Worlds (Frame M), satisfies M w f. 

而且我們展示了它對於Not連接詞的含義。

Lemma M_satisfies_Not : forall M f 
, M_satisfies M (Not f) -> ~ M_satisfies M f 
. 
Proof. 
    unfold M_satisfies. 
    intros M f Hn Hcontra. 
    destruct (WorldsExist (Frame M)). 
    specialize (Hn x); clear H. 
    rewrite satisfies_Not in Hn. 
    specialize (Hcontra x). auto. 
Qed. 

這是事情。上述引理的反過來並不成立,我想通過一個反例來展示它,展示一個它不具有的模型。

Inductive Wcounter : Set := | x1:Wcounter | x2:Wcounter | x3:Wcounter. 

Lemma Wcounter_not_empty : exists w : Wcounter, True. 
Proof. exists x1. constructor. Qed. 

Inductive Rcounter (x : Wcounter) (y : Wcounter) : Prop := 
| E1 : x = x1 -> y = x2 -> Rcounter x y 
| E2 : x = x2 -> y = x3 -> Rcounter x y 
. 

Definition Lcounter : Wcounter -> id -> Prop 
:= fun x i => match x with 
| x1 => match i with | Id 0 => True | _ => False end 
| x2 => match i with | Id 1 => True | _ => False end 
| x3 => match i with | Id 0 => True | _ => False end 
end. 

Definition Fcounter : frame := Build_frame Wcounter Wcounter_not_empty Rcounter. 

Definition Kcounter : kripke := Build_kripke Fcounter Lcounter. 

下一個Ltac是減輕我打字詳細assert秒。

Ltac counter_example H Hc := match type of H with 
| ?P -> ~ ?Q => assert(Hc: Q) 
| ?P -> (?Q -> False) => assert(Hc: Q) 
| ?P -> ?Q => assert(Hc: ~Q) 
end. 

最後我用這個反例來證明以下Lemma

Lemma M_not_satisfies_Not : ~ forall M f 
, (~ M_satisfies M f) -> M_satisfies M (Not f) 
. 
Proof. 
    apply ex_not_not_all. exists Kcounter. 
    apply ex_not_not_all. exists (V (Id 0)). 
    unfold M_satisfies. simpl. 
    intro Hcontra. unfold not in Hcontra. 
    counter_example Hcontra Hn2. 
    apply ex_not_not_all. exists x1. simpl. auto. 
    apply Hn2. apply Hcontra. apply ex_not_not_all; exists x2. simpl. auto. 
Qed. 

最好,我會用remember策略來定義證明裏面的反例,但我不認爲它可以用於Inductive定義。所有關於反例的定義都作爲我理論的一部分出口,我不願意這樣做。它僅用於M_not_satisfies_Not的證明。其實我甚至不想出口這個Lemma,因爲它不是很有用。我只是在那裏辯解M_satisfies_Not不可能是等價的。

回答

1

Section不會隱藏定義,請改爲使用Module。例如,將計數器示例放在一個模塊中。

Module CounterExample. 
    Import Definitions. 
    Inductive Wcounter : Set := x1 | x2 | x3. 
    ... 
    Lemma M_not_satisfies_Not : ... 
End CounterExample. 

在這個階段,只有CounterExample被定義在頂層。

如果您不想那麼做,那麼您可以將定義放在一個.v文件中,並將計數器示例放入另一個導入定義的文件中。實際上,它的工作方式是將.v文件轉換爲單個模塊。