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