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