src/FOLP/IFOLP.thy
author wenzelm
Sat May 14 11:42:43 2011 +0200 (2011-05-14)
changeset 42799 4e33894aec6d
parent 42616 92715b528e78
child 44121 44adaa6db327
permissions -rw-r--r--
modernized functor names;
tuned;
clasohm@1477
     1
(*  Title:      FOLP/IFOLP.thy
clasohm@1477
     2
    Author:     Martin D Coen, Cambridge University Computer Laboratory
lcp@1142
     3
    Copyright   1992  University of Cambridge
lcp@1142
     4
*)
lcp@1142
     5
wenzelm@17480
     6
header {* Intuitionistic First-Order Logic with Proofs *}
wenzelm@17480
     7
wenzelm@17480
     8
theory IFOLP
wenzelm@17480
     9
imports Pure
wenzelm@26322
    10
uses ("hypsubst.ML") ("intprover.ML")
wenzelm@17480
    11
begin
clasohm@0
    12
wenzelm@39557
    13
setup Pure_Thy.old_appl_syntax_setup
wenzelm@26956
    14
wenzelm@17480
    15
classes "term"
wenzelm@36452
    16
default_sort "term"
clasohm@0
    17
wenzelm@17480
    18
typedecl p
wenzelm@17480
    19
typedecl o
clasohm@0
    20
wenzelm@17480
    21
consts
clasohm@0
    22
      (*** Judgements ***)
clasohm@1477
    23
 Proof          ::   "[o,p]=>prop"
clasohm@0
    24
 EqProof        ::   "[p,p,o]=>prop"    ("(3_ /= _ :/ _)" [10,10,10] 5)
wenzelm@17480
    25
clasohm@0
    26
      (*** Logical Connectives -- Type Formers ***)
wenzelm@41310
    27
 eq             ::      "['a,'a] => o"  (infixl "=" 50)
wenzelm@17480
    28
 True           ::      "o"
wenzelm@17480
    29
 False          ::      "o"
paulson@2714
    30
 Not            ::      "o => o"        ("~ _" [40] 40)
wenzelm@41310
    31
 conj           ::      "[o,o] => o"    (infixr "&" 35)
wenzelm@41310
    32
 disj           ::      "[o,o] => o"    (infixr "|" 30)
wenzelm@41310
    33
 imp            ::      "[o,o] => o"    (infixr "-->" 25)
wenzelm@41310
    34
 iff            ::      "[o,o] => o"    (infixr "<->" 25)
clasohm@0
    35
      (*Quantifiers*)
clasohm@1477
    36
 All            ::      "('a => o) => o"        (binder "ALL " 10)
clasohm@1477
    37
 Ex             ::      "('a => o) => o"        (binder "EX " 10)
clasohm@1477
    38
 Ex1            ::      "('a => o) => o"        (binder "EX! " 10)
clasohm@0
    39
      (*Rewriting gadgets*)
clasohm@1477
    40
 NORM           ::      "o => o"
clasohm@1477
    41
 norm           ::      "'a => 'a"
clasohm@0
    42
lcp@648
    43
      (*** Proof Term Formers: precedence must exceed 50 ***)
clasohm@1477
    44
 tt             :: "p"
clasohm@1477
    45
 contr          :: "p=>p"
wenzelm@17480
    46
 fst            :: "p=>p"
wenzelm@17480
    47
 snd            :: "p=>p"
clasohm@1477
    48
 pair           :: "[p,p]=>p"           ("(1<_,/_>)")
clasohm@1477
    49
 split          :: "[p, [p,p]=>p] =>p"
wenzelm@17480
    50
 inl            :: "p=>p"
wenzelm@17480
    51
 inr            :: "p=>p"
clasohm@1477
    52
 when           :: "[p, p=>p, p=>p]=>p"
clasohm@1477
    53
 lambda         :: "(p => p) => p"      (binder "lam " 55)
wenzelm@41310
    54
 App            :: "[p,p]=>p"           (infixl "`" 60)
lcp@648
    55
 alll           :: "['a=>p]=>p"         (binder "all " 55)
wenzelm@41310
    56
 app            :: "[p,'a]=>p"          (infixl "^" 55)
clasohm@1477
    57
 exists         :: "['a,p]=>p"          ("(1[_,/_])")
clasohm@0
    58
 xsplit         :: "[p,['a,p]=>p]=>p"
clasohm@0
    59
 ideq           :: "'a=>p"
clasohm@0
    60
 idpeel         :: "[p,'a=>p]=>p"
wenzelm@17480
    61
 nrm            :: p
wenzelm@17480
    62
 NRM            :: p
clasohm@0
    63
wenzelm@35113
    64
syntax "_Proof" :: "[p,o]=>prop"    ("(_ /: _)" [51, 10] 5)
wenzelm@35113
    65
wenzelm@38800
    66
parse_translation {*
wenzelm@38800
    67
  let fun proof_tr [p, P] = Const (@{const_syntax Proof}, dummyT) $ P $ p
wenzelm@38800
    68
  in [(@{syntax_const "_Proof"}, proof_tr)] end
wenzelm@17480
    69
*}
wenzelm@17480
    70
wenzelm@38800
    71
(*show_proofs = true displays the proof terms -- they are ENORMOUS*)
wenzelm@42616
    72
ML {* val show_proofs = Attrib.setup_config_bool @{binding show_proofs} (K false) *}
wenzelm@38800
    73
wenzelm@38800
    74
print_translation (advanced) {*
wenzelm@38800
    75
  let
wenzelm@38800
    76
    fun proof_tr' ctxt [P, p] =
wenzelm@38800
    77
      if Config.get ctxt show_proofs then Const (@{syntax_const "_Proof"}, dummyT) $ p $ P
wenzelm@38800
    78
      else P
wenzelm@38800
    79
  in [(@{const_syntax Proof}, proof_tr')] end
wenzelm@38800
    80
*}
wenzelm@17480
    81
wenzelm@17480
    82
axioms
clasohm@0
    83
clasohm@0
    84
(**** Propositional logic ****)
clasohm@0
    85
clasohm@0
    86
(*Equality*)
clasohm@0
    87
(* Like Intensional Equality in MLTT - but proofs distinct from terms *)
clasohm@0
    88
wenzelm@17480
    89
ieqI:      "ideq(a) : a=a"
wenzelm@17480
    90
ieqE:      "[| p : a=b;  !!x. f(x) : P(x,x) |] ==> idpeel(p,f) : P(a,b)"
clasohm@0
    91
clasohm@0
    92
(* Truth and Falsity *)
clasohm@0
    93
wenzelm@17480
    94
TrueI:     "tt : True"
wenzelm@17480
    95
FalseE:    "a:False ==> contr(a):P"
clasohm@0
    96
clasohm@0
    97
(* Conjunction *)
clasohm@0
    98
wenzelm@17480
    99
conjI:     "[| a:P;  b:Q |] ==> <a,b> : P&Q"
wenzelm@17480
   100
conjunct1: "p:P&Q ==> fst(p):P"
wenzelm@17480
   101
conjunct2: "p:P&Q ==> snd(p):Q"
clasohm@0
   102
clasohm@0
   103
(* Disjunction *)
clasohm@0
   104
wenzelm@17480
   105
disjI1:    "a:P ==> inl(a):P|Q"
wenzelm@17480
   106
disjI2:    "b:Q ==> inr(b):P|Q"
wenzelm@17480
   107
disjE:     "[| a:P|Q;  !!x. x:P ==> f(x):R;  !!x. x:Q ==> g(x):R
wenzelm@17480
   108
           |] ==> when(a,f,g):R"
clasohm@0
   109
clasohm@0
   110
(* Implication *)
clasohm@0
   111
wenzelm@17480
   112
impI:      "(!!x. x:P ==> f(x):Q) ==> lam x. f(x):P-->Q"
wenzelm@17480
   113
mp:        "[| f:P-->Q;  a:P |] ==> f`a:Q"
clasohm@0
   114
clasohm@0
   115
(*Quantifiers*)
clasohm@0
   116
wenzelm@17480
   117
allI:      "(!!x. f(x) : P(x)) ==> all x. f(x) : ALL x. P(x)"
wenzelm@17480
   118
spec:      "(f:ALL x. P(x)) ==> f^x : P(x)"
clasohm@0
   119
wenzelm@17480
   120
exI:       "p : P(x) ==> [x,p] : EX x. P(x)"
wenzelm@17480
   121
exE:       "[| p: EX x. P(x);  !!x u. u:P(x) ==> f(x,u) : R |] ==> xsplit(p,f):R"
clasohm@0
   122
clasohm@0
   123
(**** Equality between proofs ****)
clasohm@0
   124
wenzelm@17480
   125
prefl:     "a : P ==> a = a : P"
wenzelm@17480
   126
psym:      "a = b : P ==> b = a : P"
wenzelm@17480
   127
ptrans:    "[| a = b : P;  b = c : P |] ==> a = c : P"
clasohm@0
   128
wenzelm@17480
   129
idpeelB:   "[| !!x. f(x) : P(x,x) |] ==> idpeel(ideq(a),f) = f(a) : P(a,a)"
clasohm@0
   130
wenzelm@17480
   131
fstB:      "a:P ==> fst(<a,b>) = a : P"
wenzelm@17480
   132
sndB:      "b:Q ==> snd(<a,b>) = b : Q"
wenzelm@17480
   133
pairEC:    "p:P&Q ==> p = <fst(p),snd(p)> : P&Q"
clasohm@0
   134
wenzelm@17480
   135
whenBinl:  "[| a:P;  !!x. x:P ==> f(x) : Q |] ==> when(inl(a),f,g) = f(a) : Q"
wenzelm@17480
   136
whenBinr:  "[| b:P;  !!x. x:P ==> g(x) : Q |] ==> when(inr(b),f,g) = g(b) : Q"
wenzelm@17480
   137
plusEC:    "a:P|Q ==> when(a,%x. inl(x),%y. inr(y)) = a : P|Q"
clasohm@0
   138
wenzelm@17480
   139
applyB:     "[| a:P;  !!x. x:P ==> b(x) : Q |] ==> (lam x. b(x)) ` a = b(a) : Q"
wenzelm@17480
   140
funEC:      "f:P ==> f = lam x. f`x : P"
clasohm@0
   141
wenzelm@17480
   142
specB:      "[| !!x. f(x) : P(x) |] ==> (all x. f(x)) ^ a = f(a) : P(a)"
clasohm@0
   143
clasohm@0
   144
clasohm@0
   145
(**** Definitions ****)
clasohm@0
   146
wenzelm@17480
   147
not_def:              "~P == P-->False"
wenzelm@17480
   148
iff_def:         "P<->Q == (P-->Q) & (Q-->P)"
clasohm@0
   149
clasohm@0
   150
(*Unique existence*)
wenzelm@17480
   151
ex1_def:   "EX! x. P(x) == EX x. P(x) & (ALL y. P(y) --> y=x)"
clasohm@0
   152
clasohm@0
   153
(*Rewriting -- special constants to flag normalized terms and formulae*)
wenzelm@17480
   154
norm_eq: "nrm : norm(x) = x"
wenzelm@17480
   155
NORM_iff:        "NRM : NORM(P) <-> P"
wenzelm@17480
   156
wenzelm@26322
   157
(*** Sequent-style elimination rules for & --> and ALL ***)
wenzelm@26322
   158
wenzelm@36319
   159
schematic_lemma conjE:
wenzelm@26322
   160
  assumes "p:P&Q"
wenzelm@26322
   161
    and "!!x y.[| x:P; y:Q |] ==> f(x,y):R"
wenzelm@26322
   162
  shows "?a:R"
wenzelm@26322
   163
  apply (rule assms(2))
wenzelm@26322
   164
   apply (rule conjunct1 [OF assms(1)])
wenzelm@26322
   165
  apply (rule conjunct2 [OF assms(1)])
wenzelm@26322
   166
  done
wenzelm@26322
   167
wenzelm@36319
   168
schematic_lemma impE:
wenzelm@26322
   169
  assumes "p:P-->Q"
wenzelm@26322
   170
    and "q:P"
wenzelm@26322
   171
    and "!!x. x:Q ==> r(x):R"
wenzelm@26322
   172
  shows "?p:R"
wenzelm@26322
   173
  apply (rule assms mp)+
wenzelm@26322
   174
  done
wenzelm@26322
   175
wenzelm@36319
   176
schematic_lemma allE:
wenzelm@26322
   177
  assumes "p:ALL x. P(x)"
wenzelm@26322
   178
    and "!!y. y:P(x) ==> q(y):R"
wenzelm@26322
   179
  shows "?p:R"
wenzelm@26322
   180
  apply (rule assms spec)+
wenzelm@26322
   181
  done
wenzelm@26322
   182
wenzelm@26322
   183
(*Duplicates the quantifier; for use with eresolve_tac*)
wenzelm@36319
   184
schematic_lemma all_dupE:
wenzelm@26322
   185
  assumes "p:ALL x. P(x)"
wenzelm@26322
   186
    and "!!y z.[| y:P(x); z:ALL x. P(x) |] ==> q(y,z):R"
wenzelm@26322
   187
  shows "?p:R"
wenzelm@26322
   188
  apply (rule assms spec)+
wenzelm@26322
   189
  done
wenzelm@26322
   190
wenzelm@26322
   191
wenzelm@26322
   192
(*** Negation rules, which translate between ~P and P-->False ***)
wenzelm@26322
   193
wenzelm@36319
   194
schematic_lemma notI:
wenzelm@26322
   195
  assumes "!!x. x:P ==> q(x):False"
wenzelm@26322
   196
  shows "?p:~P"
wenzelm@26322
   197
  unfolding not_def
wenzelm@26322
   198
  apply (assumption | rule assms impI)+
wenzelm@26322
   199
  done
wenzelm@26322
   200
wenzelm@36319
   201
schematic_lemma notE: "p:~P \<Longrightarrow> q:P \<Longrightarrow> ?p:R"
wenzelm@26322
   202
  unfolding not_def
wenzelm@26322
   203
  apply (drule (1) mp)
wenzelm@26322
   204
  apply (erule FalseE)
wenzelm@26322
   205
  done
wenzelm@26322
   206
wenzelm@26322
   207
(*This is useful with the special implication rules for each kind of P. *)
wenzelm@36319
   208
schematic_lemma not_to_imp:
wenzelm@26322
   209
  assumes "p:~P"
wenzelm@26322
   210
    and "!!x. x:(P-->False) ==> q(x):Q"
wenzelm@26322
   211
  shows "?p:Q"
wenzelm@26322
   212
  apply (assumption | rule assms impI notE)+
wenzelm@26322
   213
  done
wenzelm@26322
   214
wenzelm@26322
   215
(* For substitution int an assumption P, reduce Q to P-->Q, substitute into
wenzelm@27150
   216
   this implication, then apply impI to move P back into the assumptions.*)
wenzelm@36319
   217
schematic_lemma rev_mp: "[| p:P;  q:P --> Q |] ==> ?p:Q"
wenzelm@26322
   218
  apply (assumption | rule mp)+
wenzelm@26322
   219
  done
wenzelm@26322
   220
wenzelm@26322
   221
wenzelm@26322
   222
(*Contrapositive of an inference rule*)
wenzelm@36319
   223
schematic_lemma contrapos:
wenzelm@26322
   224
  assumes major: "p:~Q"
wenzelm@26322
   225
    and minor: "!!y. y:P==>q(y):Q"
wenzelm@26322
   226
  shows "?a:~P"
wenzelm@26322
   227
  apply (rule major [THEN notE, THEN notI])
wenzelm@26322
   228
  apply (erule minor)
wenzelm@26322
   229
  done
wenzelm@26322
   230
wenzelm@26322
   231
(** Unique assumption tactic.
wenzelm@26322
   232
    Ignores proof objects.
wenzelm@26322
   233
    Fails unless one assumption is equal and exactly one is unifiable
wenzelm@26322
   234
**)
wenzelm@26322
   235
wenzelm@26322
   236
ML {*
wenzelm@26322
   237
local
wenzelm@26322
   238
  fun discard_proof (Const (@{const_name Proof}, _) $ P $ _) = P;
wenzelm@26322
   239
in
wenzelm@26322
   240
val uniq_assume_tac =
wenzelm@26322
   241
  SUBGOAL
wenzelm@26322
   242
    (fn (prem,i) =>
wenzelm@26322
   243
      let val hyps = map discard_proof (Logic.strip_assums_hyp prem)
wenzelm@26322
   244
          and concl = discard_proof (Logic.strip_assums_concl prem)
wenzelm@26322
   245
      in
wenzelm@26322
   246
          if exists (fn hyp => hyp aconv concl) hyps
wenzelm@29269
   247
          then case distinct (op =) (filter (fn hyp => Term.could_unify (hyp, concl)) hyps) of
wenzelm@26322
   248
                   [_] => assume_tac i
wenzelm@26322
   249
                 |  _  => no_tac
wenzelm@26322
   250
          else no_tac
wenzelm@26322
   251
      end);
wenzelm@26322
   252
end;
wenzelm@26322
   253
*}
wenzelm@26322
   254
wenzelm@26322
   255
wenzelm@26322
   256
(*** Modus Ponens Tactics ***)
wenzelm@26322
   257
wenzelm@26322
   258
(*Finds P-->Q and P in the assumptions, replaces implication by Q *)
wenzelm@26322
   259
ML {*
wenzelm@26322
   260
  fun mp_tac i = eresolve_tac [@{thm notE}, make_elim @{thm mp}] i  THEN  assume_tac i
wenzelm@26322
   261
*}
wenzelm@26322
   262
wenzelm@26322
   263
(*Like mp_tac but instantiates no variables*)
wenzelm@26322
   264
ML {*
wenzelm@26322
   265
  fun int_uniq_mp_tac i = eresolve_tac [@{thm notE}, @{thm impE}] i  THEN  uniq_assume_tac i
wenzelm@26322
   266
*}
wenzelm@26322
   267
wenzelm@26322
   268
wenzelm@26322
   269
(*** If-and-only-if ***)
wenzelm@26322
   270
wenzelm@36319
   271
schematic_lemma iffI:
wenzelm@26322
   272
  assumes "!!x. x:P ==> q(x):Q"
wenzelm@26322
   273
    and "!!x. x:Q ==> r(x):P"
wenzelm@26322
   274
  shows "?p:P<->Q"
wenzelm@26322
   275
  unfolding iff_def
wenzelm@26322
   276
  apply (assumption | rule assms conjI impI)+
wenzelm@26322
   277
  done
wenzelm@26322
   278
wenzelm@26322
   279
wenzelm@26322
   280
(*Observe use of rewrite_rule to unfold "<->" in meta-assumptions (prems) *)
wenzelm@26322
   281
  
wenzelm@36319
   282
schematic_lemma iffE:
wenzelm@26322
   283
  assumes "p:P <-> Q"
wenzelm@26322
   284
    and "!!x y.[| x:P-->Q; y:Q-->P |] ==> q(x,y):R"
wenzelm@26322
   285
  shows "?p:R"
wenzelm@26322
   286
  apply (rule conjE)
wenzelm@26322
   287
   apply (rule assms(1) [unfolded iff_def])
wenzelm@26322
   288
  apply (rule assms(2))
wenzelm@26322
   289
   apply assumption+
wenzelm@26322
   290
  done
wenzelm@26322
   291
wenzelm@26322
   292
(* Destruct rules for <-> similar to Modus Ponens *)
wenzelm@26322
   293
wenzelm@36319
   294
schematic_lemma iffD1: "[| p:P <-> Q; q:P |] ==> ?p:Q"
wenzelm@26322
   295
  unfolding iff_def
wenzelm@26322
   296
  apply (rule conjunct1 [THEN mp], assumption+)
wenzelm@26322
   297
  done
wenzelm@26322
   298
wenzelm@36319
   299
schematic_lemma iffD2: "[| p:P <-> Q; q:Q |] ==> ?p:P"
wenzelm@26322
   300
  unfolding iff_def
wenzelm@26322
   301
  apply (rule conjunct2 [THEN mp], assumption+)
wenzelm@26322
   302
  done
wenzelm@26322
   303
wenzelm@36319
   304
schematic_lemma iff_refl: "?p:P <-> P"
wenzelm@26322
   305
  apply (rule iffI)
wenzelm@26322
   306
   apply assumption+
wenzelm@26322
   307
  done
wenzelm@26322
   308
wenzelm@36319
   309
schematic_lemma iff_sym: "p:Q <-> P ==> ?p:P <-> Q"
wenzelm@26322
   310
  apply (erule iffE)
wenzelm@26322
   311
  apply (rule iffI)
wenzelm@26322
   312
   apply (erule (1) mp)+
wenzelm@26322
   313
  done
wenzelm@26322
   314
wenzelm@36319
   315
schematic_lemma iff_trans: "[| p:P <-> Q; q:Q<-> R |] ==> ?p:P <-> R"
wenzelm@26322
   316
  apply (rule iffI)
wenzelm@26322
   317
   apply (assumption | erule iffE | erule (1) impE)+
wenzelm@26322
   318
  done
wenzelm@26322
   319
wenzelm@26322
   320
(*** Unique existence.  NOTE THAT the following 2 quantifications
wenzelm@26322
   321
   EX!x such that [EX!y such that P(x,y)]     (sequential)
wenzelm@26322
   322
   EX!x,y such that P(x,y)                    (simultaneous)
wenzelm@26322
   323
 do NOT mean the same thing.  The parser treats EX!x y.P(x,y) as sequential.
wenzelm@26322
   324
***)
wenzelm@26322
   325
wenzelm@36319
   326
schematic_lemma ex1I:
wenzelm@26322
   327
  assumes "p:P(a)"
wenzelm@26322
   328
    and "!!x u. u:P(x) ==> f(u) : x=a"
wenzelm@26322
   329
  shows "?p:EX! x. P(x)"
wenzelm@26322
   330
  unfolding ex1_def
wenzelm@26322
   331
  apply (assumption | rule assms exI conjI allI impI)+
wenzelm@26322
   332
  done
wenzelm@26322
   333
wenzelm@36319
   334
schematic_lemma ex1E:
wenzelm@26322
   335
  assumes "p:EX! x. P(x)"
wenzelm@26322
   336
    and "!!x u v. [| u:P(x);  v:ALL y. P(y) --> y=x |] ==> f(x,u,v):R"
wenzelm@26322
   337
  shows "?a : R"
wenzelm@26322
   338
  apply (insert assms(1) [unfolded ex1_def])
wenzelm@26322
   339
  apply (erule exE conjE | assumption | rule assms(1))+
wenzelm@29305
   340
  apply (erule assms(2), assumption)
wenzelm@26322
   341
  done
wenzelm@26322
   342
wenzelm@26322
   343
wenzelm@26322
   344
(*** <-> congruence rules for simplification ***)
wenzelm@26322
   345
wenzelm@26322
   346
(*Use iffE on a premise.  For conj_cong, imp_cong, all_cong, ex_cong*)
wenzelm@26322
   347
ML {*
wenzelm@26322
   348
fun iff_tac prems i =
wenzelm@26322
   349
    resolve_tac (prems RL [@{thm iffE}]) i THEN
wenzelm@26322
   350
    REPEAT1 (eresolve_tac [asm_rl, @{thm mp}] i)
wenzelm@26322
   351
*}
wenzelm@26322
   352
wenzelm@36319
   353
schematic_lemma conj_cong:
wenzelm@26322
   354
  assumes "p:P <-> P'"
wenzelm@26322
   355
    and "!!x. x:P' ==> q(x):Q <-> Q'"
wenzelm@26322
   356
  shows "?p:(P&Q) <-> (P'&Q')"
wenzelm@26322
   357
  apply (insert assms(1))
wenzelm@26322
   358
  apply (assumption | rule iffI conjI |
wenzelm@26322
   359
    erule iffE conjE mp | tactic {* iff_tac @{thms assms} 1 *})+
wenzelm@26322
   360
  done
wenzelm@26322
   361
wenzelm@36319
   362
schematic_lemma disj_cong:
wenzelm@26322
   363
  "[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P|Q) <-> (P'|Q')"
wenzelm@26322
   364
  apply (erule iffE disjE disjI1 disjI2 | assumption | rule iffI | tactic {* mp_tac 1 *})+
wenzelm@26322
   365
  done
wenzelm@26322
   366
wenzelm@36319
   367
schematic_lemma imp_cong:
wenzelm@26322
   368
  assumes "p:P <-> P'"
wenzelm@26322
   369
    and "!!x. x:P' ==> q(x):Q <-> Q'"
wenzelm@26322
   370
  shows "?p:(P-->Q) <-> (P'-->Q')"
wenzelm@26322
   371
  apply (insert assms(1))
wenzelm@26322
   372
  apply (assumption | rule iffI impI | erule iffE | tactic {* mp_tac 1 *} |
wenzelm@26322
   373
    tactic {* iff_tac @{thms assms} 1 *})+
wenzelm@26322
   374
  done
wenzelm@26322
   375
wenzelm@36319
   376
schematic_lemma iff_cong:
wenzelm@26322
   377
  "[| p:P <-> P'; q:Q <-> Q' |] ==> ?p:(P<->Q) <-> (P'<->Q')"
wenzelm@26322
   378
  apply (erule iffE | assumption | rule iffI | tactic {* mp_tac 1 *})+
wenzelm@26322
   379
  done
wenzelm@26322
   380
wenzelm@36319
   381
schematic_lemma not_cong:
wenzelm@26322
   382
  "p:P <-> P' ==> ?p:~P <-> ~P'"
wenzelm@26322
   383
  apply (assumption | rule iffI notI | tactic {* mp_tac 1 *} | erule iffE notE)+
wenzelm@26322
   384
  done
wenzelm@26322
   385
wenzelm@36319
   386
schematic_lemma all_cong:
wenzelm@26322
   387
  assumes "!!x. f(x):P(x) <-> Q(x)"
wenzelm@26322
   388
  shows "?p:(ALL x. P(x)) <-> (ALL x. Q(x))"
wenzelm@26322
   389
  apply (assumption | rule iffI allI | tactic {* mp_tac 1 *} | erule allE |
wenzelm@26322
   390
    tactic {* iff_tac @{thms assms} 1 *})+
wenzelm@26322
   391
  done
wenzelm@26322
   392
wenzelm@36319
   393
schematic_lemma ex_cong:
wenzelm@26322
   394
  assumes "!!x. f(x):P(x) <-> Q(x)"
wenzelm@26322
   395
  shows "?p:(EX x. P(x)) <-> (EX x. Q(x))"
wenzelm@26322
   396
  apply (erule exE | assumption | rule iffI exI | tactic {* mp_tac 1 *} |
wenzelm@26322
   397
    tactic {* iff_tac @{thms assms} 1 *})+
wenzelm@26322
   398
  done
wenzelm@26322
   399
wenzelm@26322
   400
(*NOT PROVED
wenzelm@26322
   401
bind_thm ("ex1_cong", prove_goal (the_context ())
wenzelm@26322
   402
    "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX! x.P(x)) <-> (EX! x.Q(x))"
wenzelm@26322
   403
 (fn prems =>
wenzelm@26322
   404
  [ (REPEAT   (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1
wenzelm@26322
   405
      ORELSE   mp_tac 1
wenzelm@26322
   406
      ORELSE   iff_tac prems 1)) ]))
wenzelm@26322
   407
*)
wenzelm@26322
   408
wenzelm@26322
   409
(*** Equality rules ***)
wenzelm@26322
   410
wenzelm@26322
   411
lemmas refl = ieqI
wenzelm@26322
   412
wenzelm@36319
   413
schematic_lemma subst:
wenzelm@26322
   414
  assumes prem1: "p:a=b"
wenzelm@26322
   415
    and prem2: "q:P(a)"
wenzelm@26322
   416
  shows "?p : P(b)"
wenzelm@26322
   417
  apply (rule prem2 [THEN rev_mp])
wenzelm@26322
   418
  apply (rule prem1 [THEN ieqE])
wenzelm@26322
   419
  apply (rule impI)
wenzelm@26322
   420
  apply assumption
wenzelm@26322
   421
  done
wenzelm@26322
   422
wenzelm@36319
   423
schematic_lemma sym: "q:a=b ==> ?c:b=a"
wenzelm@26322
   424
  apply (erule subst)
wenzelm@26322
   425
  apply (rule refl)
wenzelm@26322
   426
  done
wenzelm@26322
   427
wenzelm@36319
   428
schematic_lemma trans: "[| p:a=b;  q:b=c |] ==> ?d:a=c"
wenzelm@26322
   429
  apply (erule (1) subst)
wenzelm@26322
   430
  done
wenzelm@26322
   431
wenzelm@26322
   432
(** ~ b=a ==> ~ a=b **)
wenzelm@36319
   433
schematic_lemma not_sym: "p:~ b=a ==> ?q:~ a=b"
wenzelm@26322
   434
  apply (erule contrapos)
wenzelm@26322
   435
  apply (erule sym)
wenzelm@26322
   436
  done
wenzelm@26322
   437
wenzelm@26322
   438
(*calling "standard" reduces maxidx to 0*)
wenzelm@26322
   439
lemmas ssubst = sym [THEN subst, standard]
wenzelm@26322
   440
wenzelm@26322
   441
(*A special case of ex1E that would otherwise need quantifier expansion*)
wenzelm@36319
   442
schematic_lemma ex1_equalsE: "[| p:EX! x. P(x);  q:P(a);  r:P(b) |] ==> ?d:a=b"
wenzelm@26322
   443
  apply (erule ex1E)
wenzelm@26322
   444
  apply (rule trans)
wenzelm@26322
   445
   apply (rule_tac [2] sym)
wenzelm@26322
   446
   apply (assumption | erule spec [THEN mp])+
wenzelm@26322
   447
  done
wenzelm@26322
   448
wenzelm@26322
   449
(** Polymorphic congruence rules **)
wenzelm@26322
   450
wenzelm@36319
   451
schematic_lemma subst_context: "[| p:a=b |]  ==>  ?d:t(a)=t(b)"
wenzelm@26322
   452
  apply (erule ssubst)
wenzelm@26322
   453
  apply (rule refl)
wenzelm@26322
   454
  done
wenzelm@26322
   455
wenzelm@36319
   456
schematic_lemma subst_context2: "[| p:a=b;  q:c=d |]  ==>  ?p:t(a,c)=t(b,d)"
wenzelm@26322
   457
  apply (erule ssubst)+
wenzelm@26322
   458
  apply (rule refl)
wenzelm@26322
   459
  done
wenzelm@26322
   460
wenzelm@36319
   461
schematic_lemma subst_context3: "[| p:a=b;  q:c=d;  r:e=f |]  ==>  ?p:t(a,c,e)=t(b,d,f)"
wenzelm@26322
   462
  apply (erule ssubst)+
wenzelm@26322
   463
  apply (rule refl)
wenzelm@26322
   464
  done
wenzelm@26322
   465
wenzelm@26322
   466
(*Useful with eresolve_tac for proving equalties from known equalities.
wenzelm@26322
   467
        a = b
wenzelm@26322
   468
        |   |
wenzelm@26322
   469
        c = d   *)
wenzelm@36319
   470
schematic_lemma box_equals: "[| p:a=b;  q:a=c;  r:b=d |] ==> ?p:c=d"
wenzelm@26322
   471
  apply (rule trans)
wenzelm@26322
   472
   apply (rule trans)
wenzelm@26322
   473
    apply (rule sym)
wenzelm@26322
   474
    apply assumption+
wenzelm@26322
   475
  done
wenzelm@26322
   476
wenzelm@26322
   477
(*Dual of box_equals: for proving equalities backwards*)
wenzelm@36319
   478
schematic_lemma simp_equals: "[| p:a=c;  q:b=d;  r:c=d |] ==> ?p:a=b"
wenzelm@26322
   479
  apply (rule trans)
wenzelm@26322
   480
   apply (rule trans)
wenzelm@26322
   481
    apply (assumption | rule sym)+
wenzelm@26322
   482
  done
wenzelm@26322
   483
wenzelm@26322
   484
(** Congruence rules for predicate letters **)
wenzelm@26322
   485
wenzelm@36319
   486
schematic_lemma pred1_cong: "p:a=a' ==> ?p:P(a) <-> P(a')"
wenzelm@26322
   487
  apply (rule iffI)
wenzelm@26322
   488
   apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
wenzelm@26322
   489
  done
wenzelm@26322
   490
wenzelm@36319
   491
schematic_lemma pred2_cong: "[| p:a=a';  q:b=b' |] ==> ?p:P(a,b) <-> P(a',b')"
wenzelm@26322
   492
  apply (rule iffI)
wenzelm@26322
   493
   apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
wenzelm@26322
   494
  done
wenzelm@26322
   495
wenzelm@36319
   496
schematic_lemma pred3_cong: "[| p:a=a';  q:b=b';  r:c=c' |] ==> ?p:P(a,b,c) <-> P(a',b',c')"
wenzelm@26322
   497
  apply (rule iffI)
wenzelm@26322
   498
   apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE eresolve_tac [@{thm subst}, @{thm ssubst}] 1) *})
wenzelm@26322
   499
  done
wenzelm@26322
   500
wenzelm@27152
   501
lemmas pred_congs = pred1_cong pred2_cong pred3_cong
wenzelm@26322
   502
wenzelm@26322
   503
(*special case for the equality predicate!*)
wenzelm@26322
   504
lemmas eq_cong = pred2_cong [where P = "op =", standard]
wenzelm@26322
   505
wenzelm@26322
   506
wenzelm@26322
   507
(*** Simplifications of assumed implications.
wenzelm@26322
   508
     Roy Dyckhoff has proved that conj_impE, disj_impE, and imp_impE
wenzelm@26322
   509
     used with mp_tac (restricted to atomic formulae) is COMPLETE for
wenzelm@26322
   510
     intuitionistic propositional logic.  See
wenzelm@26322
   511
   R. Dyckhoff, Contraction-free sequent calculi for intuitionistic logic
wenzelm@26322
   512
    (preprint, University of St Andrews, 1991)  ***)
wenzelm@26322
   513
wenzelm@36319
   514
schematic_lemma conj_impE:
wenzelm@26322
   515
  assumes major: "p:(P&Q)-->S"
wenzelm@26322
   516
    and minor: "!!x. x:P-->(Q-->S) ==> q(x):R"
wenzelm@26322
   517
  shows "?p:R"
wenzelm@26322
   518
  apply (assumption | rule conjI impI major [THEN mp] minor)+
wenzelm@26322
   519
  done
wenzelm@26322
   520
wenzelm@36319
   521
schematic_lemma disj_impE:
wenzelm@26322
   522
  assumes major: "p:(P|Q)-->S"
wenzelm@26322
   523
    and minor: "!!x y.[| x:P-->S; y:Q-->S |] ==> q(x,y):R"
wenzelm@26322
   524
  shows "?p:R"
wenzelm@26322
   525
  apply (tactic {* DEPTH_SOLVE (atac 1 ORELSE
wenzelm@26322
   526
      resolve_tac [@{thm disjI1}, @{thm disjI2}, @{thm impI},
wenzelm@26322
   527
        @{thm major} RS @{thm mp}, @{thm minor}] 1) *})
wenzelm@26322
   528
  done
wenzelm@26322
   529
wenzelm@26322
   530
(*Simplifies the implication.  Classical version is stronger.
wenzelm@26322
   531
  Still UNSAFE since Q must be provable -- backtracking needed.  *)
wenzelm@36319
   532
schematic_lemma imp_impE:
wenzelm@26322
   533
  assumes major: "p:(P-->Q)-->S"
wenzelm@26322
   534
    and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q"
wenzelm@26322
   535
    and r2: "!!x. x:S ==> r(x):R"
wenzelm@26322
   536
  shows "?p:R"
wenzelm@26322
   537
  apply (assumption | rule impI major [THEN mp] r1 r2)+
wenzelm@26322
   538
  done
wenzelm@26322
   539
wenzelm@26322
   540
(*Simplifies the implication.  Classical version is stronger.
wenzelm@26322
   541
  Still UNSAFE since ~P must be provable -- backtracking needed.  *)
wenzelm@36319
   542
schematic_lemma not_impE:
wenzelm@26322
   543
  assumes major: "p:~P --> S"
wenzelm@26322
   544
    and r1: "!!y. y:P ==> q(y):False"
wenzelm@26322
   545
    and r2: "!!y. y:S ==> r(y):R"
wenzelm@26322
   546
  shows "?p:R"
wenzelm@26322
   547
  apply (assumption | rule notI impI major [THEN mp] r1 r2)+
wenzelm@26322
   548
  done
wenzelm@26322
   549
wenzelm@26322
   550
(*Simplifies the implication.   UNSAFE.  *)
wenzelm@36319
   551
schematic_lemma iff_impE:
wenzelm@26322
   552
  assumes major: "p:(P<->Q)-->S"
wenzelm@26322
   553
    and r1: "!!x y.[| x:P; y:Q-->S |] ==> q(x,y):Q"
wenzelm@26322
   554
    and r2: "!!x y.[| x:Q; y:P-->S |] ==> r(x,y):P"
wenzelm@26322
   555
    and r3: "!!x. x:S ==> s(x):R"
wenzelm@26322
   556
  shows "?p:R"
wenzelm@26322
   557
  apply (assumption | rule iffI impI major [THEN mp] r1 r2 r3)+
wenzelm@26322
   558
  done
wenzelm@26322
   559
wenzelm@26322
   560
(*What if (ALL x.~~P(x)) --> ~~(ALL x.P(x)) is an assumption? UNSAFE*)
wenzelm@36319
   561
schematic_lemma all_impE:
wenzelm@26322
   562
  assumes major: "p:(ALL x. P(x))-->S"
wenzelm@26322
   563
    and r1: "!!x. q:P(x)"
wenzelm@26322
   564
    and r2: "!!y. y:S ==> r(y):R"
wenzelm@26322
   565
  shows "?p:R"
wenzelm@26322
   566
  apply (assumption | rule allI impI major [THEN mp] r1 r2)+
wenzelm@26322
   567
  done
wenzelm@26322
   568
wenzelm@26322
   569
(*Unsafe: (EX x.P(x))-->S  is equivalent to  ALL x.P(x)-->S.  *)
wenzelm@36319
   570
schematic_lemma ex_impE:
wenzelm@26322
   571
  assumes major: "p:(EX x. P(x))-->S"
wenzelm@26322
   572
    and r: "!!y. y:P(a)-->S ==> q(y):R"
wenzelm@26322
   573
  shows "?p:R"
wenzelm@26322
   574
  apply (assumption | rule exI impI major [THEN mp] r)+
wenzelm@26322
   575
  done
wenzelm@26322
   576
wenzelm@26322
   577
wenzelm@36319
   578
schematic_lemma rev_cut_eq:
wenzelm@26322
   579
  assumes "p:a=b"
wenzelm@26322
   580
    and "!!x. x:a=b ==> f(x):R"
wenzelm@26322
   581
  shows "?p:R"
wenzelm@26322
   582
  apply (rule assms)+
wenzelm@26322
   583
  done
wenzelm@26322
   584
wenzelm@26322
   585
lemma thin_refl: "!!X. [|p:x=x; PROP W|] ==> PROP W" .
wenzelm@26322
   586
wenzelm@26322
   587
use "hypsubst.ML"
wenzelm@26322
   588
wenzelm@26322
   589
ML {*
wenzelm@42799
   590
structure Hypsubst = Hypsubst
wenzelm@42799
   591
(
wenzelm@26322
   592
  (*Take apart an equality judgement; otherwise raise Match!*)
wenzelm@26322
   593
  fun dest_eq (Const (@{const_name Proof}, _) $
wenzelm@41310
   594
    (Const (@{const_name eq}, _)  $ t $ u) $ _) = (t, u);
wenzelm@26322
   595
wenzelm@26322
   596
  val imp_intr = @{thm impI}
wenzelm@26322
   597
wenzelm@26322
   598
  (*etac rev_cut_eq moves an equality to be the last premise. *)
wenzelm@26322
   599
  val rev_cut_eq = @{thm rev_cut_eq}
wenzelm@26322
   600
wenzelm@26322
   601
  val rev_mp = @{thm rev_mp}
wenzelm@26322
   602
  val subst = @{thm subst}
wenzelm@26322
   603
  val sym = @{thm sym}
wenzelm@26322
   604
  val thin_refl = @{thm thin_refl}
wenzelm@42799
   605
);
wenzelm@26322
   606
open Hypsubst;
wenzelm@26322
   607
*}
wenzelm@26322
   608
wenzelm@26322
   609
use "intprover.ML"
wenzelm@26322
   610
wenzelm@26322
   611
wenzelm@26322
   612
(*** Rewrite rules ***)
wenzelm@26322
   613
wenzelm@36319
   614
schematic_lemma conj_rews:
wenzelm@26322
   615
  "?p1 : P & True <-> P"
wenzelm@26322
   616
  "?p2 : True & P <-> P"
wenzelm@26322
   617
  "?p3 : P & False <-> False"
wenzelm@26322
   618
  "?p4 : False & P <-> False"
wenzelm@26322
   619
  "?p5 : P & P <-> P"
wenzelm@26322
   620
  "?p6 : P & ~P <-> False"
wenzelm@26322
   621
  "?p7 : ~P & P <-> False"
wenzelm@26322
   622
  "?p8 : (P & Q) & R <-> P & (Q & R)"
wenzelm@26322
   623
  apply (tactic {* fn st => IntPr.fast_tac 1 st *})+
wenzelm@26322
   624
  done
wenzelm@26322
   625
wenzelm@36319
   626
schematic_lemma disj_rews:
wenzelm@26322
   627
  "?p1 : P | True <-> True"
wenzelm@26322
   628
  "?p2 : True | P <-> True"
wenzelm@26322
   629
  "?p3 : P | False <-> P"
wenzelm@26322
   630
  "?p4 : False | P <-> P"
wenzelm@26322
   631
  "?p5 : P | P <-> P"
wenzelm@26322
   632
  "?p6 : (P | Q) | R <-> P | (Q | R)"
wenzelm@26322
   633
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   634
  done
wenzelm@26322
   635
wenzelm@36319
   636
schematic_lemma not_rews:
wenzelm@26322
   637
  "?p1 : ~ False <-> True"
wenzelm@26322
   638
  "?p2 : ~ True <-> False"
wenzelm@26322
   639
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   640
  done
wenzelm@26322
   641
wenzelm@36319
   642
schematic_lemma imp_rews:
wenzelm@26322
   643
  "?p1 : (P --> False) <-> ~P"
wenzelm@26322
   644
  "?p2 : (P --> True) <-> True"
wenzelm@26322
   645
  "?p3 : (False --> P) <-> True"
wenzelm@26322
   646
  "?p4 : (True --> P) <-> P"
wenzelm@26322
   647
  "?p5 : (P --> P) <-> True"
wenzelm@26322
   648
  "?p6 : (P --> ~P) <-> ~P"
wenzelm@26322
   649
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   650
  done
wenzelm@26322
   651
wenzelm@36319
   652
schematic_lemma iff_rews:
wenzelm@26322
   653
  "?p1 : (True <-> P) <-> P"
wenzelm@26322
   654
  "?p2 : (P <-> True) <-> P"
wenzelm@26322
   655
  "?p3 : (P <-> P) <-> True"
wenzelm@26322
   656
  "?p4 : (False <-> P) <-> ~P"
wenzelm@26322
   657
  "?p5 : (P <-> False) <-> ~P"
wenzelm@26322
   658
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   659
  done
wenzelm@26322
   660
wenzelm@36319
   661
schematic_lemma quant_rews:
wenzelm@26322
   662
  "?p1 : (ALL x. P) <-> P"
wenzelm@26322
   663
  "?p2 : (EX x. P) <-> P"
wenzelm@26322
   664
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   665
  done
wenzelm@26322
   666
wenzelm@26322
   667
(*These are NOT supplied by default!*)
wenzelm@36319
   668
schematic_lemma distrib_rews1:
wenzelm@26322
   669
  "?p1 : ~(P|Q) <-> ~P & ~Q"
wenzelm@26322
   670
  "?p2 : P & (Q | R) <-> P&Q | P&R"
wenzelm@26322
   671
  "?p3 : (Q | R) & P <-> Q&P | R&P"
wenzelm@26322
   672
  "?p4 : (P | Q --> R) <-> (P --> R) & (Q --> R)"
wenzelm@26322
   673
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   674
  done
wenzelm@26322
   675
wenzelm@36319
   676
schematic_lemma distrib_rews2:
wenzelm@26322
   677
  "?p1 : ~(EX x. NORM(P(x))) <-> (ALL x. ~NORM(P(x)))"
wenzelm@26322
   678
  "?p2 : ((EX x. NORM(P(x))) --> Q) <-> (ALL x. NORM(P(x)) --> Q)"
wenzelm@26322
   679
  "?p3 : (EX x. NORM(P(x))) & NORM(Q) <-> (EX x. NORM(P(x)) & NORM(Q))"
wenzelm@26322
   680
  "?p4 : NORM(Q) & (EX x. NORM(P(x))) <-> (EX x. NORM(Q) & NORM(P(x)))"
wenzelm@26322
   681
  apply (tactic {* IntPr.fast_tac 1 *})+
wenzelm@26322
   682
  done
wenzelm@26322
   683
wenzelm@26322
   684
lemmas distrib_rews = distrib_rews1 distrib_rews2
wenzelm@26322
   685
wenzelm@36319
   686
schematic_lemma P_Imp_P_iff_T: "p:P ==> ?p:(P <-> True)"
wenzelm@26322
   687
  apply (tactic {* IntPr.fast_tac 1 *})
wenzelm@26322
   688
  done
wenzelm@26322
   689
wenzelm@36319
   690
schematic_lemma not_P_imp_P_iff_F: "p:~P ==> ?p:(P <-> False)"
wenzelm@26322
   691
  apply (tactic {* IntPr.fast_tac 1 *})
wenzelm@26322
   692
  done
clasohm@0
   693
clasohm@0
   694
end