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