src/Sequents/LK0.thy
author bulwahn
Tue Aug 31 08:00:53 2010 +0200 (2010-08-31)
changeset 38950 62578950e748
parent 38499 8f0cd11238a7
child 39159 0dec18004e75
permissions -rw-r--r--
storing options for prolog code generation in the theory
wenzelm@17481
     1
(*  Title:      LK/LK0.thy
paulson@7093
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@7093
     3
    Copyright   1993  University of Cambridge
paulson@7093
     4
paulson@7093
     5
There may be printing problems if a seqent is in expanded normal form
wenzelm@35113
     6
(eta-expanded, beta-contracted).
paulson@7093
     7
*)
paulson@7093
     8
wenzelm@17481
     9
header {* Classical First-Order Sequent Calculus *}
wenzelm@17481
    10
wenzelm@17481
    11
theory LK0
wenzelm@17481
    12
imports Sequents
wenzelm@17481
    13
begin
paulson@7093
    14
wenzelm@17481
    15
classes "term"
wenzelm@36452
    16
default_sort "term"
paulson@7093
    17
paulson@7093
    18
consts
paulson@7093
    19
wenzelm@21524
    20
  Trueprop       :: "two_seqi"
paulson@7093
    21
wenzelm@17481
    22
  True         :: o
wenzelm@17481
    23
  False        :: o
wenzelm@22894
    24
  equal        :: "['a,'a] => o"     (infixl "=" 50)
wenzelm@17481
    25
  Not          :: "o => o"           ("~ _" [40] 40)
wenzelm@22894
    26
  conj         :: "[o,o] => o"       (infixr "&" 35)
wenzelm@22894
    27
  disj         :: "[o,o] => o"       (infixr "|" 30)
wenzelm@22894
    28
  imp          :: "[o,o] => o"       (infixr "-->" 25)
wenzelm@22894
    29
  iff          :: "[o,o] => o"       (infixr "<->" 25)
wenzelm@17481
    30
  The          :: "('a => o) => 'a"  (binder "THE " 10)
wenzelm@17481
    31
  All          :: "('a => o) => o"   (binder "ALL " 10)
wenzelm@17481
    32
  Ex           :: "('a => o) => o"   (binder "EX " 10)
paulson@7093
    33
paulson@7093
    34
syntax
wenzelm@35113
    35
 "_Trueprop"    :: "two_seqe" ("((_)/ |- (_))" [6,6] 5)
wenzelm@17481
    36
wenzelm@35113
    37
parse_translation {* [(@{syntax_const "_Trueprop"}, two_seq_tr @{const_syntax Trueprop})] *}
wenzelm@35113
    38
print_translation {* [(@{const_syntax Trueprop}, two_seq_tr' @{syntax_const "_Trueprop"})] *}
paulson@7093
    39
wenzelm@22894
    40
abbreviation
wenzelm@22894
    41
  not_equal  (infixl "~=" 50) where
wenzelm@22894
    42
  "x ~= y == ~ (x = y)"
paulson@7093
    43
wenzelm@35355
    44
notation (xsymbols)
wenzelm@35355
    45
  Not  ("\<not> _" [40] 40) and
wenzelm@35355
    46
  conj  (infixr "\<and>" 35) and
wenzelm@35355
    47
  disj  (infixr "\<or>" 30) and
wenzelm@35355
    48
  imp  (infixr "\<longrightarrow>" 25) and
wenzelm@35355
    49
  iff  (infixr "\<longleftrightarrow>" 25) and
wenzelm@35355
    50
  All  (binder "\<forall>" 10) and
wenzelm@35355
    51
  Ex  (binder "\<exists>" 10) and
wenzelm@35355
    52
  not_equal  (infixl "\<noteq>" 50)
paulson@7093
    53
wenzelm@35355
    54
notation (HTML output)
wenzelm@35355
    55
  Not  ("\<not> _" [40] 40) and
wenzelm@35355
    56
  conj  (infixr "\<and>" 35) and
wenzelm@35355
    57
  disj  (infixr "\<or>" 30) and
wenzelm@35355
    58
  All  (binder "\<forall>" 10) and
wenzelm@35355
    59
  Ex  (binder "\<exists>" 10) and
wenzelm@35355
    60
  not_equal  (infixl "\<noteq>" 50)
paulson@7093
    61
wenzelm@17481
    62
axioms
paulson@7093
    63
paulson@7093
    64
  (*Structural rules: contraction, thinning, exchange [Soren Heilmann] *)
paulson@7093
    65
wenzelm@17481
    66
  contRS: "$H |- $E, $S, $S, $F ==> $H |- $E, $S, $F"
wenzelm@17481
    67
  contLS: "$H, $S, $S, $G |- $E ==> $H, $S, $G |- $E"
paulson@7093
    68
wenzelm@17481
    69
  thinRS: "$H |- $E, $F ==> $H |- $E, $S, $F"
wenzelm@17481
    70
  thinLS: "$H, $G |- $E ==> $H, $S, $G |- $E"
paulson@7093
    71
wenzelm@17481
    72
  exchRS: "$H |- $E, $R, $S, $F ==> $H |- $E, $S, $R, $F"
wenzelm@17481
    73
  exchLS: "$H, $R, $S, $G |- $E ==> $H, $S, $R, $G |- $E"
paulson@7093
    74
wenzelm@17481
    75
  cut:   "[| $H |- $E, P;  $H, P |- $E |] ==> $H |- $E"
paulson@7093
    76
paulson@7093
    77
  (*Propositional rules*)
paulson@7093
    78
wenzelm@17481
    79
  basic: "$H, P, $G |- $E, P, $F"
paulson@7093
    80
wenzelm@17481
    81
  conjR: "[| $H|- $E, P, $F;  $H|- $E, Q, $F |] ==> $H|- $E, P&Q, $F"
wenzelm@17481
    82
  conjL: "$H, P, Q, $G |- $E ==> $H, P & Q, $G |- $E"
paulson@7093
    83
wenzelm@17481
    84
  disjR: "$H |- $E, P, Q, $F ==> $H |- $E, P|Q, $F"
wenzelm@17481
    85
  disjL: "[| $H, P, $G |- $E;  $H, Q, $G |- $E |] ==> $H, P|Q, $G |- $E"
paulson@7093
    86
wenzelm@17481
    87
  impR:  "$H, P |- $E, Q, $F ==> $H |- $E, P-->Q, $F"
wenzelm@17481
    88
  impL:  "[| $H,$G |- $E,P;  $H, Q, $G |- $E |] ==> $H, P-->Q, $G |- $E"
paulson@7093
    89
wenzelm@17481
    90
  notR:  "$H, P |- $E, $F ==> $H |- $E, ~P, $F"
wenzelm@17481
    91
  notL:  "$H, $G |- $E, P ==> $H, ~P, $G |- $E"
paulson@7093
    92
wenzelm@17481
    93
  FalseL: "$H, False, $G |- $E"
paulson@7093
    94
wenzelm@17481
    95
  True_def: "True == False-->False"
wenzelm@17481
    96
  iff_def:  "P<->Q == (P-->Q) & (Q-->P)"
paulson@7093
    97
paulson@7093
    98
  (*Quantifiers*)
paulson@7093
    99
wenzelm@17481
   100
  allR:  "(!!x.$H |- $E, P(x), $F) ==> $H |- $E, ALL x. P(x), $F"
wenzelm@17481
   101
  allL:  "$H, P(x), $G, ALL x. P(x) |- $E ==> $H, ALL x. P(x), $G |- $E"
paulson@7093
   102
wenzelm@17481
   103
  exR:   "$H |- $E, P(x), $F, EX x. P(x) ==> $H |- $E, EX x. P(x), $F"
wenzelm@17481
   104
  exL:   "(!!x.$H, P(x), $G |- $E) ==> $H, EX x. P(x), $G |- $E"
paulson@7093
   105
paulson@7093
   106
  (*Equality*)
paulson@7093
   107
wenzelm@17481
   108
  refl:  "$H |- $E, a=a, $F"
wenzelm@17481
   109
  subst: "$H(a), $G(a) |- $E(a) ==> $H(b), a=b, $G(b) |- $E(b)"
paulson@7093
   110
paulson@7093
   111
  (* Reflection *)
paulson@7093
   112
wenzelm@17481
   113
  eq_reflection:  "|- x=y ==> (x==y)"
wenzelm@17481
   114
  iff_reflection: "|- P<->Q ==> (P==Q)"
paulson@7093
   115
paulson@7093
   116
  (*Descriptions*)
paulson@7093
   117
wenzelm@17481
   118
  The: "[| $H |- $E, P(a), $F;  !!x.$H, P(x) |- $E, x=a, $F |] ==>
paulson@7093
   119
          $H |- $E, P(THE x. P(x)), $F"
paulson@7093
   120
haftmann@35416
   121
definition If :: "[o, 'a, 'a] => 'a" ("(if (_)/ then (_)/ else (_))" 10) where 
paulson@7093
   122
   "If(P,x,y) == THE z::'a. (P --> z=x) & (~P --> z=y)"
paulson@7093
   123
wenzelm@21426
   124
wenzelm@21426
   125
(** Structural Rules on formulas **)
wenzelm@21426
   126
wenzelm@21426
   127
(*contraction*)
wenzelm@21426
   128
wenzelm@21426
   129
lemma contR: "$H |- $E, P, P, $F ==> $H |- $E, P, $F"
wenzelm@21426
   130
  by (rule contRS)
wenzelm@21426
   131
wenzelm@21426
   132
lemma contL: "$H, P, P, $G |- $E ==> $H, P, $G |- $E"
wenzelm@21426
   133
  by (rule contLS)
wenzelm@21426
   134
wenzelm@21426
   135
(*thinning*)
wenzelm@21426
   136
wenzelm@21426
   137
lemma thinR: "$H |- $E, $F ==> $H |- $E, P, $F"
wenzelm@21426
   138
  by (rule thinRS)
wenzelm@21426
   139
wenzelm@21426
   140
lemma thinL: "$H, $G |- $E ==> $H, P, $G |- $E"
wenzelm@21426
   141
  by (rule thinLS)
wenzelm@21426
   142
wenzelm@21426
   143
(*exchange*)
wenzelm@21426
   144
wenzelm@21426
   145
lemma exchR: "$H |- $E, Q, P, $F ==> $H |- $E, P, Q, $F"
wenzelm@21426
   146
  by (rule exchRS)
wenzelm@21426
   147
wenzelm@21426
   148
lemma exchL: "$H, Q, P, $G |- $E ==> $H, P, Q, $G |- $E"
wenzelm@21426
   149
  by (rule exchLS)
wenzelm@21426
   150
wenzelm@21426
   151
ML {*
wenzelm@21426
   152
(*Cut and thin, replacing the right-side formula*)
wenzelm@27208
   153
fun cutR_tac ctxt s i =
wenzelm@27239
   154
  res_inst_tac ctxt [(("P", 0), s) ] @{thm cut} i  THEN  rtac @{thm thinR} i
wenzelm@21426
   155
wenzelm@21426
   156
(*Cut and thin, replacing the left-side formula*)
wenzelm@27208
   157
fun cutL_tac ctxt s i =
wenzelm@27239
   158
  res_inst_tac ctxt [(("P", 0), s)] @{thm cut} i  THEN  rtac @{thm thinL} (i+1)
wenzelm@21426
   159
*}
wenzelm@21426
   160
wenzelm@21426
   161
wenzelm@21426
   162
(** If-and-only-if rules **)
wenzelm@21426
   163
lemma iffR: 
wenzelm@21426
   164
    "[| $H,P |- $E,Q,$F;  $H,Q |- $E,P,$F |] ==> $H |- $E, P <-> Q, $F"
wenzelm@21426
   165
  apply (unfold iff_def)
wenzelm@21426
   166
  apply (assumption | rule conjR impR)+
wenzelm@21426
   167
  done
wenzelm@21426
   168
wenzelm@21426
   169
lemma iffL: 
wenzelm@21426
   170
    "[| $H,$G |- $E,P,Q;  $H,Q,P,$G |- $E |] ==> $H, P <-> Q, $G |- $E"
wenzelm@21426
   171
  apply (unfold iff_def)
wenzelm@21426
   172
  apply (assumption | rule conjL impL basic)+
wenzelm@21426
   173
  done
wenzelm@21426
   174
wenzelm@21426
   175
lemma iff_refl: "$H |- $E, (P <-> P), $F"
wenzelm@21426
   176
  apply (rule iffR basic)+
wenzelm@21426
   177
  done
wenzelm@21426
   178
wenzelm@21426
   179
lemma TrueR: "$H |- $E, True, $F"
wenzelm@21426
   180
  apply (unfold True_def)
wenzelm@21426
   181
  apply (rule impR)
wenzelm@21426
   182
  apply (rule basic)
wenzelm@21426
   183
  done
wenzelm@21426
   184
wenzelm@21426
   185
(*Descriptions*)
wenzelm@21426
   186
lemma the_equality:
wenzelm@21426
   187
  assumes p1: "$H |- $E, P(a), $F"
wenzelm@21426
   188
    and p2: "!!x. $H, P(x) |- $E, x=a, $F"
wenzelm@21426
   189
  shows "$H |- $E, (THE x. P(x)) = a, $F"
wenzelm@21426
   190
  apply (rule cut)
wenzelm@21426
   191
   apply (rule_tac [2] p2)
wenzelm@21426
   192
  apply (rule The, rule thinR, rule exchRS, rule p1)
wenzelm@21426
   193
  apply (rule thinR, rule exchRS, rule p2)
wenzelm@21426
   194
  done
wenzelm@21426
   195
wenzelm@21426
   196
wenzelm@21426
   197
(** Weakened quantifier rules.  Incomplete, they let the search terminate.**)
wenzelm@21426
   198
wenzelm@21426
   199
lemma allL_thin: "$H, P(x), $G |- $E ==> $H, ALL x. P(x), $G |- $E"
wenzelm@21426
   200
  apply (rule allL)
wenzelm@21426
   201
  apply (erule thinL)
wenzelm@21426
   202
  done
wenzelm@21426
   203
wenzelm@21426
   204
lemma exR_thin: "$H |- $E, P(x), $F ==> $H |- $E, EX x. P(x), $F"
wenzelm@21426
   205
  apply (rule exR)
wenzelm@21426
   206
  apply (erule thinR)
wenzelm@21426
   207
  done
wenzelm@21426
   208
wenzelm@21426
   209
(*The rules of LK*)
wenzelm@21426
   210
wenzelm@21426
   211
ML {*
wenzelm@21426
   212
val prop_pack = empty_pack add_safes
wenzelm@21426
   213
                [thm "basic", thm "refl", thm "TrueR", thm "FalseL",
wenzelm@21426
   214
                 thm "conjL", thm "conjR", thm "disjL", thm "disjR", thm "impL", thm "impR",
wenzelm@21426
   215
                 thm "notL", thm "notR", thm "iffL", thm "iffR"];
wenzelm@21426
   216
wenzelm@21426
   217
val LK_pack = prop_pack add_safes   [thm "allR", thm "exL"]
wenzelm@21426
   218
                        add_unsafes [thm "allL_thin", thm "exR_thin", thm "the_equality"];
wenzelm@21426
   219
wenzelm@21426
   220
val LK_dup_pack = prop_pack add_safes   [thm "allR", thm "exL"]
wenzelm@21426
   221
                            add_unsafes [thm "allL", thm "exR", thm "the_equality"];
wenzelm@21426
   222
wenzelm@21426
   223
wenzelm@21426
   224
local
wenzelm@21426
   225
  val thinR = thm "thinR"
wenzelm@21426
   226
  val thinL = thm "thinL"
wenzelm@21426
   227
  val cut = thm "cut"
wenzelm@21426
   228
in
wenzelm@21426
   229
wenzelm@21426
   230
fun lemma_tac th i =
wenzelm@21426
   231
    rtac (thinR RS cut) i THEN REPEAT (rtac thinL i) THEN rtac th i;
wenzelm@21426
   232
wenzelm@21426
   233
end;
wenzelm@21426
   234
*}
wenzelm@21426
   235
wenzelm@21426
   236
method_setup fast_prop =
wenzelm@30549
   237
  {* Scan.succeed (K (SIMPLE_METHOD' (fast_tac prop_pack))) *}
wenzelm@21426
   238
  "propositional reasoning"
wenzelm@21426
   239
wenzelm@21426
   240
method_setup fast =
wenzelm@30549
   241
  {* Scan.succeed (K (SIMPLE_METHOD' (fast_tac LK_pack))) *}
wenzelm@21426
   242
  "classical reasoning"
wenzelm@21426
   243
wenzelm@21426
   244
method_setup fast_dup =
wenzelm@30549
   245
  {* Scan.succeed (K (SIMPLE_METHOD' (fast_tac LK_dup_pack))) *}
wenzelm@21426
   246
  "classical reasoning"
wenzelm@21426
   247
wenzelm@21426
   248
method_setup best =
wenzelm@30549
   249
  {* Scan.succeed (K (SIMPLE_METHOD' (best_tac LK_pack))) *}
wenzelm@21426
   250
  "classical reasoning"
wenzelm@21426
   251
wenzelm@21426
   252
method_setup best_dup =
wenzelm@30549
   253
  {* Scan.succeed (K (SIMPLE_METHOD' (best_tac LK_dup_pack))) *}
wenzelm@21426
   254
  "classical reasoning"
paulson@7093
   255
paulson@7118
   256
wenzelm@21426
   257
lemma mp_R:
wenzelm@21426
   258
  assumes major: "$H |- $E, $F, P --> Q"
wenzelm@21426
   259
    and minor: "$H |- $E, $F, P"
wenzelm@21426
   260
  shows "$H |- $E, Q, $F"
wenzelm@21426
   261
  apply (rule thinRS [THEN cut], rule major)
wenzelm@21426
   262
  apply (tactic "step_tac LK_pack 1")
wenzelm@21426
   263
  apply (rule thinR, rule minor)
wenzelm@21426
   264
  done
wenzelm@21426
   265
wenzelm@21426
   266
lemma mp_L:
wenzelm@21426
   267
  assumes major: "$H, $G |- $E, P --> Q"
wenzelm@21426
   268
    and minor: "$H, $G, Q |- $E"
wenzelm@21426
   269
  shows "$H, P, $G |- $E"
wenzelm@21426
   270
  apply (rule thinL [THEN cut], rule major)
wenzelm@21426
   271
  apply (tactic "step_tac LK_pack 1")
wenzelm@21426
   272
  apply (rule thinL, rule minor)
wenzelm@21426
   273
  done
wenzelm@21426
   274
wenzelm@21426
   275
wenzelm@21426
   276
(** Two rules to generate left- and right- rules from implications **)
wenzelm@21426
   277
wenzelm@21426
   278
lemma R_of_imp:
wenzelm@21426
   279
  assumes major: "|- P --> Q"
wenzelm@21426
   280
    and minor: "$H |- $E, $F, P"
wenzelm@21426
   281
  shows "$H |- $E, Q, $F"
wenzelm@21426
   282
  apply (rule mp_R)
wenzelm@21426
   283
   apply (rule_tac [2] minor)
wenzelm@21426
   284
  apply (rule thinRS, rule major [THEN thinLS])
wenzelm@21426
   285
  done
wenzelm@21426
   286
wenzelm@21426
   287
lemma L_of_imp:
wenzelm@21426
   288
  assumes major: "|- P --> Q"
wenzelm@21426
   289
    and minor: "$H, $G, Q |- $E"
wenzelm@21426
   290
  shows "$H, P, $G |- $E"
wenzelm@21426
   291
  apply (rule mp_L)
wenzelm@21426
   292
   apply (rule_tac [2] minor)
wenzelm@21426
   293
  apply (rule thinRS, rule major [THEN thinLS])
wenzelm@21426
   294
  done
wenzelm@21426
   295
wenzelm@21426
   296
(*Can be used to create implications in a subgoal*)
wenzelm@21426
   297
lemma backwards_impR:
wenzelm@21426
   298
  assumes prem: "$H, $G |- $E, $F, P --> Q"
wenzelm@21426
   299
  shows "$H, P, $G |- $E, Q, $F"
wenzelm@21426
   300
  apply (rule mp_L)
wenzelm@21426
   301
   apply (rule_tac [2] basic)
wenzelm@21426
   302
  apply (rule thinR, rule prem)
wenzelm@21426
   303
  done
wenzelm@21426
   304
wenzelm@21426
   305
lemma conjunct1: "|-P&Q ==> |-P"
wenzelm@21426
   306
  apply (erule thinR [THEN cut])
wenzelm@21426
   307
  apply fast
wenzelm@21426
   308
  done
wenzelm@21426
   309
wenzelm@21426
   310
lemma conjunct2: "|-P&Q ==> |-Q"
wenzelm@21426
   311
  apply (erule thinR [THEN cut])
wenzelm@21426
   312
  apply fast
wenzelm@21426
   313
  done
wenzelm@21426
   314
wenzelm@21426
   315
lemma spec: "|- (ALL x. P(x)) ==> |- P(x)"
wenzelm@21426
   316
  apply (erule thinR [THEN cut])
wenzelm@21426
   317
  apply fast
wenzelm@21426
   318
  done
wenzelm@21426
   319
wenzelm@21426
   320
wenzelm@21426
   321
(** Equality **)
wenzelm@21426
   322
wenzelm@21426
   323
lemma sym: "|- a=b --> b=a"
wenzelm@21426
   324
  by (tactic {* safe_tac (LK_pack add_safes [thm "subst"]) 1 *})
wenzelm@21426
   325
wenzelm@21426
   326
lemma trans: "|- a=b --> b=c --> a=c"
wenzelm@21426
   327
  by (tactic {* safe_tac (LK_pack add_safes [thm "subst"]) 1 *})
wenzelm@21426
   328
wenzelm@21426
   329
(* Symmetry of equality in hypotheses *)
wenzelm@21426
   330
lemmas symL = sym [THEN L_of_imp, standard]
wenzelm@21426
   331
wenzelm@21426
   332
(* Symmetry of equality in hypotheses *)
wenzelm@21426
   333
lemmas symR = sym [THEN R_of_imp, standard]
wenzelm@21426
   334
wenzelm@21426
   335
lemma transR: "[| $H|- $E, $F, a=b;  $H|- $E, $F, b=c |] ==> $H|- $E, a=c, $F"
wenzelm@21426
   336
  by (rule trans [THEN R_of_imp, THEN mp_R])
wenzelm@21426
   337
wenzelm@21426
   338
(* Two theorms for rewriting only one instance of a definition:
wenzelm@21426
   339
   the first for definitions of formulae and the second for terms *)
wenzelm@21426
   340
wenzelm@21426
   341
lemma def_imp_iff: "(A == B) ==> |- A <-> B"
wenzelm@21426
   342
  apply unfold
wenzelm@21426
   343
  apply (rule iff_refl)
wenzelm@21426
   344
  done
wenzelm@21426
   345
wenzelm@21426
   346
lemma meta_eq_to_obj_eq: "(A == B) ==> |- A = B"
wenzelm@21426
   347
  apply unfold
wenzelm@21426
   348
  apply (rule refl)
wenzelm@21426
   349
  done
wenzelm@21426
   350
wenzelm@21426
   351
wenzelm@21426
   352
(** if-then-else rules **)
wenzelm@21426
   353
wenzelm@21426
   354
lemma if_True: "|- (if True then x else y) = x"
wenzelm@21426
   355
  unfolding If_def by fast
wenzelm@21426
   356
wenzelm@21426
   357
lemma if_False: "|- (if False then x else y) = y"
wenzelm@21426
   358
  unfolding If_def by fast
wenzelm@21426
   359
wenzelm@21426
   360
lemma if_P: "|- P ==> |- (if P then x else y) = x"
wenzelm@21426
   361
  apply (unfold If_def)
wenzelm@21426
   362
  apply (erule thinR [THEN cut])
wenzelm@21426
   363
  apply fast
wenzelm@21426
   364
  done
wenzelm@21426
   365
wenzelm@21426
   366
lemma if_not_P: "|- ~P ==> |- (if P then x else y) = y";
wenzelm@21426
   367
  apply (unfold If_def)
wenzelm@21426
   368
  apply (erule thinR [THEN cut])
wenzelm@21426
   369
  apply fast
wenzelm@21426
   370
  done
wenzelm@21426
   371
wenzelm@21426
   372
end