我在一些證明中使用了幾個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
不可能是等價的。