src/FOL/IFOL.thy
author wenzelm
Fri Jan 01 10:49:00 2016 +0100 (2016-01-01)
changeset 62020 5d208fd2507d
parent 61490 7c9c54eb9658
child 63901 4ce989e962e0
permissions -rw-r--r--
isabelle update_cartouches -c -t;
clasohm@1268
     1
(*  Title:      FOL/IFOL.thy
wenzelm@11677
     2
    Author:     Lawrence C Paulson and Markus Wenzel
wenzelm@11677
     3
*)
lcp@35
     4
wenzelm@60770
     5
section \<open>Intuitionistic first-order logic\<close>
lcp@35
     6
paulson@15481
     7
theory IFOL
paulson@15481
     8
imports Pure
paulson@15481
     9
begin
wenzelm@7355
    10
wenzelm@48891
    11
ML_file "~~/src/Tools/misc_legacy.ML"
wenzelm@48891
    12
ML_file "~~/src/Provers/splitter.ML"
wenzelm@48891
    13
ML_file "~~/src/Provers/hypsubst.ML"
wenzelm@48891
    14
ML_file "~~/src/Tools/IsaPlanner/zipper.ML"
wenzelm@48891
    15
ML_file "~~/src/Tools/IsaPlanner/isand.ML"
wenzelm@48891
    16
ML_file "~~/src/Tools/IsaPlanner/rw_inst.ML"
wenzelm@48891
    17
ML_file "~~/src/Provers/quantifier1.ML"
wenzelm@48891
    18
ML_file "~~/src/Tools/intuitionistic.ML"
wenzelm@48891
    19
ML_file "~~/src/Tools/project_rule.ML"
wenzelm@48891
    20
ML_file "~~/src/Tools/atomize_elim.ML"
wenzelm@48891
    21
clasohm@0
    22
wenzelm@60770
    23
subsection \<open>Syntax and axiomatic basis\<close>
wenzelm@11677
    24
wenzelm@39557
    25
setup Pure_Thy.old_appl_syntax_setup
wenzelm@26956
    26
wenzelm@55380
    27
class "term"
wenzelm@36452
    28
default_sort "term"
clasohm@0
    29
wenzelm@7355
    30
typedecl o
wenzelm@79
    31
wenzelm@11747
    32
judgment
wenzelm@61487
    33
  Trueprop :: "o \<Rightarrow> prop"  ("(_)" 5)
clasohm@0
    34
wenzelm@79
    35
wenzelm@60770
    36
subsubsection \<open>Equality\<close>
lcp@35
    37
wenzelm@46972
    38
axiomatization
wenzelm@61487
    39
  eq :: "['a, 'a] \<Rightarrow> o"  (infixl "=" 50)
wenzelm@46972
    40
where
wenzelm@61487
    41
  refl: "a = a" and
wenzelm@61487
    42
  subst: "a = b \<Longrightarrow> P(a) \<Longrightarrow> P(b)"
wenzelm@79
    43
clasohm@0
    44
wenzelm@60770
    45
subsubsection \<open>Propositional logic\<close>
wenzelm@46972
    46
wenzelm@46972
    47
axiomatization
wenzelm@46972
    48
  False :: o and
wenzelm@61487
    49
  conj :: "[o, o] => o"  (infixr "\<and>" 35) and
wenzelm@61487
    50
  disj :: "[o, o] => o"  (infixr "\<or>" 30) and
wenzelm@61487
    51
  imp :: "[o, o] => o"  (infixr "\<longrightarrow>" 25)
wenzelm@46972
    52
where
wenzelm@61487
    53
  conjI: "\<lbrakk>P;  Q\<rbrakk> \<Longrightarrow> P \<and> Q" and
wenzelm@61487
    54
  conjunct1: "P \<and> Q \<Longrightarrow> P" and
wenzelm@61487
    55
  conjunct2: "P \<and> Q \<Longrightarrow> Q" and
wenzelm@46972
    56
wenzelm@61487
    57
  disjI1: "P \<Longrightarrow> P \<or> Q" and
wenzelm@61487
    58
  disjI2: "Q \<Longrightarrow> P \<or> Q" and
wenzelm@61487
    59
  disjE: "\<lbrakk>P \<or> Q; P \<Longrightarrow> R; Q \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R" and
wenzelm@46972
    60
wenzelm@61487
    61
  impI: "(P \<Longrightarrow> Q) \<Longrightarrow> P \<longrightarrow> Q" and
wenzelm@61487
    62
  mp: "\<lbrakk>P \<longrightarrow> Q; P\<rbrakk> \<Longrightarrow> Q" and
wenzelm@46972
    63
wenzelm@61487
    64
  FalseE: "False \<Longrightarrow> P"
wenzelm@46972
    65
wenzelm@46972
    66
wenzelm@60770
    67
subsubsection \<open>Quantifiers\<close>
wenzelm@46972
    68
wenzelm@46972
    69
axiomatization
wenzelm@61487
    70
  All :: "('a \<Rightarrow> o) \<Rightarrow> o"  (binder "\<forall>" 10) and
wenzelm@61487
    71
  Ex :: "('a \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>" 10)
wenzelm@46972
    72
where
wenzelm@61487
    73
  allI: "(\<And>x. P(x)) \<Longrightarrow> (\<forall>x. P(x))" and
wenzelm@61487
    74
  spec: "(\<forall>x. P(x)) \<Longrightarrow> P(x)" and
wenzelm@61487
    75
  exI: "P(x) \<Longrightarrow> (\<exists>x. P(x))" and
wenzelm@61487
    76
  exE: "\<lbrakk>\<exists>x. P(x); \<And>x. P(x) \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
wenzelm@46972
    77
wenzelm@46972
    78
wenzelm@60770
    79
subsubsection \<open>Definitions\<close>
wenzelm@46972
    80
wenzelm@61487
    81
definition "True \<equiv> False \<longrightarrow> False"
wenzelm@61487
    82
wenzelm@61487
    83
definition Not ("\<not> _" [40] 40)
wenzelm@61487
    84
  where not_def: "\<not> P \<equiv> P \<longrightarrow> False"
wenzelm@46972
    85
wenzelm@61487
    86
definition iff  (infixr "\<longleftrightarrow>" 25)
wenzelm@61487
    87
  where "P \<longleftrightarrow> Q \<equiv> (P \<longrightarrow> Q) \<and> (Q \<longrightarrow> P)"
wenzelm@61487
    88
wenzelm@61487
    89
definition Ex1 :: "('a \<Rightarrow> o) \<Rightarrow> o"  (binder "\<exists>!" 10)
wenzelm@61487
    90
  where ex1_def: "\<exists>!x. P(x) \<equiv> \<exists>x. P(x) \<and> (\<forall>y. P(y) \<longrightarrow> y = x)"
wenzelm@46972
    91
wenzelm@62020
    92
axiomatization where  \<comment> \<open>Reflection, admissible\<close>
wenzelm@61487
    93
  eq_reflection: "(x = y) \<Longrightarrow> (x \<equiv> y)" and
wenzelm@61487
    94
  iff_reflection: "(P \<longleftrightarrow> Q) \<Longrightarrow> (P \<equiv> Q)"
wenzelm@61487
    95
wenzelm@61487
    96
abbreviation not_equal :: "['a, 'a] \<Rightarrow> o"  (infixl "\<noteq>" 50)
wenzelm@61487
    97
  where "x \<noteq> y \<equiv> \<not> (x = y)"
wenzelm@46972
    98
wenzelm@46972
    99
wenzelm@61487
   100
subsubsection \<open>Old-style ASCII syntax\<close>
wenzelm@79
   101
wenzelm@61487
   102
notation (ASCII)
wenzelm@61487
   103
  not_equal  (infixl "~=" 50) and
wenzelm@61487
   104
  Not  ("~ _" [40] 40) and
wenzelm@61487
   105
  conj  (infixr "&" 35) and
wenzelm@61487
   106
  disj  (infixr "|" 30) and
wenzelm@61487
   107
  All  (binder "ALL " 10) and
wenzelm@61487
   108
  Ex  (binder "EX " 10) and
wenzelm@61487
   109
  Ex1  (binder "EX! " 10) and
wenzelm@61487
   110
  imp  (infixr "-->" 25) and
wenzelm@61487
   111
  iff  (infixr "<->" 25)
lcp@35
   112
paulson@13779
   113
wenzelm@60770
   114
subsection \<open>Lemmas and proof tools\<close>
wenzelm@11677
   115
wenzelm@46972
   116
lemmas strip = impI allI
wenzelm@46972
   117
wenzelm@21539
   118
lemma TrueI: True
wenzelm@21539
   119
  unfolding True_def by (rule impI)
wenzelm@21539
   120
wenzelm@21539
   121
wenzelm@62020
   122
subsubsection \<open>Sequent-style elimination rules for \<open>\<and>\<close> \<open>\<longrightarrow>\<close> and \<open>\<forall>\<close>\<close>
wenzelm@21539
   123
wenzelm@21539
   124
lemma conjE:
wenzelm@61487
   125
  assumes major: "P \<and> Q"
wenzelm@61487
   126
    and r: "\<lbrakk>P; Q\<rbrakk> \<Longrightarrow> R"
wenzelm@21539
   127
  shows R
wenzelm@21539
   128
  apply (rule r)
wenzelm@21539
   129
   apply (rule major [THEN conjunct1])
wenzelm@21539
   130
  apply (rule major [THEN conjunct2])
wenzelm@21539
   131
  done
wenzelm@21539
   132
wenzelm@21539
   133
lemma impE:
wenzelm@61487
   134
  assumes major: "P \<longrightarrow> Q"
wenzelm@21539
   135
    and P
wenzelm@61487
   136
  and r: "Q \<Longrightarrow> R"
wenzelm@21539
   137
  shows R
wenzelm@21539
   138
  apply (rule r)
wenzelm@21539
   139
  apply (rule major [THEN mp])
wenzelm@60770
   140
  apply (rule \<open>P\<close>)
wenzelm@21539
   141
  done
wenzelm@21539
   142
wenzelm@21539
   143
lemma allE:
wenzelm@61487
   144
  assumes major: "\<forall>x. P(x)"
wenzelm@61487
   145
    and r: "P(x) \<Longrightarrow> R"
wenzelm@21539
   146
  shows R
wenzelm@21539
   147
  apply (rule r)
wenzelm@21539
   148
  apply (rule major [THEN spec])
wenzelm@21539
   149
  done
wenzelm@21539
   150
wenzelm@61487
   151
text \<open>Duplicates the quantifier; for use with @{ML eresolve_tac}.\<close>
wenzelm@21539
   152
lemma all_dupE:
wenzelm@61487
   153
  assumes major: "\<forall>x. P(x)"
wenzelm@61487
   154
    and r: "\<lbrakk>P(x); \<forall>x. P(x)\<rbrakk> \<Longrightarrow> R"
wenzelm@21539
   155
  shows R
wenzelm@21539
   156
  apply (rule r)
wenzelm@21539
   157
   apply (rule major [THEN spec])
wenzelm@21539
   158
  apply (rule major)
wenzelm@21539
   159
  done
wenzelm@21539
   160
wenzelm@21539
   161
wenzelm@62020
   162
subsubsection \<open>Negation rules, which translate between \<open>\<not> P\<close> and \<open>P \<longrightarrow> False\<close>\<close>
wenzelm@21539
   163
wenzelm@61487
   164
lemma notI: "(P \<Longrightarrow> False) \<Longrightarrow> \<not> P"
wenzelm@21539
   165
  unfolding not_def by (erule impI)
wenzelm@21539
   166
wenzelm@61487
   167
lemma notE: "\<lbrakk>\<not> P; P\<rbrakk> \<Longrightarrow> R"
wenzelm@21539
   168
  unfolding not_def by (erule mp [THEN FalseE])
wenzelm@21539
   169
wenzelm@61487
   170
lemma rev_notE: "\<lbrakk>P; \<not> P\<rbrakk> \<Longrightarrow> R"
wenzelm@21539
   171
  by (erule notE)
wenzelm@21539
   172
wenzelm@62020
   173
text \<open>This is useful with the special implication rules for each kind of \<open>P\<close>.\<close>
wenzelm@21539
   174
lemma not_to_imp:
wenzelm@61487
   175
  assumes "\<not> P"
wenzelm@61487
   176
    and r: "P \<longrightarrow> False \<Longrightarrow> Q"
wenzelm@21539
   177
  shows Q
wenzelm@21539
   178
  apply (rule r)
wenzelm@21539
   179
  apply (rule impI)
wenzelm@61487
   180
  apply (erule notE [OF \<open>\<not> P\<close>])
wenzelm@21539
   181
  done
wenzelm@21539
   182
wenzelm@61487
   183
text \<open>
wenzelm@62020
   184
  For substitution into an assumption \<open>P\<close>, reduce \<open>Q\<close> to \<open>P \<longrightarrow> Q\<close>, substitute into this implication, then apply \<open>impI\<close> to
wenzelm@62020
   185
  move \<open>P\<close> back into the assumptions.
wenzelm@61487
   186
\<close>
wenzelm@61487
   187
lemma rev_mp: "\<lbrakk>P; P \<longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
wenzelm@21539
   188
  by (erule mp)
wenzelm@21539
   189
wenzelm@61487
   190
text \<open>Contrapositive of an inference rule.\<close>
wenzelm@21539
   191
lemma contrapos:
wenzelm@61487
   192
  assumes major: "\<not> Q"
wenzelm@61487
   193
    and minor: "P \<Longrightarrow> Q"
wenzelm@61487
   194
  shows "\<not> P"
wenzelm@21539
   195
  apply (rule major [THEN notE, THEN notI])
wenzelm@21539
   196
  apply (erule minor)
wenzelm@21539
   197
  done
wenzelm@21539
   198
wenzelm@21539
   199
wenzelm@61487
   200
subsubsection \<open>Modus Ponens Tactics\<close>
wenzelm@21539
   201
wenzelm@61487
   202
text \<open>
wenzelm@62020
   203
  Finds \<open>P \<longrightarrow> Q\<close> and P in the assumptions, replaces implication by
wenzelm@62020
   204
  \<open>Q\<close>.
wenzelm@61487
   205
\<close>
wenzelm@60770
   206
ML \<open>
wenzelm@61487
   207
  fun mp_tac ctxt i =
wenzelm@61487
   208
    eresolve_tac ctxt @{thms notE impE} i THEN assume_tac ctxt i;
wenzelm@61487
   209
  fun eq_mp_tac ctxt i =
wenzelm@61487
   210
    eresolve_tac ctxt @{thms notE impE} i THEN eq_assume_tac i;
wenzelm@60770
   211
\<close>
wenzelm@21539
   212
wenzelm@21539
   213
wenzelm@61487
   214
subsection \<open>If-and-only-if\<close>
wenzelm@21539
   215
wenzelm@61487
   216
lemma iffI: "\<lbrakk>P \<Longrightarrow> Q; Q \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P \<longleftrightarrow> Q"
wenzelm@21539
   217
  apply (unfold iff_def)
wenzelm@21539
   218
  apply (rule conjI)
wenzelm@21539
   219
   apply (erule impI)
wenzelm@21539
   220
  apply (erule impI)
wenzelm@21539
   221
  done
wenzelm@21539
   222
wenzelm@21539
   223
lemma iffE:
wenzelm@61487
   224
  assumes major: "P \<longleftrightarrow> Q"
wenzelm@61487
   225
    and r: "P \<longrightarrow> Q \<Longrightarrow> Q \<longrightarrow> P \<Longrightarrow> R"
wenzelm@21539
   226
  shows R
wenzelm@21539
   227
  apply (insert major, unfold iff_def)
wenzelm@21539
   228
  apply (erule conjE)
wenzelm@21539
   229
  apply (erule r)
wenzelm@21539
   230
  apply assumption
wenzelm@21539
   231
  done
wenzelm@21539
   232
wenzelm@21539
   233
wenzelm@62020
   234
subsubsection \<open>Destruct rules for \<open>\<longleftrightarrow>\<close> similar to Modus Ponens\<close>
wenzelm@61487
   235
wenzelm@61487
   236
lemma iffD1: "\<lbrakk>P \<longleftrightarrow> Q; P\<rbrakk> \<Longrightarrow> Q"
wenzelm@21539
   237
  apply (unfold iff_def)
wenzelm@21539
   238
  apply (erule conjunct1 [THEN mp])
wenzelm@21539
   239
  apply assumption
wenzelm@21539
   240
  done
wenzelm@21539
   241
wenzelm@61487
   242
lemma iffD2: "\<lbrakk>P \<longleftrightarrow> Q; Q\<rbrakk> \<Longrightarrow> P"
wenzelm@21539
   243
  apply (unfold iff_def)
wenzelm@21539
   244
  apply (erule conjunct2 [THEN mp])
wenzelm@21539
   245
  apply assumption
wenzelm@21539
   246
  done
wenzelm@21539
   247
wenzelm@61487
   248
lemma rev_iffD1: "\<lbrakk>P; P \<longleftrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
wenzelm@21539
   249
  apply (erule iffD1)
wenzelm@21539
   250
  apply assumption
wenzelm@21539
   251
  done
wenzelm@21539
   252
wenzelm@61487
   253
lemma rev_iffD2: "\<lbrakk>Q; P \<longleftrightarrow> Q\<rbrakk> \<Longrightarrow> P"
wenzelm@21539
   254
  apply (erule iffD2)
wenzelm@21539
   255
  apply assumption
wenzelm@21539
   256
  done
wenzelm@21539
   257
wenzelm@61487
   258
lemma iff_refl: "P \<longleftrightarrow> P"
wenzelm@21539
   259
  by (rule iffI)
wenzelm@21539
   260
wenzelm@61487
   261
lemma iff_sym: "Q \<longleftrightarrow> P \<Longrightarrow> P \<longleftrightarrow> Q"
wenzelm@21539
   262
  apply (erule iffE)
wenzelm@21539
   263
  apply (rule iffI)
wenzelm@21539
   264
  apply (assumption | erule mp)+
wenzelm@21539
   265
  done
wenzelm@21539
   266
wenzelm@61487
   267
lemma iff_trans: "\<lbrakk>P \<longleftrightarrow> Q; Q \<longleftrightarrow> R\<rbrakk> \<Longrightarrow> P \<longleftrightarrow> R"
wenzelm@21539
   268
  apply (rule iffI)
wenzelm@21539
   269
  apply (assumption | erule iffE | erule (1) notE impE)+
wenzelm@21539
   270
  done
wenzelm@21539
   271
wenzelm@21539
   272
wenzelm@61487
   273
subsection \<open>Unique existence\<close>
wenzelm@61487
   274
wenzelm@61487
   275
text \<open>
wenzelm@61487
   276
  NOTE THAT the following 2 quantifications:
wenzelm@21539
   277
wenzelm@61487
   278
    \<^item> EX!x such that [EX!y such that P(x,y)]     (sequential)
wenzelm@61487
   279
    \<^item> EX!x,y such that P(x,y)                    (simultaneous)
wenzelm@61487
   280
wenzelm@61487
   281
  do NOT mean the same thing. The parser treats EX!x y.P(x,y) as sequential.
wenzelm@61487
   282
\<close>
wenzelm@61487
   283
wenzelm@61487
   284
lemma ex1I: "P(a) \<Longrightarrow> (\<And>x. P(x) \<Longrightarrow> x = a) \<Longrightarrow> \<exists>!x. P(x)"
wenzelm@21539
   285
  apply (unfold ex1_def)
wenzelm@23393
   286
  apply (assumption | rule exI conjI allI impI)+
wenzelm@21539
   287
  done
wenzelm@21539
   288
wenzelm@61487
   289
text \<open>Sometimes easier to use: the premises have no shared variables. Safe!\<close>
wenzelm@61487
   290
lemma ex_ex1I: "\<exists>x. P(x) \<Longrightarrow> (\<And>x y. \<lbrakk>P(x); P(y)\<rbrakk> \<Longrightarrow> x = y) \<Longrightarrow> \<exists>!x. P(x)"
wenzelm@23393
   291
  apply (erule exE)
wenzelm@23393
   292
  apply (rule ex1I)
wenzelm@23393
   293
   apply assumption
wenzelm@23393
   294
  apply assumption
wenzelm@21539
   295
  done
wenzelm@21539
   296
wenzelm@61487
   297
lemma ex1E: "\<exists>! x. P(x) \<Longrightarrow> (\<And>x. \<lbrakk>P(x); \<forall>y. P(y) \<longrightarrow> y = x\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
wenzelm@23393
   298
  apply (unfold ex1_def)
wenzelm@21539
   299
  apply (assumption | erule exE conjE)+
wenzelm@21539
   300
  done
wenzelm@21539
   301
wenzelm@21539
   302
wenzelm@62020
   303
subsubsection \<open>\<open>\<longleftrightarrow>\<close> congruence rules for simplification\<close>
wenzelm@21539
   304
wenzelm@62020
   305
text \<open>Use \<open>iffE\<close> on a premise. For \<open>conj_cong\<close>, \<open>imp_cong\<close>, \<open>all_cong\<close>, \<open>ex_cong\<close>.\<close>
wenzelm@60770
   306
ML \<open>
wenzelm@59529
   307
  fun iff_tac ctxt prems i =
wenzelm@59529
   308
    resolve_tac ctxt (prems RL @{thms iffE}) i THEN
wenzelm@61487
   309
    REPEAT1 (eresolve_tac ctxt @{thms asm_rl mp} i);
wenzelm@60770
   310
\<close>
wenzelm@21539
   311
wenzelm@59529
   312
method_setup iff =
wenzelm@61487
   313
  \<open>Attrib.thms >>
wenzelm@61487
   314
    (fn prems => fn ctxt => SIMPLE_METHOD' (iff_tac ctxt prems))\<close>
wenzelm@59529
   315
wenzelm@21539
   316
lemma conj_cong:
wenzelm@61487
   317
  assumes "P \<longleftrightarrow> P'"
wenzelm@61487
   318
    and "P' \<Longrightarrow> Q \<longleftrightarrow> Q'"
wenzelm@61487
   319
  shows "(P \<and> Q) \<longleftrightarrow> (P' \<and> Q')"
wenzelm@21539
   320
  apply (insert assms)
wenzelm@59529
   321
  apply (assumption | rule iffI conjI | erule iffE conjE mp | iff assms)+
wenzelm@21539
   322
  done
wenzelm@21539
   323
wenzelm@61487
   324
text \<open>Reversed congruence rule!  Used in ZF/Order.\<close>
wenzelm@21539
   325
lemma conj_cong2:
wenzelm@61487
   326
  assumes "P \<longleftrightarrow> P'"
wenzelm@61487
   327
    and "P' \<Longrightarrow> Q \<longleftrightarrow> Q'"
wenzelm@61487
   328
  shows "(Q \<and> P) \<longleftrightarrow> (Q' \<and> P')"
wenzelm@21539
   329
  apply (insert assms)
wenzelm@59529
   330
  apply (assumption | rule iffI conjI | erule iffE conjE mp | iff assms)+
wenzelm@21539
   331
  done
wenzelm@21539
   332
wenzelm@21539
   333
lemma disj_cong:
wenzelm@61487
   334
  assumes "P \<longleftrightarrow> P'" and "Q \<longleftrightarrow> Q'"
wenzelm@61487
   335
  shows "(P \<or> Q) \<longleftrightarrow> (P' \<or> Q')"
wenzelm@21539
   336
  apply (insert assms)
wenzelm@61487
   337
  apply (erule iffE disjE disjI1 disjI2 |
wenzelm@61487
   338
    assumption | rule iffI | erule (1) notE impE)+
wenzelm@21539
   339
  done
wenzelm@21539
   340
wenzelm@21539
   341
lemma imp_cong:
wenzelm@61487
   342
  assumes "P \<longleftrightarrow> P'"
wenzelm@61487
   343
    and "P' \<Longrightarrow> Q \<longleftrightarrow> Q'"
wenzelm@61487
   344
  shows "(P \<longrightarrow> Q) \<longleftrightarrow> (P' \<longrightarrow> Q')"
wenzelm@21539
   345
  apply (insert assms)
wenzelm@59529
   346
  apply (assumption | rule iffI impI | erule iffE | erule (1) notE impE | iff assms)+
wenzelm@21539
   347
  done
wenzelm@21539
   348
wenzelm@61487
   349
lemma iff_cong: "\<lbrakk>P \<longleftrightarrow> P'; Q \<longleftrightarrow> Q'\<rbrakk> \<Longrightarrow> (P \<longleftrightarrow> Q) \<longleftrightarrow> (P' \<longleftrightarrow> Q')"
wenzelm@21539
   350
  apply (erule iffE | assumption | rule iffI | erule (1) notE impE)+
wenzelm@21539
   351
  done
wenzelm@21539
   352
wenzelm@61487
   353
lemma not_cong: "P \<longleftrightarrow> P' \<Longrightarrow> \<not> P \<longleftrightarrow> \<not> P'"
wenzelm@21539
   354
  apply (assumption | rule iffI notI | erule (1) notE impE | erule iffE notE)+
wenzelm@21539
   355
  done
wenzelm@21539
   356
wenzelm@21539
   357
lemma all_cong:
wenzelm@61487
   358
  assumes "\<And>x. P(x) \<longleftrightarrow> Q(x)"
wenzelm@61487
   359
  shows "(\<forall>x. P(x)) \<longleftrightarrow> (\<forall>x. Q(x))"
wenzelm@59529
   360
  apply (assumption | rule iffI allI | erule (1) notE impE | erule allE | iff assms)+
wenzelm@21539
   361
  done
wenzelm@21539
   362
wenzelm@21539
   363
lemma ex_cong:
wenzelm@61487
   364
  assumes "\<And>x. P(x) \<longleftrightarrow> Q(x)"
wenzelm@61487
   365
  shows "(\<exists>x. P(x)) \<longleftrightarrow> (\<exists>x. Q(x))"
wenzelm@59529
   366
  apply (erule exE | assumption | rule iffI exI | erule (1) notE impE | iff assms)+
wenzelm@21539
   367
  done
wenzelm@21539
   368
wenzelm@21539
   369
lemma ex1_cong:
wenzelm@61487
   370
  assumes "\<And>x. P(x) \<longleftrightarrow> Q(x)"
wenzelm@61487
   371
  shows "(\<exists>!x. P(x)) \<longleftrightarrow> (\<exists>!x. Q(x))"
wenzelm@59529
   372
  apply (erule ex1E spec [THEN mp] | assumption | rule iffI ex1I | erule (1) notE impE | iff assms)+
wenzelm@21539
   373
  done
wenzelm@21539
   374
wenzelm@21539
   375
wenzelm@61487
   376
subsection \<open>Equality rules\<close>
wenzelm@61487
   377
wenzelm@61487
   378
lemma sym: "a = b \<Longrightarrow> b = a"
wenzelm@21539
   379
  apply (erule subst)
wenzelm@21539
   380
  apply (rule refl)
wenzelm@21539
   381
  done
wenzelm@21539
   382
wenzelm@61487
   383
lemma trans: "\<lbrakk>a = b; b = c\<rbrakk> \<Longrightarrow> a = c"
wenzelm@21539
   384
  apply (erule subst, assumption)
wenzelm@21539
   385
  done
wenzelm@21539
   386
wenzelm@61487
   387
lemma not_sym: "b \<noteq> a \<Longrightarrow> a \<noteq> b"
wenzelm@21539
   388
  apply (erule contrapos)
wenzelm@21539
   389
  apply (erule sym)
wenzelm@21539
   390
  done
wenzelm@21539
   391
wenzelm@61487
   392
text \<open>
wenzelm@61487
   393
  Two theorems for rewriting only one instance of a definition:
wenzelm@61487
   394
  the first for definitions of formulae and the second for terms.
wenzelm@61487
   395
\<close>
wenzelm@61487
   396
wenzelm@61487
   397
lemma def_imp_iff: "(A \<equiv> B) \<Longrightarrow> A \<longleftrightarrow> B"
wenzelm@21539
   398
  apply unfold
wenzelm@21539
   399
  apply (rule iff_refl)
wenzelm@21539
   400
  done
wenzelm@21539
   401
wenzelm@61487
   402
lemma meta_eq_to_obj_eq: "(A \<equiv> B) \<Longrightarrow> A = B"
wenzelm@21539
   403
  apply unfold
wenzelm@21539
   404
  apply (rule refl)
wenzelm@21539
   405
  done
wenzelm@21539
   406
wenzelm@61487
   407
lemma meta_eq_to_iff: "x \<equiv> y \<Longrightarrow> x \<longleftrightarrow> y"
wenzelm@21539
   408
  by unfold (rule iff_refl)
wenzelm@21539
   409
wenzelm@61487
   410
text \<open>Substitution.\<close>
wenzelm@61487
   411
lemma ssubst: "\<lbrakk>b = a; P(a)\<rbrakk> \<Longrightarrow> P(b)"
wenzelm@21539
   412
  apply (drule sym)
wenzelm@21539
   413
  apply (erule (1) subst)
wenzelm@21539
   414
  done
wenzelm@21539
   415
wenzelm@62020
   416
text \<open>A special case of \<open>ex1E\<close> that would otherwise need quantifier
wenzelm@61487
   417
  expansion.\<close>
wenzelm@61487
   418
lemma ex1_equalsE: "\<lbrakk>\<exists>!x. P(x); P(a); P(b)\<rbrakk> \<Longrightarrow> a = b"
wenzelm@21539
   419
  apply (erule ex1E)
wenzelm@21539
   420
  apply (rule trans)
wenzelm@21539
   421
   apply (rule_tac [2] sym)
wenzelm@21539
   422
   apply (assumption | erule spec [THEN mp])+
wenzelm@21539
   423
  done
wenzelm@21539
   424
wenzelm@21539
   425
wenzelm@61487
   426
subsubsection \<open>Polymorphic congruence rules\<close>
wenzelm@61487
   427
wenzelm@61487
   428
lemma subst_context: "a = b \<Longrightarrow> t(a) = t(b)"
wenzelm@21539
   429
  apply (erule ssubst)
wenzelm@21539
   430
  apply (rule refl)
wenzelm@21539
   431
  done
wenzelm@21539
   432
wenzelm@61487
   433
lemma subst_context2: "\<lbrakk>a = b; c = d\<rbrakk> \<Longrightarrow> t(a,c) = t(b,d)"
wenzelm@61487
   434
  apply (erule ssubst)+
wenzelm@61487
   435
  apply (rule refl)
wenzelm@61487
   436
  done
wenzelm@61487
   437
wenzelm@61487
   438
lemma subst_context3: "\<lbrakk>a = b; c = d; e = f\<rbrakk> \<Longrightarrow> t(a,c,e) = t(b,d,f)"
wenzelm@21539
   439
  apply (erule ssubst)+
wenzelm@21539
   440
  apply (rule refl)
wenzelm@21539
   441
  done
wenzelm@21539
   442
wenzelm@61487
   443
text \<open>
wenzelm@61490
   444
  Useful with @{ML eresolve_tac} for proving equalities from known
wenzelm@61487
   445
  equalities.
wenzelm@21539
   446
wenzelm@21539
   447
        a = b
wenzelm@21539
   448
        |   |
wenzelm@61487
   449
        c = d
wenzelm@61487
   450
\<close>
wenzelm@61487
   451
lemma box_equals: "\<lbrakk>a = b; a = c; b = d\<rbrakk> \<Longrightarrow> c = d"
wenzelm@21539
   452
  apply (rule trans)
wenzelm@21539
   453
   apply (rule trans)
wenzelm@21539
   454
    apply (rule sym)
wenzelm@21539
   455
    apply assumption+
wenzelm@21539
   456
  done
wenzelm@21539
   457
wenzelm@62020
   458
text \<open>Dual of \<open>box_equals\<close>: for proving equalities backwards.\<close>
wenzelm@61487
   459
lemma simp_equals: "\<lbrakk>a = c; b = d; c = d\<rbrakk> \<Longrightarrow> a = b"
wenzelm@21539
   460
  apply (rule trans)
wenzelm@21539
   461
   apply (rule trans)
wenzelm@21539
   462
    apply assumption+
wenzelm@21539
   463
  apply (erule sym)
wenzelm@21539
   464
  done
wenzelm@21539
   465
wenzelm@21539
   466
wenzelm@61487
   467
subsubsection \<open>Congruence rules for predicate letters\<close>
wenzelm@61487
   468
wenzelm@61487
   469
lemma pred1_cong: "a = a' \<Longrightarrow> P(a) \<longleftrightarrow> P(a')"
wenzelm@21539
   470
  apply (rule iffI)
wenzelm@21539
   471
   apply (erule (1) subst)
wenzelm@21539
   472
  apply (erule (1) ssubst)
wenzelm@21539
   473
  done
wenzelm@21539
   474
wenzelm@61487
   475
lemma pred2_cong: "\<lbrakk>a = a'; b = b'\<rbrakk> \<Longrightarrow> P(a,b) \<longleftrightarrow> P(a',b')"
wenzelm@21539
   476
  apply (rule iffI)
wenzelm@21539
   477
   apply (erule subst)+
wenzelm@21539
   478
   apply assumption
wenzelm@21539
   479
  apply (erule ssubst)+
wenzelm@21539
   480
  apply assumption
wenzelm@21539
   481
  done
wenzelm@21539
   482
wenzelm@61487
   483
lemma pred3_cong: "\<lbrakk>a = a'; b = b'; c = c'\<rbrakk> \<Longrightarrow> P(a,b,c) \<longleftrightarrow> P(a',b',c')"
wenzelm@21539
   484
  apply (rule iffI)
wenzelm@21539
   485
   apply (erule subst)+
wenzelm@21539
   486
   apply assumption
wenzelm@21539
   487
  apply (erule ssubst)+
wenzelm@21539
   488
  apply assumption
wenzelm@21539
   489
  done
wenzelm@21539
   490
wenzelm@61487
   491
text \<open>Special case for the equality predicate!\<close>
wenzelm@61487
   492
lemma eq_cong: "\<lbrakk>a = a'; b = b'\<rbrakk> \<Longrightarrow> a = b \<longleftrightarrow> a' = b'"
wenzelm@21539
   493
  apply (erule (1) pred2_cong)
wenzelm@21539
   494
  done
wenzelm@21539
   495
wenzelm@21539
   496
wenzelm@61487
   497
subsection \<open>Simplifications of assumed implications\<close>
wenzelm@61487
   498
wenzelm@61487
   499
text \<open>
wenzelm@62020
   500
  Roy Dyckhoff has proved that \<open>conj_impE\<close>, \<open>disj_impE\<close>, and
wenzelm@62020
   501
  \<open>imp_impE\<close> used with @{ML mp_tac} (restricted to atomic formulae) is
wenzelm@61487
   502
  COMPLETE for intuitionistic propositional logic.
wenzelm@61487
   503
wenzelm@61487
   504
  See R. Dyckhoff, Contraction-free sequent calculi for intuitionistic logic
wenzelm@61487
   505
  (preprint, University of St Andrews, 1991).
wenzelm@61487
   506
\<close>
wenzelm@21539
   507
wenzelm@21539
   508
lemma conj_impE:
wenzelm@61487
   509
  assumes major: "(P \<and> Q) \<longrightarrow> S"
wenzelm@61487
   510
    and r: "P \<longrightarrow> (Q \<longrightarrow> S) \<Longrightarrow> R"
wenzelm@21539
   511
  shows R
wenzelm@21539
   512
  by (assumption | rule conjI impI major [THEN mp] r)+
wenzelm@21539
   513
wenzelm@21539
   514
lemma disj_impE:
wenzelm@61487
   515
  assumes major: "(P \<or> Q) \<longrightarrow> S"
wenzelm@61487
   516
    and r: "\<lbrakk>P \<longrightarrow> S; Q \<longrightarrow> S\<rbrakk> \<Longrightarrow> R"
wenzelm@21539
   517
  shows R
wenzelm@21539
   518
  by (assumption | rule disjI1 disjI2 impI major [THEN mp] r)+
wenzelm@21539
   519
wenzelm@61487
   520
text \<open>Simplifies the implication.  Classical version is stronger.
wenzelm@61487
   521
  Still UNSAFE since Q must be provable -- backtracking needed.\<close>
wenzelm@21539
   522
lemma imp_impE:
wenzelm@61487
   523
  assumes major: "(P \<longrightarrow> Q) \<longrightarrow> S"
wenzelm@61487
   524
    and r1: "\<lbrakk>P; Q \<longrightarrow> S\<rbrakk> \<Longrightarrow> Q"
wenzelm@61487
   525
    and r2: "S \<Longrightarrow> R"
wenzelm@21539
   526
  shows R
wenzelm@21539
   527
  by (assumption | rule impI major [THEN mp] r1 r2)+
wenzelm@21539
   528
wenzelm@61487
   529
text \<open>Simplifies the implication.  Classical version is stronger.
wenzelm@61487
   530
  Still UNSAFE since ~P must be provable -- backtracking needed.\<close>
wenzelm@61487
   531
lemma not_impE: "\<not> P \<longrightarrow> S \<Longrightarrow> (P \<Longrightarrow> False) \<Longrightarrow> (S \<Longrightarrow> R) \<Longrightarrow> R"
wenzelm@23393
   532
  apply (drule mp)
wenzelm@23393
   533
   apply (rule notI)
wenzelm@23393
   534
   apply assumption
wenzelm@23393
   535
  apply assumption
wenzelm@21539
   536
  done
wenzelm@21539
   537
wenzelm@61487
   538
text \<open>Simplifies the implication. UNSAFE.\<close>
wenzelm@21539
   539
lemma iff_impE:
wenzelm@61487
   540
  assumes major: "(P \<longleftrightarrow> Q) \<longrightarrow> S"
wenzelm@61487
   541
    and r1: "\<lbrakk>P; Q \<longrightarrow> S\<rbrakk> \<Longrightarrow> Q"
wenzelm@61487
   542
    and r2: "\<lbrakk>Q; P \<longrightarrow> S\<rbrakk> \<Longrightarrow> P"
wenzelm@61487
   543
    and r3: "S \<Longrightarrow> R"
wenzelm@21539
   544
  shows R
wenzelm@21539
   545
  apply (assumption | rule iffI impI major [THEN mp] r1 r2 r3)+
wenzelm@21539
   546
  done
wenzelm@21539
   547
wenzelm@62020
   548
text \<open>What if \<open>(\<forall>x. \<not> \<not> P(x)) \<longrightarrow> \<not> \<not> (\<forall>x. P(x))\<close> is an assumption?
wenzelm@61487
   549
  UNSAFE.\<close>
wenzelm@21539
   550
lemma all_impE:
wenzelm@61487
   551
  assumes major: "(\<forall>x. P(x)) \<longrightarrow> S"
wenzelm@61487
   552
    and r1: "\<And>x. P(x)"
wenzelm@61487
   553
    and r2: "S \<Longrightarrow> R"
wenzelm@21539
   554
  shows R
wenzelm@23393
   555
  apply (rule allI impI major [THEN mp] r1 r2)+
wenzelm@21539
   556
  done
wenzelm@21539
   557
wenzelm@61487
   558
text \<open>
wenzelm@62020
   559
  Unsafe: \<open>\<exists>x. P(x)) \<longrightarrow> S\<close> is equivalent
wenzelm@62020
   560
  to \<open>\<forall>x. P(x) \<longrightarrow> S\<close>.\<close>
wenzelm@21539
   561
lemma ex_impE:
wenzelm@61487
   562
  assumes major: "(\<exists>x. P(x)) \<longrightarrow> S"
wenzelm@61487
   563
    and r: "P(x) \<longrightarrow> S \<Longrightarrow> R"
wenzelm@21539
   564
  shows R
wenzelm@21539
   565
  apply (assumption | rule exI impI major [THEN mp] r)+
wenzelm@21539
   566
  done
wenzelm@21539
   567
wenzelm@61487
   568
text \<open>Courtesy of Krzysztof Grabczewski.\<close>
wenzelm@61487
   569
lemma disj_imp_disj: "P \<or> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> S) \<Longrightarrow> R \<or> S"
wenzelm@23393
   570
  apply (erule disjE)
wenzelm@21539
   571
  apply (rule disjI1) apply assumption
wenzelm@21539
   572
  apply (rule disjI2) apply assumption
wenzelm@21539
   573
  done
wenzelm@11734
   574
wenzelm@60770
   575
ML \<open>
wenzelm@32172
   576
structure Project_Rule = Project_Rule
wenzelm@32172
   577
(
wenzelm@22139
   578
  val conjunct1 = @{thm conjunct1}
wenzelm@22139
   579
  val conjunct2 = @{thm conjunct2}
wenzelm@22139
   580
  val mp = @{thm mp}
wenzelm@32172
   581
)
wenzelm@60770
   582
\<close>
wenzelm@18481
   583
wenzelm@48891
   584
ML_file "fologic.ML"
wenzelm@21539
   585
wenzelm@61487
   586
lemma thin_refl: "\<lbrakk>x = x; PROP W\<rbrakk> \<Longrightarrow> PROP W" .
wenzelm@21539
   587
wenzelm@60770
   588
ML \<open>
wenzelm@42799
   589
structure Hypsubst = Hypsubst
wenzelm@42799
   590
(
wenzelm@42799
   591
  val dest_eq = FOLogic.dest_eq
wenzelm@42799
   592
  val dest_Trueprop = FOLogic.dest_Trueprop
wenzelm@42799
   593
  val dest_imp = FOLogic.dest_imp
wenzelm@42799
   594
  val eq_reflection = @{thm eq_reflection}
wenzelm@42799
   595
  val rev_eq_reflection = @{thm meta_eq_to_obj_eq}
wenzelm@42799
   596
  val imp_intr = @{thm impI}
wenzelm@42799
   597
  val rev_mp = @{thm rev_mp}
wenzelm@42799
   598
  val subst = @{thm subst}
wenzelm@42799
   599
  val sym = @{thm sym}
wenzelm@42799
   600
  val thin_refl = @{thm thin_refl}
wenzelm@42799
   601
);
wenzelm@42799
   602
open Hypsubst;
wenzelm@60770
   603
\<close>
wenzelm@42799
   604
wenzelm@48891
   605
ML_file "intprover.ML"
wenzelm@7355
   606
wenzelm@4092
   607
wenzelm@60770
   608
subsection \<open>Intuitionistic Reasoning\<close>
wenzelm@12368
   609
wenzelm@60770
   610
setup \<open>Intuitionistic.method_setup @{binding iprover}\<close>
wenzelm@30165
   611
wenzelm@12349
   612
lemma impE':
wenzelm@61487
   613
  assumes 1: "P \<longrightarrow> Q"
wenzelm@61487
   614
    and 2: "Q \<Longrightarrow> R"
wenzelm@61487
   615
    and 3: "P \<longrightarrow> Q \<Longrightarrow> P"
wenzelm@12937
   616
  shows R
wenzelm@12349
   617
proof -
wenzelm@12349
   618
  from 3 and 1 have P .
wenzelm@12368
   619
  with 1 have Q by (rule impE)
wenzelm@12349
   620
  with 2 show R .
wenzelm@12349
   621
qed
wenzelm@12349
   622
wenzelm@12349
   623
lemma allE':
wenzelm@61487
   624
  assumes 1: "\<forall>x. P(x)"
wenzelm@61487
   625
    and 2: "P(x) \<Longrightarrow> \<forall>x. P(x) \<Longrightarrow> Q"
wenzelm@12937
   626
  shows Q
wenzelm@12349
   627
proof -
wenzelm@12349
   628
  from 1 have "P(x)" by (rule spec)
wenzelm@12349
   629
  from this and 1 show Q by (rule 2)
wenzelm@12349
   630
qed
wenzelm@12349
   631
wenzelm@12937
   632
lemma notE':
wenzelm@61487
   633
  assumes 1: "\<not> P"
wenzelm@61487
   634
    and 2: "\<not> P \<Longrightarrow> P"
wenzelm@12937
   635
  shows R
wenzelm@12349
   636
proof -
wenzelm@12349
   637
  from 2 and 1 have P .
wenzelm@12349
   638
  with 1 show R by (rule notE)
wenzelm@12349
   639
qed
wenzelm@12349
   640
wenzelm@12349
   641
lemmas [Pure.elim!] = disjE iffE FalseE conjE exE
wenzelm@12349
   642
  and [Pure.intro!] = iffI conjI impI TrueI notI allI refl
wenzelm@12349
   643
  and [Pure.elim 2] = allE notE' impE'
wenzelm@12349
   644
  and [Pure.intro] = exI disjI2 disjI1
wenzelm@12349
   645
wenzelm@61487
   646
setup \<open>
wenzelm@61487
   647
  Context_Rules.addSWrapper
wenzelm@61487
   648
    (fn ctxt => fn tac => hyp_subst_tac ctxt ORELSE' tac)
wenzelm@61487
   649
\<close>
wenzelm@12349
   650
wenzelm@12349
   651
wenzelm@61487
   652
lemma iff_not_sym: "\<not> (Q \<longleftrightarrow> P) \<Longrightarrow> \<not> (P \<longleftrightarrow> Q)"
nipkow@17591
   653
  by iprover
wenzelm@12368
   654
wenzelm@12368
   655
lemmas [sym] = sym iff_sym not_sym iff_not_sym
wenzelm@12368
   656
  and [Pure.elim?] = iffD1 iffD2 impE
wenzelm@12368
   657
wenzelm@12368
   658
wenzelm@61487
   659
lemma eq_commute: "a = b \<longleftrightarrow> b = a"
wenzelm@61487
   660
  apply (rule iffI)
wenzelm@61487
   661
  apply (erule sym)+
wenzelm@61487
   662
  done
paulson@13435
   663
paulson@13435
   664
wenzelm@60770
   665
subsection \<open>Atomizing meta-level rules\<close>
wenzelm@11677
   666
wenzelm@61487
   667
lemma atomize_all [atomize]: "(\<And>x. P(x)) \<equiv> Trueprop (\<forall>x. P(x))"
wenzelm@11976
   668
proof
wenzelm@61487
   669
  assume "\<And>x. P(x)"
wenzelm@61487
   670
  then show "\<forall>x. P(x)" ..
wenzelm@11677
   671
next
wenzelm@61487
   672
  assume "\<forall>x. P(x)"
wenzelm@61487
   673
  then show "\<And>x. P(x)" ..
wenzelm@11677
   674
qed
wenzelm@11677
   675
wenzelm@61487
   676
lemma atomize_imp [atomize]: "(A \<Longrightarrow> B) \<equiv> Trueprop (A \<longrightarrow> B)"
wenzelm@11976
   677
proof
wenzelm@61487
   678
  assume "A \<Longrightarrow> B"
wenzelm@61487
   679
  then show "A \<longrightarrow> B" ..
wenzelm@11677
   680
next
wenzelm@61487
   681
  assume "A \<longrightarrow> B" and A
wenzelm@22931
   682
  then show B by (rule mp)
wenzelm@11677
   683
qed
wenzelm@11677
   684
wenzelm@61487
   685
lemma atomize_eq [atomize]: "(x \<equiv> y) \<equiv> Trueprop (x = y)"
wenzelm@11976
   686
proof
wenzelm@61487
   687
  assume "x \<equiv> y"
wenzelm@61487
   688
  show "x = y" unfolding \<open>x \<equiv> y\<close> by (rule refl)
wenzelm@11677
   689
next
wenzelm@11677
   690
  assume "x = y"
wenzelm@61487
   691
  then show "x \<equiv> y" by (rule eq_reflection)
wenzelm@11677
   692
qed
wenzelm@11677
   693
wenzelm@61487
   694
lemma atomize_iff [atomize]: "(A \<equiv> B) \<equiv> Trueprop (A \<longleftrightarrow> B)"
wenzelm@18813
   695
proof
wenzelm@61487
   696
  assume "A \<equiv> B"
wenzelm@61487
   697
  show "A \<longleftrightarrow> B" unfolding \<open>A \<equiv> B\<close> by (rule iff_refl)
wenzelm@18813
   698
next
wenzelm@61487
   699
  assume "A \<longleftrightarrow> B"
wenzelm@61487
   700
  then show "A \<equiv> B" by (rule iff_reflection)
wenzelm@18813
   701
qed
wenzelm@18813
   702
wenzelm@61487
   703
lemma atomize_conj [atomize]: "(A &&& B) \<equiv> Trueprop (A \<and> B)"
wenzelm@11976
   704
proof
wenzelm@28856
   705
  assume conj: "A &&& B"
wenzelm@61487
   706
  show "A \<and> B"
wenzelm@19120
   707
  proof (rule conjI)
wenzelm@19120
   708
    from conj show A by (rule conjunctionD1)
wenzelm@19120
   709
    from conj show B by (rule conjunctionD2)
wenzelm@19120
   710
  qed
wenzelm@11953
   711
next
wenzelm@61487
   712
  assume conj: "A \<and> B"
wenzelm@28856
   713
  show "A &&& B"
wenzelm@19120
   714
  proof -
wenzelm@19120
   715
    from conj show A ..
wenzelm@19120
   716
    from conj show B ..
wenzelm@11953
   717
  qed
wenzelm@11953
   718
qed
wenzelm@11953
   719
wenzelm@12368
   720
lemmas [symmetric, rulify] = atomize_all atomize_imp
wenzelm@18861
   721
  and [symmetric, defn] = atomize_all atomize_imp atomize_eq atomize_iff
wenzelm@11771
   722
wenzelm@11848
   723
wenzelm@60770
   724
subsection \<open>Atomizing elimination rules\<close>
krauss@26580
   725
wenzelm@61487
   726
lemma atomize_exL[atomize_elim]: "(\<And>x. P(x) \<Longrightarrow> Q) \<equiv> ((\<exists>x. P(x)) \<Longrightarrow> Q)"
wenzelm@57948
   727
  by rule iprover+
krauss@26580
   728
wenzelm@61487
   729
lemma atomize_conjL[atomize_elim]: "(A \<Longrightarrow> B \<Longrightarrow> C) \<equiv> (A \<and> B \<Longrightarrow> C)"
wenzelm@57948
   730
  by rule iprover+
krauss@26580
   731
wenzelm@61487
   732
lemma atomize_disjL[atomize_elim]: "((A \<Longrightarrow> C) \<Longrightarrow> (B \<Longrightarrow> C) \<Longrightarrow> C) \<equiv> ((A \<or> B \<Longrightarrow> C) \<Longrightarrow> C)"
wenzelm@57948
   733
  by rule iprover+
krauss@26580
   734
wenzelm@61487
   735
lemma atomize_elimL[atomize_elim]: "(\<And>B. (A \<Longrightarrow> B) \<Longrightarrow> B) \<equiv> Trueprop(A)" ..
krauss@26580
   736
krauss@26580
   737
wenzelm@60770
   738
subsection \<open>Calculational rules\<close>
wenzelm@11848
   739
wenzelm@61487
   740
lemma forw_subst: "a = b \<Longrightarrow> P(b) \<Longrightarrow> P(a)"
wenzelm@11848
   741
  by (rule ssubst)
wenzelm@11848
   742
wenzelm@61487
   743
lemma back_subst: "P(a) \<Longrightarrow> a = b \<Longrightarrow> P(b)"
wenzelm@11848
   744
  by (rule subst)
wenzelm@11848
   745
wenzelm@60770
   746
text \<open>
wenzelm@11848
   747
  Note that this list of rules is in reverse order of priorities.
wenzelm@60770
   748
\<close>
wenzelm@11848
   749
wenzelm@12019
   750
lemmas basic_trans_rules [trans] =
wenzelm@11848
   751
  forw_subst
wenzelm@11848
   752
  back_subst
wenzelm@11848
   753
  rev_mp
wenzelm@11848
   754
  mp
wenzelm@11848
   755
  trans
wenzelm@11848
   756
wenzelm@61487
   757
wenzelm@60770
   758
subsection \<open>``Let'' declarations\<close>
paulson@13779
   759
wenzelm@41229
   760
nonterminal letbinds and letbind
paulson@13779
   761
wenzelm@61487
   762
definition Let :: "['a::{}, 'a => 'b] \<Rightarrow> ('b::{})"
wenzelm@61487
   763
  where "Let(s, f) \<equiv> f(s)"
paulson@13779
   764
paulson@13779
   765
syntax
paulson@13779
   766
  "_bind"       :: "[pttrn, 'a] => letbind"           ("(2_ =/ _)" 10)
paulson@13779
   767
  ""            :: "letbind => letbinds"              ("_")
paulson@13779
   768
  "_binds"      :: "[letbind, letbinds] => letbinds"  ("_;/ _")
paulson@13779
   769
  "_Let"        :: "[letbinds, 'a] => 'a"             ("(let (_)/ in (_))" 10)
paulson@13779
   770
paulson@13779
   771
translations
paulson@13779
   772
  "_Let(_binds(b, bs), e)"  == "_Let(b, _Let(bs, e))"
wenzelm@61487
   773
  "let x = a in e"          == "CONST Let(a, \<lambda>x. e)"
paulson@13779
   774
wenzelm@61487
   775
lemma LetI:
wenzelm@61487
   776
  assumes "\<And>x. x = t \<Longrightarrow> P(u(x))"
wenzelm@61487
   777
  shows "P(let x = t in u(x))"
wenzelm@21539
   778
  apply (unfold Let_def)
wenzelm@21539
   779
  apply (rule refl [THEN assms])
wenzelm@21539
   780
  done
wenzelm@21539
   781
wenzelm@21539
   782
wenzelm@60770
   783
subsection \<open>Intuitionistic simplification rules\<close>
wenzelm@26286
   784
wenzelm@26286
   785
lemma conj_simps:
wenzelm@61487
   786
  "P \<and> True \<longleftrightarrow> P"
wenzelm@61487
   787
  "True \<and> P \<longleftrightarrow> P"
wenzelm@61487
   788
  "P \<and> False \<longleftrightarrow> False"
wenzelm@61487
   789
  "False \<and> P \<longleftrightarrow> False"
wenzelm@61487
   790
  "P \<and> P \<longleftrightarrow> P"
wenzelm@61487
   791
  "P \<and> P \<and> Q \<longleftrightarrow> P \<and> Q"
wenzelm@61487
   792
  "P \<and> \<not> P \<longleftrightarrow> False"
wenzelm@61487
   793
  "\<not> P \<and> P \<longleftrightarrow> False"
wenzelm@61487
   794
  "(P \<and> Q) \<and> R \<longleftrightarrow> P \<and> (Q \<and> R)"
wenzelm@26286
   795
  by iprover+
wenzelm@26286
   796
wenzelm@26286
   797
lemma disj_simps:
wenzelm@61487
   798
  "P \<or> True \<longleftrightarrow> True"
wenzelm@61487
   799
  "True \<or> P \<longleftrightarrow> True"
wenzelm@61487
   800
  "P \<or> False \<longleftrightarrow> P"
wenzelm@61487
   801
  "False \<or> P \<longleftrightarrow> P"
wenzelm@61487
   802
  "P \<or> P \<longleftrightarrow> P"
wenzelm@61487
   803
  "P \<or> P \<or> Q \<longleftrightarrow> P \<or> Q"
wenzelm@61487
   804
  "(P \<or> Q) \<or> R \<longleftrightarrow> P \<or> (Q \<or> R)"
wenzelm@26286
   805
  by iprover+
wenzelm@26286
   806
wenzelm@26286
   807
lemma not_simps:
wenzelm@61487
   808
  "\<not> (P \<or> Q) \<longleftrightarrow> \<not> P \<and> \<not> Q"
wenzelm@61487
   809
  "\<not> False \<longleftrightarrow> True"
wenzelm@61487
   810
  "\<not> True \<longleftrightarrow> False"
wenzelm@26286
   811
  by iprover+
wenzelm@26286
   812
wenzelm@26286
   813
lemma imp_simps:
wenzelm@61487
   814
  "(P \<longrightarrow> False) \<longleftrightarrow> \<not> P"
wenzelm@61487
   815
  "(P \<longrightarrow> True) \<longleftrightarrow> True"
wenzelm@61487
   816
  "(False \<longrightarrow> P) \<longleftrightarrow> True"
wenzelm@61487
   817
  "(True \<longrightarrow> P) \<longleftrightarrow> P"
wenzelm@61487
   818
  "(P \<longrightarrow> P) \<longleftrightarrow> True"
wenzelm@61487
   819
  "(P \<longrightarrow> \<not> P) \<longleftrightarrow> \<not> P"
wenzelm@26286
   820
  by iprover+
wenzelm@26286
   821
wenzelm@26286
   822
lemma iff_simps:
wenzelm@61487
   823
  "(True \<longleftrightarrow> P) \<longleftrightarrow> P"
wenzelm@61487
   824
  "(P \<longleftrightarrow> True) \<longleftrightarrow> P"
wenzelm@61487
   825
  "(P \<longleftrightarrow> P) \<longleftrightarrow> True"
wenzelm@61487
   826
  "(False \<longleftrightarrow> P) \<longleftrightarrow> \<not> P"
wenzelm@61487
   827
  "(P \<longleftrightarrow> False) \<longleftrightarrow> \<not> P"
wenzelm@26286
   828
  by iprover+
wenzelm@26286
   829
wenzelm@62020
   830
text \<open>The \<open>x = t\<close> versions are needed for the simplification
wenzelm@61487
   831
  procedures.\<close>
wenzelm@26286
   832
lemma quant_simps:
wenzelm@61487
   833
  "\<And>P. (\<forall>x. P) \<longleftrightarrow> P"
wenzelm@61487
   834
  "(\<forall>x. x = t \<longrightarrow> P(x)) \<longleftrightarrow> P(t)"
wenzelm@61487
   835
  "(\<forall>x. t = x \<longrightarrow> P(x)) \<longleftrightarrow> P(t)"
wenzelm@61487
   836
  "\<And>P. (\<exists>x. P) \<longleftrightarrow> P"
wenzelm@61487
   837
  "\<exists>x. x = t"
wenzelm@61487
   838
  "\<exists>x. t = x"
wenzelm@61487
   839
  "(\<exists>x. x = t \<and> P(x)) \<longleftrightarrow> P(t)"
wenzelm@61487
   840
  "(\<exists>x. t = x \<and> P(x)) \<longleftrightarrow> P(t)"
wenzelm@26286
   841
  by iprover+
wenzelm@26286
   842
wenzelm@61487
   843
text \<open>These are NOT supplied by default!\<close>
wenzelm@26286
   844
lemma distrib_simps:
wenzelm@61487
   845
  "P \<and> (Q \<or> R) \<longleftrightarrow> P \<and> Q \<or> P \<and> R"
wenzelm@61487
   846
  "(Q \<or> R) \<and> P \<longleftrightarrow> Q \<and> P \<or> R \<and> P"
wenzelm@61487
   847
  "(P \<or> Q \<longrightarrow> R) \<longleftrightarrow> (P \<longrightarrow> R) \<and> (Q \<longrightarrow> R)"
wenzelm@26286
   848
  by iprover+
wenzelm@26286
   849
wenzelm@26286
   850
wenzelm@61487
   851
subsubsection \<open>Conversion into rewrite rules\<close>
wenzelm@26286
   852
wenzelm@61487
   853
lemma P_iff_F: "\<not> P \<Longrightarrow> (P \<longleftrightarrow> False)"
wenzelm@61487
   854
  by iprover
wenzelm@61487
   855
lemma iff_reflection_F: "\<not> P \<Longrightarrow> (P \<equiv> False)"
wenzelm@61487
   856
  by (rule P_iff_F [THEN iff_reflection])
wenzelm@26286
   857
wenzelm@61487
   858
lemma P_iff_T: "P \<Longrightarrow> (P \<longleftrightarrow> True)"
wenzelm@61487
   859
  by iprover
wenzelm@61487
   860
lemma iff_reflection_T: "P \<Longrightarrow> (P \<equiv> True)"
wenzelm@61487
   861
  by (rule P_iff_T [THEN iff_reflection])
wenzelm@26286
   862
wenzelm@26286
   863
wenzelm@61487
   864
subsubsection \<open>More rewrite rules\<close>
wenzelm@26286
   865
wenzelm@61487
   866
lemma conj_commute: "P \<and> Q \<longleftrightarrow> Q \<and> P" by iprover
wenzelm@61487
   867
lemma conj_left_commute: "P \<and> (Q \<and> R) \<longleftrightarrow> Q \<and> (P \<and> R)" by iprover
wenzelm@26286
   868
lemmas conj_comms = conj_commute conj_left_commute
wenzelm@26286
   869
wenzelm@61487
   870
lemma disj_commute: "P \<or> Q \<longleftrightarrow> Q \<or> P" by iprover
wenzelm@61487
   871
lemma disj_left_commute: "P \<or> (Q \<or> R) \<longleftrightarrow> Q \<or> (P \<or> R)" by iprover
wenzelm@26286
   872
lemmas disj_comms = disj_commute disj_left_commute
wenzelm@26286
   873
wenzelm@61487
   874
lemma conj_disj_distribL: "P \<and> (Q \<or> R) \<longleftrightarrow> (P \<and> Q \<or> P \<and> R)" by iprover
wenzelm@61487
   875
lemma conj_disj_distribR: "(P \<or> Q) \<and> R \<longleftrightarrow> (P \<and> R \<or> Q \<and> R)" by iprover
wenzelm@26286
   876
wenzelm@61487
   877
lemma disj_conj_distribL: "P \<or> (Q \<and> R) \<longleftrightarrow> (P \<or> Q) \<and> (P \<or> R)" by iprover
wenzelm@61487
   878
lemma disj_conj_distribR: "(P \<and> Q) \<or> R \<longleftrightarrow> (P \<or> R) \<and> (Q \<or> R)" by iprover
wenzelm@26286
   879
wenzelm@61487
   880
lemma imp_conj_distrib: "(P \<longrightarrow> (Q \<and> R)) \<longleftrightarrow> (P \<longrightarrow> Q) \<and> (P \<longrightarrow> R)" by iprover
wenzelm@61487
   881
lemma imp_conj: "((P \<and> Q) \<longrightarrow> R) \<longleftrightarrow> (P \<longrightarrow> (Q \<longrightarrow> R))" by iprover
wenzelm@61487
   882
lemma imp_disj: "(P \<or> Q \<longrightarrow> R) \<longleftrightarrow> (P \<longrightarrow> R) \<and> (Q \<longrightarrow> R)" by iprover
wenzelm@26286
   883
wenzelm@61487
   884
lemma de_Morgan_disj: "(\<not> (P \<or> Q)) \<longleftrightarrow> (\<not> P \<and> \<not> Q)" by iprover
wenzelm@26286
   885
wenzelm@61487
   886
lemma not_ex: "(\<not> (\<exists>x. P(x))) \<longleftrightarrow> (\<forall>x. \<not> P(x))" by iprover
wenzelm@61487
   887
lemma imp_ex: "((\<exists>x. P(x)) \<longrightarrow> Q) \<longleftrightarrow> (\<forall>x. P(x) \<longrightarrow> Q)" by iprover
wenzelm@26286
   888
wenzelm@61487
   889
lemma ex_disj_distrib: "(\<exists>x. P(x) \<or> Q(x)) \<longleftrightarrow> ((\<exists>x. P(x)) \<or> (\<exists>x. Q(x)))"
wenzelm@61487
   890
  by iprover
wenzelm@26286
   891
wenzelm@61487
   892
lemma all_conj_distrib: "(\<forall>x. P(x) \<and> Q(x)) \<longleftrightarrow> ((\<forall>x. P(x)) \<and> (\<forall>x. Q(x)))"
wenzelm@61487
   893
  by iprover
wenzelm@26286
   894
wenzelm@4854
   895
end