src/Sequents/simpdata.ML
author wenzelm
Mon, 20 Nov 2006 23:47:10 +0100
changeset 21426 87ac12bed1ab
parent 17892 62c397c17d18
child 21428 f84cf8e9cad8
permissions -rw-r--r--
converted legacy ML scripts;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     1
(*  Title:      Sequents/simpdata.ML
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     2
    ID:         $Id$
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     5
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     6
Instantiation of the generic simplifier for LK
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     7
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     8
Borrows from the DC simplifier of Soren Heilmann.
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
     9
*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    10
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    11
(*** Rewrite rules ***)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    12
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    13
local
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    14
  val subst = thm "subst"
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    15
in
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    16
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    17
fun prove_fun s =
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    18
 (writeln s;
17481
75166ebb619b converted to Isar theory format;
wenzelm
parents: 12725
diff changeset
    19
  prove_goal (the_context ()) s
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    20
   (fn prems => [ (cut_facts_tac prems 1),
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    21
                  (fast_tac (pack() add_safes [subst]) 1) ]));
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    22
end;
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    23
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    24
val conj_simps = map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    25
 ["|- P & True <-> P",      "|- True & P <-> P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    26
  "|- P & False <-> False", "|- False & P <-> False",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    27
  "|- P & P <-> P", "        |- P & P & Q <-> P & Q",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    28
  "|- P & ~P <-> False",    "|- ~P & P <-> False",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    29
  "|- (P & Q) & R <-> P & (Q & R)"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    30
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    31
val disj_simps = map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    32
 ["|- P | True <-> True",  "|- True | P <-> True",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    33
  "|- P | False <-> P",    "|- False | P <-> P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    34
  "|- P | P <-> P",        "|- P | P | Q <-> P | Q",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    35
  "|- (P | Q) | R <-> P | (Q | R)"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    36
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    37
val not_simps = map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    38
 ["|- ~ False <-> True",   "|- ~ True <-> False"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    39
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    40
val imp_simps = map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    41
 ["|- (P --> False) <-> ~P",       "|- (P --> True) <-> True",
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    42
  "|- (False --> P) <-> True",     "|- (True --> P) <-> P",
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    43
  "|- (P --> P) <-> True",         "|- (P --> ~P) <-> ~P"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    44
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    45
val iff_simps = map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    46
 ["|- (True <-> P) <-> P",         "|- (P <-> True) <-> P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    47
  "|- (P <-> P) <-> True",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    48
  "|- (False <-> P) <-> ~P",       "|- (P <-> False) <-> ~P"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    49
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    50
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    51
val quant_simps = map prove_fun
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    52
 ["|- (ALL x. P) <-> P",
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    53
  "|- (ALL x. x=t --> P(x)) <-> P(t)",
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    54
  "|- (ALL x. t=x --> P(x)) <-> P(t)",
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    55
  "|- (EX x. P) <-> P",
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    56
  "|- (EX x. x=t & P(x)) <-> P(t)",
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    57
  "|- (EX x. t=x & P(x)) <-> P(t)"];
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    58
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    59
(*** Miniscoping: pushing quantifiers in
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    60
     We do NOT distribute of ALL over &, or dually that of EX over |
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    61
     Baaz and Leitsch, On Skolemization and Proof Complexity (1994)
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    62
     show that this step can increase proof length!
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    63
***)
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    64
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    65
(*existential miniscoping*)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    66
val ex_simps = map prove_fun
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    67
                   ["|- (EX x. P(x) & Q) <-> (EX x. P(x)) & Q",
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    68
                    "|- (EX x. P & Q(x)) <-> P & (EX x. Q(x))",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    69
                    "|- (EX x. P(x) | Q) <-> (EX x. P(x)) | Q",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    70
                    "|- (EX x. P | Q(x)) <-> P | (EX x. Q(x))",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    71
                    "|- (EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    72
                    "|- (EX x. P --> Q(x)) <-> P --> (EX x. Q(x))"];
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    73
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    74
(*universal miniscoping*)
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    75
val all_simps = map prove_fun
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    76
                    ["|- (ALL x. P(x) & Q) <-> (ALL x. P(x)) & Q",
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    77
                     "|- (ALL x. P & Q(x)) <-> P & (ALL x. Q(x))",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    78
                     "|- (ALL x. P(x) --> Q) <-> (EX x. P(x)) --> Q",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    79
                     "|- (ALL x. P --> Q(x)) <-> P --> (ALL x. Q(x))",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    80
                     "|- (ALL x. P(x) | Q) <-> (ALL x. P(x)) | Q",
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    81
                     "|- (ALL x. P | Q(x)) <-> P | (ALL x. Q(x))"];
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
    82
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    83
(*These are NOT supplied by default!*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    84
val distrib_simps  = map prove_fun
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
    85
 ["|- P & (Q | R) <-> P&Q | P&R",
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    86
  "|- (Q | R) & P <-> Q&P | R&P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    87
  "|- (P | Q --> R) <-> (P --> R) & (Q --> R)"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    88
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    89
(** Conversion into rewrite rules **)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    90
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    91
local
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    92
  val mp_R = thm "mp_R";
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    93
  val conjunct1 = thm "conjunct1";
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    94
  val conjunct2 = thm "conjunct2";
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    95
  val spec = thm "spec";
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
    96
in
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    97
(*Make atomic rewrite rules*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    98
fun atomize r =
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
    99
 case concl_of r of
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   100
   Const("Trueprop",_) $ Abs(_,_,a) $ Abs(_,_,c) =>
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   101
     (case (forms_of_seq a, forms_of_seq c) of
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   102
        ([], [p]) =>
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   103
          (case p of
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   104
               Const("op -->",_)$_$_ => atomize(r RS mp_R)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   105
             | Const("op &",_)$_$_   => atomize(r RS conjunct1) @
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   106
                   atomize(r RS conjunct2)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   107
             | Const("All",_)$_      => atomize(r RS spec)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   108
             | Const("True",_)       => []    (*True is DELETED*)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   109
             | Const("False",_)      => []    (*should False do something?*)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   110
             | _                     => [r])
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   111
      | _ => [])  (*ignore theorem unless it has precisely one conclusion*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   112
 | _ => [r];
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   113
end;
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   114
9259
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   115
Goal "|- ~P ==> |- (P <-> False)";
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   116
by (etac (thm "thinR" RS (thm "cut")) 1);
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   117
by (Fast_tac 1);
9259
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   118
qed "P_iff_F";
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   119
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   120
bind_thm ("iff_reflection_F", thm "P_iff_F" RS thm "iff_reflection");
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   121
9259
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   122
Goal "|- P ==> |- (P <-> True)";
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   123
by (etac (thm "thinR" RS (thm "cut")) 1);
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   124
by (Fast_tac 1);
9259
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   125
qed "P_iff_T";
103acc345f75 removal of batch style, and tidying
paulson
parents: 7570
diff changeset
   126
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   127
bind_thm ("iff_reflection_T", thm "P_iff_T" RS thm "iff_reflection");
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   128
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   129
local
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   130
  val eq_reflection = thm "eq_reflection"
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   131
  val iff_reflection = thm "iff_reflection"
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   132
in
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   133
(*Make meta-equalities.*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   134
fun mk_meta_eq th = case concl_of th of
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   135
    Const("==",_)$_$_           => th
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   136
  | Const("Trueprop",_) $ Abs(_,_,a) $ Abs(_,_,c) =>
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   137
        (case (forms_of_seq a, forms_of_seq c) of
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   138
             ([], [p]) =>
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   139
                 (case p of
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   140
                      (Const("op =",_)$_$_)   => th RS eq_reflection
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   141
                    | (Const("op <->",_)$_$_) => th RS iff_reflection
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   142
                    | (Const("Not",_)$_)      => th RS iff_reflection_F
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   143
                    | _                       => th RS iff_reflection_T)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   144
           | _ => error ("addsimps: unable to use theorem\n" ^
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   145
                         string_of_thm th));
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   146
end;
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   147
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   148
(*Replace premises x=y, X<->Y by X==Y*)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   149
val mk_meta_prems =
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   150
    rule_by_tactic
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   151
      (REPEAT_FIRST (resolve_tac [thm "meta_eq_to_obj_eq", thm "def_imp_iff"]));
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   152
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   153
(*Congruence rules for = or <-> (instead of ==)*)
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   154
fun mk_meta_cong rl =
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   155
  standard(mk_meta_eq (mk_meta_prems rl))
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   156
  handle THM _ =>
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   157
  error("Premises and conclusion of congruence rules must use =-equality or <->");
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   158
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   159
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   160
(*** Named rewrite rules ***)
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   161
17481
75166ebb619b converted to Isar theory format;
wenzelm
parents: 12725
diff changeset
   162
fun prove nm thm  = qed_goal nm (the_context ()) thm
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   163
    (fn prems => [ (cut_facts_tac prems 1),
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   164
                   (fast_tac LK_pack 1) ]);
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   165
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   166
prove "conj_commute" "|- P&Q <-> Q&P";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   167
prove "conj_left_commute" "|- P&(Q&R) <-> Q&(P&R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   168
val conj_comms = [conj_commute, conj_left_commute];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   169
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   170
prove "disj_commute" "|- P|Q <-> Q|P";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   171
prove "disj_left_commute" "|- P|(Q|R) <-> Q|(P|R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   172
val disj_comms = [disj_commute, disj_left_commute];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   173
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   174
prove "conj_disj_distribL" "|- P&(Q|R) <-> (P&Q | P&R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   175
prove "conj_disj_distribR" "|- (P|Q)&R <-> (P&R | Q&R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   176
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   177
prove "disj_conj_distribL" "|- P|(Q&R) <-> (P|Q) & (P|R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   178
prove "disj_conj_distribR" "|- (P&Q)|R <-> (P|R) & (Q|R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   179
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   180
prove "imp_conj_distrib" "|- (P --> (Q&R)) <-> (P-->Q) & (P-->R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   181
prove "imp_conj"         "|- ((P&Q)-->R)   <-> (P --> (Q --> R))";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   182
prove "imp_disj"         "|- (P|Q --> R)   <-> (P-->R) & (Q-->R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   183
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   184
prove "imp_disj1" "|- (P-->Q) | R <-> (P-->Q | R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   185
prove "imp_disj2" "|- Q | (P-->R) <-> (P-->Q | R)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   186
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   187
prove "de_Morgan_disj" "|- (~(P | Q)) <-> (~P & ~Q)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   188
prove "de_Morgan_conj" "|- (~(P & Q)) <-> (~P | ~Q)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   189
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   190
prove "not_iff" "|- ~(P <-> Q) <-> (P <-> ~Q)";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   191
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   192
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   193
val [p1,p2] = Goal
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   194
    "[| |- P <-> P';  |- P' ==> |- Q <-> Q' |] ==> |- (P-->Q) <-> (P'-->Q')";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   195
by (lemma_tac p1 1);
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   196
by (Safe_tac 1);
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   197
by (REPEAT (rtac (thm "cut") 1
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   198
            THEN
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   199
            DEPTH_SOLVE_1 (resolve_tac [thm "thinL", thm "thinR", p2 COMP thm "monotonic"] 1)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   200
            THEN
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   201
            Safe_tac 1));
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   202
qed "imp_cong";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   203
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   204
val [p1,p2] = Goal
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   205
    "[| |- P <-> P';  |- P' ==> |- Q <-> Q' |] ==> |- (P&Q) <-> (P'&Q')";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   206
by (lemma_tac p1 1);
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   207
by (Safe_tac 1);
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   208
by (REPEAT (rtac (thm "cut") 1
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   209
            THEN
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   210
            DEPTH_SOLVE_1 (resolve_tac [thm "thinL", thm "thinR", p2 COMP thm "monotonic"] 1)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   211
            THEN
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   212
            Safe_tac 1));
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   213
qed "conj_cong";
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   214
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   215
Goal "|- (x=y) <-> (y=x)";
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   216
by (fast_tac (pack() add_safes [thm "subst"]) 1);
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   217
qed "eq_sym_conv";
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   218
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   219
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   220
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   221
(*** Standard simpsets ***)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   222
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   223
val triv_rls = [thm "FalseL", thm "TrueR", thm "basic", thm "refl",
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   224
  thm "iff_refl", reflexive_thm];
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   225
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   226
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls@prems),
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   227
                                 assume_tac];
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   228
(*No premature instantiation of variables during simplification*)
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   229
fun   safe_solver prems = FIRST'[fn i => DETERM (match_tac (triv_rls@prems) i),
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   230
                                 eq_assume_tac];
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   231
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   232
(*No simprules, but basic infrastructure for simplification*)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   233
val LK_basic_ss =
17892
62c397c17d18 Simplifier.theory_context;
wenzelm
parents: 17876
diff changeset
   234
  Simplifier.theory_context (the_context ()) empty_ss
62c397c17d18 Simplifier.theory_context;
wenzelm
parents: 17876
diff changeset
   235
    setsubgoaler asm_simp_tac
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   236
    setSSolver (mk_solver "safe" safe_solver)
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   237
    setSolver (mk_solver "unsafe" unsafe_solver)
12725
7ede865e1fe5 renamed forall_elim_vars_safe to gen_all;
wenzelm
parents: 12720
diff changeset
   238
    setmksimps (map mk_meta_eq o atomize o gen_all)
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   239
    setmkcong mk_meta_cong;
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   240
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   241
val LK_simps =
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   242
   [triv_forall_equality, (* prunes params *)
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   243
    thm "refl" RS P_iff_T] @
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   244
    conj_simps @ disj_simps @ not_simps @
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   245
    imp_simps @ iff_simps @quant_simps @ all_simps @ ex_simps @
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   246
    [de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2] @
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   247
    map prove_fun
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   248
     ["|- P | ~P",             "|- ~P | P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   249
      "|- ~ ~ P <-> P",        "|- (~P --> P) <-> P",
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   250
      "|- (~P <-> ~Q) <-> (P<->Q)"];
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   251
9713
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   252
val LK_ss =
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   253
  LK_basic_ss addsimps LK_simps
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   254
  addeqcongs [left_cong]
2c5b42311eb0 cong setup now part of Simplifier;
wenzelm
parents: 9259
diff changeset
   255
  addcongs [imp_cong];
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   256
17876
b9c92f384109 change_claset/simpset;
wenzelm
parents: 17481
diff changeset
   257
change_simpset (fn _ => LK_ss);
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   258
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   259
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   260
(* To create substition rules *)
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   261
17481
75166ebb619b converted to Isar theory format;
wenzelm
parents: 12725
diff changeset
   262
qed_goal "eq_imp_subst" (the_context ()) "|- a=b ==> $H, A(a), $G |- $E, A(b), $F"
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   263
  (fn prems =>
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   264
   [cut_facts_tac prems 1,
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   265
    asm_simp_tac LK_basic_ss 1]);
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   266
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   267
Goal "|- P(if Q then x else y) <-> ((Q --> P(x)) & (~Q --> P(y)))";
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   268
by (res_inst_tac [ ("P","Q") ] (thm "cut") 1);
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   269
by (simp_tac (simpset() addsimps [thm "if_P"]) 2);
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   270
by (res_inst_tac [ ("P","~Q") ] (thm "cut") 1);
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   271
by (simp_tac (simpset() addsimps [thm "if_not_P"]) 2);
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   272
by (Fast_tac 1);
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   273
qed "split_if";
7098
86583034aacf installation of simplifier and classical reasoner, better rules etc
paulson
parents:
diff changeset
   274
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   275
Goal "|- (if P then x else x) = x";
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   276
by (lemma_tac split_if 1);
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   277
by (Fast_tac 1);
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   278
qed "if_cancel";
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   279
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   280
Goal "|- (if x=y then y else x) = x";
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   281
by (lemma_tac split_if 1);
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   282
by (Safe_tac 1);
21426
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   283
by (rtac (thm "symL") 1);
87ac12bed1ab converted legacy ML scripts;
wenzelm
parents: 17892
diff changeset
   284
by (rtac (thm "basic") 1);
7123
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   285
qed "if_eq_cancel";
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   286
4ab38de3fd20 congruence rule for |-, etc.
paulson
parents: 7098
diff changeset
   287
(*Putting in automatic case splits seems to require a lot of work.*)