src/HOL/Meson.thy
author blanchet
Tue Oct 05 11:45:10 2010 +0200 (2010-10-05)
changeset 39953 aa54f347e5e2
parent 39950 f3c4849868b8
child 40620 7a9278de19ad
permissions -rw-r--r--
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
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@39947
     8
header {* MESON Proof Method *}
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@39948
    14
     ("Tools/Meson/meson_tactic.ML")
blanchet@39941
    15
begin
blanchet@39941
    16
blanchet@39941
    17
section {* Negation Normal Form *}
blanchet@39941
    18
blanchet@39941
    19
text {* de Morgan laws *}
blanchet@39941
    20
blanchet@39953
    21
lemma not_conjD: "~(P&Q) ==> ~P | ~Q"
blanchet@39953
    22
  and not_disjD: "~(P|Q) ==> ~P & ~Q"
blanchet@39953
    23
  and not_notD: "~~P ==> P"
blanchet@39953
    24
  and not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
blanchet@39953
    25
  and not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
blanchet@39941
    26
  by fast+
blanchet@39941
    27
blanchet@39941
    28
text {* Removal of @{text "-->"} and @{text "<->"} (positive and
blanchet@39941
    29
negative occurrences) *}
blanchet@39941
    30
blanchet@39953
    31
lemma imp_to_disjD: "P-->Q ==> ~P | Q"
blanchet@39953
    32
  and not_impD: "~(P-->Q) ==> P & ~Q"
blanchet@39953
    33
  and iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
blanchet@39953
    34
  and not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
blanchet@39941
    35
    -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
blanchet@39953
    36
  and not_refl_disj_D: "x ~= x | P ==> P"
blanchet@39941
    37
  by fast+
blanchet@39941
    38
blanchet@39941
    39
blanchet@39941
    40
section {* Pulling out the existential quantifiers *}
blanchet@39941
    41
blanchet@39941
    42
text {* Conjunction *}
blanchet@39941
    43
blanchet@39953
    44
lemma conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
blanchet@39953
    45
  and conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
blanchet@39941
    46
  by fast+
blanchet@39941
    47
blanchet@39941
    48
blanchet@39941
    49
text {* Disjunction *}
blanchet@39941
    50
blanchet@39953
    51
lemma disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
blanchet@39941
    52
  -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
blanchet@39941
    53
  -- {* With ex-Skolemization, makes fewer Skolem constants *}
blanchet@39953
    54
  and disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
blanchet@39953
    55
  and disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
blanchet@39941
    56
  by fast+
blanchet@39941
    57
blanchet@39953
    58
lemma disj_assoc: "(P|Q)|R ==> P|(Q|R)"
blanchet@39953
    59
  and disj_comm: "P|Q ==> Q|P"
blanchet@39953
    60
  and disj_FalseD1: "False|P ==> P"
blanchet@39953
    61
  and disj_FalseD2: "P|False ==> P"
blanchet@39941
    62
  by fast+
blanchet@39941
    63
blanchet@39941
    64
blanchet@39941
    65
text{* Generation of contrapositives *}
blanchet@39941
    66
blanchet@39941
    67
text{*Inserts negated disjunct after removing the negation; P is a literal.
blanchet@39941
    68
  Model elimination requires assuming the negation of every attempted subgoal,
blanchet@39941
    69
  hence the negated disjuncts.*}
blanchet@39941
    70
lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
blanchet@39941
    71
by blast
blanchet@39941
    72
blanchet@39941
    73
text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
blanchet@39941
    74
lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
blanchet@39941
    75
by blast
blanchet@39941
    76
blanchet@39941
    77
text{*@{term P} should be a literal*}
blanchet@39941
    78
lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
blanchet@39941
    79
by blast
blanchet@39941
    80
blanchet@39941
    81
text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
blanchet@39941
    82
insert new assumptions, for ordinary resolution.*}
blanchet@39941
    83
blanchet@39941
    84
lemmas make_neg_rule' = make_refined_neg_rule
blanchet@39941
    85
blanchet@39941
    86
lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
blanchet@39941
    87
by blast
blanchet@39941
    88
blanchet@39941
    89
text{* Generation of a goal clause -- put away the final literal *}
blanchet@39941
    90
blanchet@39941
    91
lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
blanchet@39941
    92
by blast
blanchet@39941
    93
blanchet@39941
    94
lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
blanchet@39941
    95
by blast
blanchet@39941
    96
blanchet@39941
    97
blanchet@39941
    98
section {* Lemmas for Forward Proof *}
blanchet@39941
    99
blanchet@39941
   100
text{*There is a similarity to congruence rules*}
blanchet@39941
   101
blanchet@39941
   102
(*NOTE: could handle conjunctions (faster?) by
blanchet@39941
   103
    nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
blanchet@39941
   104
lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
blanchet@39941
   105
by blast
blanchet@39941
   106
blanchet@39941
   107
lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
blanchet@39941
   108
by blast
blanchet@39941
   109
blanchet@39941
   110
(*Version of @{text disj_forward} for removal of duplicate literals*)
blanchet@39941
   111
lemma disj_forward2:
blanchet@39941
   112
    "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
blanchet@39941
   113
apply blast 
blanchet@39941
   114
done
blanchet@39941
   115
blanchet@39941
   116
lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
blanchet@39941
   117
by blast
blanchet@39941
   118
blanchet@39941
   119
lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
blanchet@39941
   120
by blast
blanchet@39941
   121
blanchet@39941
   122
blanchet@39941
   123
section {* Clausification helper *}
blanchet@39941
   124
blanchet@39941
   125
lemma TruepropI: "P \<equiv> Q \<Longrightarrow> Trueprop P \<equiv> Trueprop Q"
blanchet@39941
   126
by simp
blanchet@39941
   127
blanchet@39941
   128
blanchet@39941
   129
text{* Combinator translation helpers *}
blanchet@39941
   130
blanchet@39941
   131
definition COMBI :: "'a \<Rightarrow> 'a" where
blanchet@39941
   132
[no_atp]: "COMBI P = P"
blanchet@39941
   133
blanchet@39941
   134
definition COMBK :: "'a \<Rightarrow> 'b \<Rightarrow> 'a" where
blanchet@39941
   135
[no_atp]: "COMBK P Q = P"
blanchet@39941
   136
blanchet@39941
   137
definition COMBB :: "('b => 'c) \<Rightarrow> ('a => 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where [no_atp]:
blanchet@39941
   138
"COMBB P Q R = P (Q R)"
blanchet@39941
   139
blanchet@39941
   140
definition COMBC :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
blanchet@39941
   141
[no_atp]: "COMBC P Q R = P R Q"
blanchet@39941
   142
blanchet@39941
   143
definition COMBS :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where
blanchet@39941
   144
[no_atp]: "COMBS P Q R = P R (Q R)"
blanchet@39941
   145
blanchet@39941
   146
lemma abs_S [no_atp]: "\<lambda>x. (f x) (g x) \<equiv> COMBS f g"
blanchet@39941
   147
apply (rule eq_reflection)
blanchet@39941
   148
apply (rule ext) 
blanchet@39941
   149
apply (simp add: COMBS_def) 
blanchet@39941
   150
done
blanchet@39941
   151
blanchet@39941
   152
lemma abs_I [no_atp]: "\<lambda>x. x \<equiv> COMBI"
blanchet@39941
   153
apply (rule eq_reflection)
blanchet@39941
   154
apply (rule ext) 
blanchet@39941
   155
apply (simp add: COMBI_def) 
blanchet@39941
   156
done
blanchet@39941
   157
blanchet@39941
   158
lemma abs_K [no_atp]: "\<lambda>x. y \<equiv> COMBK y"
blanchet@39941
   159
apply (rule eq_reflection)
blanchet@39941
   160
apply (rule ext) 
blanchet@39941
   161
apply (simp add: COMBK_def) 
blanchet@39941
   162
done
blanchet@39941
   163
blanchet@39941
   164
lemma abs_B [no_atp]: "\<lambda>x. a (g x) \<equiv> COMBB a g"
blanchet@39941
   165
apply (rule eq_reflection)
blanchet@39941
   166
apply (rule ext) 
blanchet@39941
   167
apply (simp add: COMBB_def) 
blanchet@39941
   168
done
blanchet@39941
   169
blanchet@39941
   170
lemma abs_C [no_atp]: "\<lambda>x. (f x) b \<equiv> COMBC f b"
blanchet@39941
   171
apply (rule eq_reflection)
blanchet@39941
   172
apply (rule ext) 
blanchet@39941
   173
apply (simp add: COMBC_def) 
blanchet@39941
   174
done
blanchet@39941
   175
blanchet@39941
   176
blanchet@39941
   177
section {* Skolemization helpers *}
blanchet@39941
   178
blanchet@39941
   179
definition skolem :: "'a \<Rightarrow> 'a" where
blanchet@39941
   180
[no_atp]: "skolem = (\<lambda>x. x)"
blanchet@39941
   181
blanchet@39941
   182
lemma skolem_COMBK_iff: "P \<longleftrightarrow> skolem (COMBK P (i\<Colon>nat))"
blanchet@39941
   183
unfolding skolem_def COMBK_def by (rule refl)
blanchet@39941
   184
blanchet@39941
   185
lemmas skolem_COMBK_I = iffD1 [OF skolem_COMBK_iff]
blanchet@39941
   186
lemmas skolem_COMBK_D = iffD2 [OF skolem_COMBK_iff]
blanchet@39941
   187
blanchet@39941
   188
blanchet@39941
   189
section {* Meson package *}
blanchet@39941
   190
blanchet@39941
   191
use "Tools/Meson/meson.ML"
blanchet@39941
   192
use "Tools/Meson/meson_clausify.ML"
blanchet@39948
   193
use "Tools/Meson/meson_tactic.ML"
blanchet@39941
   194
blanchet@39941
   195
setup {*
blanchet@39950
   196
  Meson.setup
blanchet@39948
   197
  #> Meson_Tactic.setup
blanchet@39941
   198
*}
blanchet@39941
   199
blanchet@39953
   200
hide_const (open) COMBI COMBK COMBB COMBC COMBS skolem
blanchet@39953
   201
hide_fact (open) not_conjD not_disjD not_notD not_allD not_exD imp_to_disjD
blanchet@39953
   202
    not_impD iff_to_disjD not_iffD not_refl_disj_D conj_exD1 conj_exD2 disj_exD
blanchet@39953
   203
    disj_exD1 disj_exD2 disj_assoc disj_comm disj_FalseD1 disj_FalseD2 TruepropI
blanchet@39953
   204
    COMBI_def COMBK_def COMBB_def COMBC_def COMBS_def abs_I abs_K abs_B abs_C
blanchet@39953
   205
    abs_S skolem_def skolem_COMBK_iff skolem_COMBK_I skolem_COMBK_D
blanchet@39953
   206
blanchet@39941
   207
end