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