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