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