
blanchet@39941: (*  Title:      HOL/Meson.thy
blanchet@39944:     Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
blanchet@39944:     Author:     Tobias Nipkow, TU Muenchen
blanchet@39944:     Author:     Jasmin Blanchette, TU Muenchen
blanchet@39941:     Copyright   2001  University of Cambridge
blanchet@39941: *)
blanchet@39941: 
blanchet@39947: header {* MESON Proof Method *}
blanchet@39941: 
blanchet@39941: theory Meson
blanchet@54553: imports Nat
blanchet@39941: begin
blanchet@39941: 
huffman@40620: subsection {* Negation Normal Form *}
blanchet@39941: 
blanchet@39941: text {* de Morgan laws *}
blanchet@39941: 
blanchet@39953: lemma not_conjD: "~(P&Q) ==> ~P | ~Q"
blanchet@39953:   and not_disjD: "~(P|Q) ==> ~P & ~Q"
blanchet@39953:   and not_notD: "~~P ==> P"
blanchet@39953:   and not_allD: "!!P. ~(\<forall>x. P(x)) ==> \<exists>x. ~P(x)"
blanchet@39953:   and not_exD: "!!P. ~(\<exists>x. P(x)) ==> \<forall>x. ~P(x)"
blanchet@39941:   by fast+
blanchet@39941: 
blanchet@39941: text {* Removal of @{text "-->"} and @{text "<->"} (positive and
blanchet@39941: negative occurrences) *}
blanchet@39941: 
blanchet@39953: lemma imp_to_disjD: "P-->Q ==> ~P | Q"
blanchet@39953:   and not_impD: "~(P-->Q) ==> P & ~Q"
blanchet@39953:   and iff_to_disjD: "P=Q ==> (~P | Q) & (~Q | P)"
blanchet@39953:   and not_iffD: "~(P=Q) ==> (P | Q) & (~P | ~Q)"
blanchet@39941:     -- {* Much more efficient than @{prop "(P & ~Q) | (Q & ~P)"} for computing CNF *}
blanchet@39953:   and not_refl_disj_D: "x ~= x | P ==> P"
blanchet@39941:   by fast+
blanchet@39941: 
blanchet@39941: 
huffman@40620: subsection {* Pulling out the existential quantifiers *}
blanchet@39941: 
blanchet@39941: text {* Conjunction *}
blanchet@39941: 
blanchet@39953: lemma conj_exD1: "!!P Q. (\<exists>x. P(x)) & Q ==> \<exists>x. P(x) & Q"
blanchet@39953:   and conj_exD2: "!!P Q. P & (\<exists>x. Q(x)) ==> \<exists>x. P & Q(x)"
blanchet@39941:   by fast+
blanchet@39941: 
blanchet@39941: 
blanchet@39941: text {* Disjunction *}
blanchet@39941: 
blanchet@39953: lemma disj_exD: "!!P Q. (\<exists>x. P(x)) | (\<exists>x. Q(x)) ==> \<exists>x. P(x) | Q(x)"
blanchet@39941:   -- {* DO NOT USE with forall-Skolemization: makes fewer schematic variables!! *}
blanchet@39941:   -- {* With ex-Skolemization, makes fewer Skolem constants *}
blanchet@39953:   and disj_exD1: "!!P Q. (\<exists>x. P(x)) | Q ==> \<exists>x. P(x) | Q"
blanchet@39953:   and disj_exD2: "!!P Q. P | (\<exists>x. Q(x)) ==> \<exists>x. P | Q(x)"
blanchet@39941:   by fast+
blanchet@39941: 
blanchet@39953: lemma disj_assoc: "(P|Q)|R ==> P|(Q|R)"
blanchet@39953:   and disj_comm: "P|Q ==> Q|P"
blanchet@39953:   and disj_FalseD1: "False|P ==> P"
blanchet@39953:   and disj_FalseD2: "P|False ==> P"
blanchet@39941:   by fast+
blanchet@39941: 
blanchet@39941: 
blanchet@39941: text{* Generation of contrapositives *}
blanchet@39941: 
blanchet@39941: text{*Inserts negated disjunct after removing the negation; P is a literal.
blanchet@39941:   Model elimination requires assuming the negation of every attempted subgoal,
blanchet@39941:   hence the negated disjuncts.*}
blanchet@39941: lemma make_neg_rule: "~P|Q ==> ((~P==>P) ==> Q)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: text{*Version for Plaisted's "Postive refinement" of the Meson procedure*}
blanchet@39941: lemma make_refined_neg_rule: "~P|Q ==> (P ==> Q)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: text{*@{term P} should be a literal*}
blanchet@39941: lemma make_pos_rule: "P|Q ==> ((P==>~P) ==> Q)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: text{*Versions of @{text make_neg_rule} and @{text make_pos_rule} that don't
blanchet@39941: insert new assumptions, for ordinary resolution.*}
blanchet@39941: 
blanchet@39941: lemmas make_neg_rule' = make_refined_neg_rule
blanchet@39941: 
blanchet@39941: lemma make_pos_rule': "[|P|Q; ~P|] ==> Q"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: text{* Generation of a goal clause -- put away the final literal *}
blanchet@39941: 
blanchet@39941: lemma make_neg_goal: "~P ==> ((~P==>P) ==> False)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: lemma make_pos_goal: "P ==> ((P==>~P) ==> False)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: 
huffman@40620: subsection {* Lemmas for Forward Proof *}
blanchet@39941: 
blanchet@39941: text{*There is a similarity to congruence rules*}
blanchet@39941: 
blanchet@39941: (*NOTE: could handle conjunctions (faster?) by
blanchet@39941:     nf(th RS conjunct2) RS (nf(th RS conjunct1) RS conjI) *)
blanchet@39941: lemma conj_forward: "[| P'&Q';  P' ==> P;  Q' ==> Q |] ==> P&Q"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: lemma disj_forward: "[| P'|Q';  P' ==> P;  Q' ==> Q |] ==> P|Q"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: (*Version of @{text disj_forward} for removal of duplicate literals*)
blanchet@39941: lemma disj_forward2:
blanchet@39941:     "[| P'|Q';  P' ==> P;  [| Q'; P==>False |] ==> Q |] ==> P|Q"
blanchet@39941: apply blast 
blanchet@39941: done
blanchet@39941: 
blanchet@39941: lemma all_forward: "[| \<forall>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<forall>x. P(x)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: lemma ex_forward: "[| \<exists>x. P'(x);  !!x. P'(x) ==> P(x) |] ==> \<exists>x. P(x)"
blanchet@39941: by blast
blanchet@39941: 
blanchet@39941: 
huffman@40620: subsection {* Clausification helper *}
blanchet@39941: 
blanchet@39941: lemma TruepropI: "P \<equiv> Q \<Longrightarrow> Trueprop P \<equiv> Trueprop Q"
blanchet@39941: by simp
blanchet@39941: 
blanchet@47953: lemma ext_cong_neq: "F g \<noteq> F h \<Longrightarrow> F g \<noteq> F h \<and> (\<exists>x. g x \<noteq> h x)"
blanchet@47953: apply (erule contrapos_np)
blanchet@47953: apply clarsimp
blanchet@47953: apply (rule cong[where f = F])
blanchet@47953: by auto
blanchet@47953: 
blanchet@39941: 
blanchet@39941: text{* Combinator translation helpers *}
blanchet@39941: 
blanchet@39941: definition COMBI :: "'a \<Rightarrow> 'a" where
blanchet@54148: "COMBI P = P"
blanchet@39941: 
blanchet@39941: definition COMBK :: "'a \<Rightarrow> 'b \<Rightarrow> 'a" where
blanchet@54148: "COMBK P Q = P"
blanchet@39941: 
blanchet@54148: definition COMBB :: "('b => 'c) \<Rightarrow> ('a => 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where
blanchet@39941: "COMBB P Q R = P (Q R)"
blanchet@39941: 
blanchet@39941: definition COMBC :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
blanchet@54148: "COMBC P Q R = P R Q"
blanchet@39941: 
blanchet@39941: definition COMBS :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'c" where
blanchet@54148: "COMBS P Q R = P R (Q R)"
blanchet@39941: 
blanchet@54148: lemma abs_S: "\<lambda>x. (f x) (g x) \<equiv> COMBS f g"
blanchet@39941: apply (rule eq_reflection)
blanchet@39941: apply (rule ext) 
blanchet@39941: apply (simp add: COMBS_def) 
blanchet@39941: done
blanchet@39941: 
blanchet@54148: lemma abs_I: "\<lambda>x. x \<equiv> COMBI"
blanchet@39941: apply (rule eq_reflection)
blanchet@39941: apply (rule ext) 
blanchet@39941: apply (simp add: COMBI_def) 
blanchet@39941: done
blanchet@39941: 
blanchet@54148: lemma abs_K: "\<lambda>x. y \<equiv> COMBK y"
blanchet@39941: apply (rule eq_reflection)
blanchet@39941: apply (rule ext) 
blanchet@39941: apply (simp add: COMBK_def) 
blanchet@39941: done
blanchet@39941: 
blanchet@54148: lemma abs_B: "\<lambda>x. a (g x) \<equiv> COMBB a g"
blanchet@39941: apply (rule eq_reflection)
blanchet@39941: apply (rule ext) 
blanchet@39941: apply (simp add: COMBB_def) 
blanchet@39941: done
blanchet@39941: 
blanchet@54148: lemma abs_C: "\<lambda>x. (f x) b \<equiv> COMBC f b"
blanchet@39941: apply (rule eq_reflection)
blanchet@39941: apply (rule ext) 
blanchet@39941: apply (simp add: COMBC_def) 
blanchet@39941: done
blanchet@39941: 
blanchet@39941: 
huffman@40620: subsection {* Skolemization helpers *}
blanchet@39941: 
blanchet@39941: definition skolem :: "'a \<Rightarrow> 'a" where
blanchet@54148: "skolem = (\<lambda>x. x)"
blanchet@39941: 
blanchet@39941: lemma skolem_COMBK_iff: "P \<longleftrightarrow> skolem (COMBK P (i\<Colon>nat))"
blanchet@39941: unfolding skolem_def COMBK_def by (rule refl)
blanchet@39941: 
blanchet@39941: lemmas skolem_COMBK_I = iffD1 [OF skolem_COMBK_iff]
blanchet@39941: lemmas skolem_COMBK_D = iffD2 [OF skolem_COMBK_iff]
blanchet@39941: 
blanchet@39941: 
huffman@40620: subsection {* Meson package *}
blanchet@39941: 
wenzelm@48891: ML_file "Tools/Meson/meson.ML"
wenzelm@48891: ML_file "Tools/Meson/meson_clausify.ML"
wenzelm@48891: ML_file "Tools/Meson/meson_tactic.ML"
blanchet@39941: 
wenzelm@42616: setup {* Meson_Tactic.setup *}
blanchet@39941: 
blanchet@39953: hide_const (open) COMBI COMBK COMBB COMBC COMBS skolem
blanchet@39953: hide_fact (open) not_conjD not_disjD not_notD not_allD not_exD imp_to_disjD
blanchet@39953:     not_impD iff_to_disjD not_iffD not_refl_disj_D conj_exD1 conj_exD2 disj_exD
blanchet@39953:     disj_exD1 disj_exD2 disj_assoc disj_comm disj_FalseD1 disj_FalseD2 TruepropI
blanchet@47953:     ext_cong_neq COMBI_def COMBK_def COMBB_def COMBC_def COMBS_def abs_I abs_K
blanchet@47953:     abs_B abs_C abs_S skolem_def skolem_COMBK_iff skolem_COMBK_I skolem_COMBK_D
blanchet@39953: 
blanchet@39941: end




