src/HOL/Meson.thy
 author blanchet Mon Oct 04 22:45:09 2010 +0200 (2010-10-04) changeset 39946 78faa9b31202 parent 39944 03ac1fbc76d3 child 39947 f95834c8bb4d permissions -rw-r--r--
move Metis into Plain
1 (*  Title:      HOL/Meson.thy
2     Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
3     Author:     Tobias Nipkow, TU Muenchen
4     Author:     Jasmin Blanchette, TU Muenchen
5     Copyright   2001  University of Cambridge
6 *)
8 header {* MESON Proof Procedure (Model Elimination) *}
10 theory Meson
11 imports Datatype
12 uses ("Tools/Meson/meson.ML")
13      ("Tools/Meson/meson_clausify.ML")
14 begin
16 section {* Negation Normal Form *}
18 text {* de Morgan laws *}
20 lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
21   and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
22   and meson_not_notD: "~~P ==> P"
23   and meson_not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
24   and meson_not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
25   by fast+
27 text {* Removal of @{text "-->"} and @{text "<->"} (positive and
28 negative occurrences) *}
30 lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
31   and meson_not_impD: "~(P-->Q) ==> P & ~Q"
32   and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
33   and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
34     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
35   and meson_not_refl_disj_D: "x ~= x | P ==> P"
36   by fast+
39 section {* Pulling out the existential quantifiers *}
41 text {* Conjunction *}
43 lemma meson_conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
44   and meson_conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
45   by fast+
48 text {* Disjunction *}
50 lemma meson_disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
51   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
52   -- {* With ex-Skolemization, makes fewer Skolem constants *}
53   and meson_disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
54   and meson_disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
55   by fast+
57 lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
58   and meson_disj_comm: "P|Q ==> Q|P"
59   and meson_disj_FalseD1: "False|P ==> P"
60   and meson_disj_FalseD2: "P|False ==> P"
61   by fast+
64 text{* Generation of contrapositives *}
66 text{*Inserts negated disjunct after removing the negation; P is a literal.
67   Model elimination requires assuming the negation of every attempted subgoal,
68   hence the negated disjuncts.*}
69 lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
70 by blast
72 text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
73 lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
74 by blast
76 text{*@{term P} should be a literal*}
77 lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
78 by blast
80 text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
81 insert new assumptions, for ordinary resolution.*}
83 lemmas make_neg_rule' = make_refined_neg_rule
85 lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
86 by blast
88 text{* Generation of a goal clause -- put away the final literal *}
90 lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
91 by blast
93 lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
94 by blast
97 section {* Lemmas for Forward Proof *}
99 text{*There is a similarity to congruence rules*}
101 (*NOTE: could handle conjunctions (faster?) by
102     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
103 lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
104 by blast
106 lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
107 by blast
109 (*Version of @{text disj_forward} for removal of duplicate literals*)
110 lemma disj_forward2:
111     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
112 apply blast
113 done
115 lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
116 by blast
118 lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
119 by blast
122 section {* Clausification helper *}
124 lemma TruepropI: "P \<equiv> Q \<Longrightarrow> Trueprop P \<equiv> Trueprop Q"
125 by simp
128 text{* Combinator translation helpers *}
130 definition COMBI :: "'a \<Rightarrow> 'a" where
131 [no_atp]: "COMBI P = P"
133 definition COMBK :: "'a \<Rightarrow> 'b \<Rightarrow> 'a" where
134 [no_atp]: "COMBK P Q = P"
136 definition COMBB :: "('b => 'c) \<Rightarrow> ('a => 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where [no_atp]:
137 "COMBB P Q R = P (Q R)"
139 definition COMBC :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
140 [no_atp]: "COMBC P Q R = P R Q"
142 definition COMBS :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where
143 [no_atp]: "COMBS P Q R = P R (Q R)"
145 lemma abs_S [no_atp]: "\<lambda>x. (f x) (g x) \<equiv> COMBS f g"
146 apply (rule eq_reflection)
147 apply (rule ext)
149 done
151 lemma abs_I [no_atp]: "\<lambda>x. x \<equiv> COMBI"
152 apply (rule eq_reflection)
153 apply (rule ext)
155 done
157 lemma abs_K [no_atp]: "\<lambda>x. y \<equiv> COMBK y"
158 apply (rule eq_reflection)
159 apply (rule ext)
161 done
163 lemma abs_B [no_atp]: "\<lambda>x. a (g x) \<equiv> COMBB a g"
164 apply (rule eq_reflection)
165 apply (rule ext)
167 done
169 lemma abs_C [no_atp]: "\<lambda>x. (f x) b \<equiv> COMBC f b"
170 apply (rule eq_reflection)
171 apply (rule ext)
173 done
176 section {* Skolemization helpers *}
178 definition skolem :: "'a \<Rightarrow> 'a" where
179 [no_atp]: "skolem = (\<lambda>x. x)"
181 lemma skolem_COMBK_iff: "P \<longleftrightarrow> skolem (COMBK P (i\<Colon>nat))"
182 unfolding skolem_def COMBK_def by (rule refl)
184 lemmas skolem_COMBK_I = iffD1 [OF skolem_COMBK_iff]
185 lemmas skolem_COMBK_D = iffD2 [OF skolem_COMBK_iff]
188 section {* Meson package *}
190 ML {*
191 structure Meson_Choices = Named_Thms
192 (
193   val name = "meson_choice"
194   val description = "choice axioms for MESON's (and Metis's) skolemizer"
195 )
196 *}
198 use "Tools/Meson/meson.ML"
199 use "Tools/Meson/meson_clausify.ML"
201 setup {*
202   Meson_Choices.setup
203   #> Meson.setup
204   #> Meson_Clausify.setup
205 *}
207 end