move Meson to Plain
authorblanchet
Mon Oct 04 21:49:07 2010 +0200 (2010-10-04)
changeset 3994102fcd9cd1eac
parent 39940 1f01c9b2b76b
child 39942 1ae333bfef14
move Meson to Plain
src/HOL/Meson.thy
src/HOL/Plain.thy
src/HOL/Tools/Meson/meson.ML
src/HOL/Tools/Meson/meson_clausify.ML
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Meson.thy	Mon Oct 04 21:49:07 2010 +0200
     1.3 @@ -0,0 +1,205 @@
     1.4 +(*  Title:      HOL/Meson.thy
     1.5 +    Author:     Lawrence C Paulson, Tobias Nipkow
     1.6 +    Copyright   2001  University of Cambridge
     1.7 +*)
     1.8 +
     1.9 +header {* MESON Proof Procedure (Model Elimination) *}
    1.10 +
    1.11 +theory Meson
    1.12 +imports Nat
    1.13 +uses ("Tools/Meson/meson.ML")
    1.14 +     ("Tools/Meson/meson_clausify.ML")
    1.15 +begin
    1.16 +
    1.17 +section {* Negation Normal Form *}
    1.18 +
    1.19 +text {* de Morgan laws *}
    1.20 +
    1.21 +lemma meson_not_conjD: "~(P&Q) ==> ~P | ~Q"
    1.22 +  and meson_not_disjD: "~(P|Q) ==> ~P & ~Q"
    1.23 +  and meson_not_notD: "~~P ==> P"
    1.24 +  and meson_not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
    1.25 +  and meson_not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
    1.26 +  by fast+
    1.27 +
    1.28 +text {* Removal of @{text "-->"} and @{text "<->"} (positive and
    1.29 +negative occurrences) *}
    1.30 +
    1.31 +lemma meson_imp_to_disjD: "P-->Q ==> ~P | Q"
    1.32 +  and meson_not_impD: "~(P-->Q) ==> P & ~Q"
    1.33 +  and meson_iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
    1.34 +  and meson_not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
    1.35 +    -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
    1.36 +  and meson_not_refl_disj_D: "x ~= x | P ==> P"
    1.37 +  by fast+
    1.38 +
    1.39 +
    1.40 +section {* Pulling out the existential quantifiers *}
    1.41 +
    1.42 +text {* Conjunction *}
    1.43 +
    1.44 +lemma meson_conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
    1.45 +  and meson_conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
    1.46 +  by fast+
    1.47 +
    1.48 +
    1.49 +text {* Disjunction *}
    1.50 +
    1.51 +lemma meson_disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
    1.52 +  -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
    1.53 +  -- {* With ex-Skolemization, makes fewer Skolem constants *}
    1.54 +  and meson_disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
    1.55 +  and meson_disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
    1.56 +  by fast+
    1.57 +
    1.58 +lemma meson_disj_assoc: "(P|Q)|R ==> P|(Q|R)"
    1.59 +  and meson_disj_comm: "P|Q ==> Q|P"
    1.60 +  and meson_disj_FalseD1: "False|P ==> P"
    1.61 +  and meson_disj_FalseD2: "P|False ==> P"
    1.62 +  by fast+
    1.63 +
    1.64 +
    1.65 +text{* Generation of contrapositives *}
    1.66 +
    1.67 +text{*Inserts negated disjunct after removing the negation; P is a literal.
    1.68 +  Model elimination requires assuming the negation of every attempted subgoal,
    1.69 +  hence the negated disjuncts.*}
    1.70 +lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
    1.71 +by blast
    1.72 +
    1.73 +text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
    1.74 +lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
    1.75 +by blast
    1.76 +
    1.77 +text{*@{term P} should be a literal*}
    1.78 +lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
    1.79 +by blast
    1.80 +
    1.81 +text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
    1.82 +insert new assumptions, for ordinary resolution.*}
    1.83 +
    1.84 +lemmas make_neg_rule' = make_refined_neg_rule
    1.85 +
    1.86 +lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
    1.87 +by blast
    1.88 +
    1.89 +text{* Generation of a goal clause -- put away the final literal *}
    1.90 +
    1.91 +lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
    1.92 +by blast
    1.93 +
    1.94 +lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
    1.95 +by blast
    1.96 +
    1.97 +
    1.98 +section {* Lemmas for Forward Proof *}
    1.99 +
   1.100 +text{*There is a similarity to congruence rules*}
   1.101 +
   1.102 +(*NOTE: could handle conjunctions (faster?) by
   1.103 +    nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
   1.104 +lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
   1.105 +by blast
   1.106 +
   1.107 +lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
   1.108 +by blast
   1.109 +
   1.110 +(*Version of @{text disj_forward} for removal of duplicate literals*)
   1.111 +lemma disj_forward2:
   1.112 +    "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
   1.113 +apply blast 
   1.114 +done
   1.115 +
   1.116 +lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
   1.117 +by blast
   1.118 +
   1.119 +lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
   1.120 +by blast
   1.121 +
   1.122 +
   1.123 +section {* Clausification helper *}
   1.124 +
   1.125 +lemma TruepropI: "P \<equiv> Q \<Longrightarrow> Trueprop P \<equiv> Trueprop Q"
   1.126 +by simp
   1.127 +
   1.128 +
   1.129 +text{* Combinator translation helpers *}
   1.130 +
   1.131 +definition COMBI :: "'a \<Rightarrow> 'a" where
   1.132 +[no_atp]: "COMBI P = P"
   1.133 +
   1.134 +definition COMBK :: "'a \<Rightarrow> 'b \<Rightarrow> 'a" where
   1.135 +[no_atp]: "COMBK P Q = P"
   1.136 +
   1.137 +definition COMBB :: "('b => 'c) \<Rightarrow> ('a => 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where [no_atp]:
   1.138 +"COMBB P Q R = P (Q R)"
   1.139 +
   1.140 +definition COMBC :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
   1.141 +[no_atp]: "COMBC P Q R = P R Q"
   1.142 +
   1.143 +definition COMBS :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where
   1.144 +[no_atp]: "COMBS P Q R = P R (Q R)"
   1.145 +
   1.146 +lemma abs_S [no_atp]: "\<lambda>x. (f x) (g x) \<equiv> COMBS f g"
   1.147 +apply (rule eq_reflection)
   1.148 +apply (rule ext) 
   1.149 +apply (simp add: COMBS_def) 
   1.150 +done
   1.151 +
   1.152 +lemma abs_I [no_atp]: "\<lambda>x. x \<equiv> COMBI"
   1.153 +apply (rule eq_reflection)
   1.154 +apply (rule ext) 
   1.155 +apply (simp add: COMBI_def) 
   1.156 +done
   1.157 +
   1.158 +lemma abs_K [no_atp]: "\<lambda>x. y \<equiv> COMBK y"
   1.159 +apply (rule eq_reflection)
   1.160 +apply (rule ext) 
   1.161 +apply (simp add: COMBK_def) 
   1.162 +done
   1.163 +
   1.164 +lemma abs_B [no_atp]: "\<lambda>x. a (g x) \<equiv> COMBB a g"
   1.165 +apply (rule eq_reflection)
   1.166 +apply (rule ext) 
   1.167 +apply (simp add: COMBB_def) 
   1.168 +done
   1.169 +
   1.170 +lemma abs_C [no_atp]: "\<lambda>x. (f x) b \<equiv> COMBC f b"
   1.171 +apply (rule eq_reflection)
   1.172 +apply (rule ext) 
   1.173 +apply (simp add: COMBC_def) 
   1.174 +done
   1.175 +
   1.176 +
   1.177 +section {* Skolemization helpers *}
   1.178 +
   1.179 +definition skolem :: "'a \<Rightarrow> 'a" where
   1.180 +[no_atp]: "skolem = (\<lambda>x. x)"
   1.181 +
   1.182 +lemma skolem_COMBK_iff: "P \<longleftrightarrow> skolem (COMBK P (i\<Colon>nat))"
   1.183 +unfolding skolem_def COMBK_def by (rule refl)
   1.184 +
   1.185 +lemmas skolem_COMBK_I = iffD1 [OF skolem_COMBK_iff]
   1.186 +lemmas skolem_COMBK_D = iffD2 [OF skolem_COMBK_iff]
   1.187 +
   1.188 +
   1.189 +section {* Meson package *}
   1.190 +
   1.191 +ML {*
   1.192 +structure Meson_Choices = Named_Thms
   1.193 +(
   1.194 +  val name = "meson_choice"
   1.195 +  val description = "choice axioms for MESON's (and Metis's) skolemizer"
   1.196 +)
   1.197 +*}
   1.198 +
   1.199 +use "Tools/Meson/meson.ML"
   1.200 +use "Tools/Meson/meson_clausify.ML"
   1.201 +
   1.202 +setup {*
   1.203 +  Meson_Choices.setup
   1.204 +  #> Meson.setup
   1.205 +  #> Meson_Clausify.setup
   1.206 +*}
   1.207 +
   1.208 +end
     2.1 --- a/src/HOL/Plain.thy	Mon Oct 04 21:37:42 2010 +0200
     2.2 +++ b/src/HOL/Plain.thy	Mon Oct 04 21:49:07 2010 +0200
     2.3 @@ -1,7 +1,7 @@
     2.4  header {* Plain HOL *}
     2.5  
     2.6  theory Plain
     2.7 -imports Datatype FunDef Extraction
     2.8 +imports Datatype FunDef Extraction Meson
     2.9  begin
    2.10  
    2.11  text {*
     3.1 --- a/src/HOL/Tools/Meson/meson.ML	Mon Oct 04 21:37:42 2010 +0200
     3.2 +++ b/src/HOL/Tools/Meson/meson.ML	Mon Oct 04 21:49:07 2010 +0200
     3.3 @@ -1,5 +1,6 @@
     3.4 -(*  Title:      HOL/Tools/meson.ML
     3.5 +(*  Title:      HOL/Tools/Meson/meson.ML
     3.6      Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3.7 +    Author:     Jasmin Blanchette, TU Muenchen
     3.8  
     3.9  The MESON resolution proof procedure for HOL.
    3.10  When making clauses, avoids using the rewriter -- instead uses RS recursively.
     4.1 --- a/src/HOL/Tools/Meson/meson_clausify.ML	Mon Oct 04 21:37:42 2010 +0200
     4.2 +++ b/src/HOL/Tools/Meson/meson_clausify.ML	Mon Oct 04 21:49:07 2010 +0200
     4.3 @@ -1,8 +1,9 @@
     4.4 -(*  Title:      HOL/Tools/Sledgehammer/meson_clausify.ML
     4.5 +(*  Title:      HOL/Tools/Meson/meson_clausify.ML
     4.6      Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
     4.7      Author:     Jasmin Blanchette, TU Muenchen
     4.8  
     4.9 -Transformation of axiom rules (elim/intro/etc) into CNF forms.
    4.10 +Transformation of HOL theorems into CNF forms.
    4.11 +The "meson" proof method for HOL.
    4.12  *)
    4.13  
    4.14  signature MESON_CLAUSIFY =
    4.15 @@ -204,7 +205,7 @@
    4.16      val (hilbert, cabs) = ch |> Thm.dest_comb |>> term_of
    4.17      val T =
    4.18        case hilbert of
    4.19 -        Const (@{const_name Eps}, Type (@{type_name fun}, [_, T])) => T
    4.20 +        Const (_, Type (@{type_name fun}, [_, T])) => T
    4.21        | _ => raise TERM ("old_skolem_theorem_from_def: expected \"Eps\"",
    4.22                           [hilbert])
    4.23      val cex = cterm_of thy (HOLogic.exists_const T)
    4.24 @@ -214,7 +215,8 @@
    4.25        |> Drule.beta_conv cabs |> Thm.capply cTrueprop
    4.26      fun tacf [prem] =
    4.27        rewrite_goals_tac skolem_def_raw
    4.28 -      THEN rtac ((prem |> rewrite_rule skolem_def_raw) RS @{thm someI_ex}) 1
    4.29 +      THEN rtac ((prem |> rewrite_rule skolem_def_raw)
    4.30 +                 RS Global_Theory.get_thm thy "someI_ex") 1
    4.31    in
    4.32      Goal.prove_internal [ex_tm] conc tacf
    4.33      |> forall_intr_list frees