src/FOL/simpdata.ML
author paulson
Wed Oct 09 13:36:17 1996 +0200 (1996-10-09)
changeset 2074 30a65172e003
parent 2065 b696f087f052
child 2469 b50b8c0eec01
permissions -rw-r--r--
Added the de Morgan laws (incl quantifier versions) to basic simpset
clasohm@1459
     1
(*  Title:      FOL/simpdata
clasohm@0
     2
    ID:         $Id$
clasohm@1459
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@282
     4
    Copyright   1994  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Simplification data for FOL
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
(*** Rewrite rules ***)
clasohm@0
    10
clasohm@0
    11
fun int_prove_fun s = 
lcp@282
    12
 (writeln s;  
lcp@282
    13
  prove_goal IFOL.thy s
lcp@282
    14
   (fn prems => [ (cut_facts_tac prems 1), 
clasohm@1459
    15
                  (Int.fast_tac 1) ]));
clasohm@0
    16
paulson@1953
    17
val conj_simps = map int_prove_fun
clasohm@1459
    18
 ["P & True <-> P",      "True & P <-> P",
clasohm@0
    19
  "P & False <-> False", "False & P <-> False",
clasohm@0
    20
  "P & P <-> P",
clasohm@1459
    21
  "P & ~P <-> False",    "~P & P <-> False",
clasohm@0
    22
  "(P & Q) & R <-> P & (Q & R)"];
clasohm@0
    23
paulson@1953
    24
val disj_simps = map int_prove_fun
clasohm@1459
    25
 ["P | True <-> True",  "True | P <-> True",
clasohm@1459
    26
  "P | False <-> P",    "False | P <-> P",
clasohm@0
    27
  "P | P <-> P",
clasohm@0
    28
  "(P | Q) | R <-> P | (Q | R)"];
clasohm@0
    29
paulson@1953
    30
val not_simps = map int_prove_fun
lcp@282
    31
 ["~(P|Q)  <-> ~P & ~Q",
clasohm@1459
    32
  "~ False <-> True",   "~ True <-> False"];
clasohm@0
    33
paulson@1953
    34
val imp_simps = map int_prove_fun
clasohm@1459
    35
 ["(P --> False) <-> ~P",       "(P --> True) <-> True",
clasohm@1459
    36
  "(False --> P) <-> True",     "(True --> P) <-> P", 
clasohm@1459
    37
  "(P --> P) <-> True",         "(P --> ~P) <-> ~P"];
clasohm@0
    38
paulson@1953
    39
val iff_simps = map int_prove_fun
clasohm@1459
    40
 ["(True <-> P) <-> P",         "(P <-> True) <-> P",
clasohm@0
    41
  "(P <-> P) <-> True",
clasohm@1459
    42
  "(False <-> P) <-> ~P",       "(P <-> False) <-> ~P"];
clasohm@0
    43
paulson@1953
    44
val quant_simps = map int_prove_fun
clasohm@1459
    45
 ["(ALL x.P) <-> P",    "(EX x.P) <-> P"];
clasohm@0
    46
clasohm@0
    47
(*These are NOT supplied by default!*)
paulson@1953
    48
val distrib_simps  = map int_prove_fun
lcp@282
    49
 ["P & (Q | R) <-> P&Q | P&R", 
lcp@282
    50
  "(Q | R) & P <-> Q&P | R&P",
clasohm@0
    51
  "(P | Q --> R) <-> (P --> R) & (Q --> R)"];
clasohm@0
    52
lcp@282
    53
(** Conversion into rewrite rules **)
clasohm@0
    54
nipkow@53
    55
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
nipkow@53
    56
lcp@282
    57
(*Make atomic rewrite rules*)
lcp@429
    58
fun atomize r =
lcp@429
    59
  case concl_of r of
lcp@429
    60
    Const("Trueprop",_) $ p =>
lcp@429
    61
      (case p of
clasohm@1459
    62
         Const("op -->",_)$_$_ => atomize(r RS mp)
lcp@429
    63
       | Const("op &",_)$_$_   => atomize(r RS conjunct1) @
clasohm@1459
    64
                                  atomize(r RS conjunct2)
lcp@429
    65
       | Const("All",_)$_      => atomize(r RS spec)
clasohm@1459
    66
       | Const("True",_)       => []    (*True is DELETED*)
clasohm@1459
    67
       | Const("False",_)      => []    (*should False do something?*)
lcp@429
    68
       | _                     => [r])
lcp@429
    69
  | _ => [r];
lcp@429
    70
lcp@282
    71
lcp@282
    72
val P_iff_F = int_prove_fun "~P ==> (P <-> False)";
lcp@282
    73
val iff_reflection_F = P_iff_F RS iff_reflection;
lcp@282
    74
lcp@282
    75
val P_iff_T = int_prove_fun "P ==> (P <-> True)";
lcp@282
    76
val iff_reflection_T = P_iff_T RS iff_reflection;
lcp@282
    77
lcp@282
    78
(*Make meta-equalities.  The operator below is Trueprop*)
lcp@282
    79
fun mk_meta_eq th = case concl_of th of
nipkow@394
    80
    Const("==",_)$_$_           => th
nipkow@394
    81
  | _ $ (Const("op =",_)$_$_)   => th RS eq_reflection
lcp@282
    82
  | _ $ (Const("op <->",_)$_$_) => th RS iff_reflection
lcp@282
    83
  | _ $ (Const("Not",_)$_)      => th RS iff_reflection_F
lcp@282
    84
  | _                           => th RS iff_reflection_T;
clasohm@0
    85
lcp@981
    86
paulson@2074
    87
(*** Classical laws ***)
lcp@282
    88
clasohm@0
    89
fun prove_fun s = 
lcp@282
    90
 (writeln s;  
lcp@282
    91
  prove_goal FOL.thy s
lcp@282
    92
   (fn prems => [ (cut_facts_tac prems 1), 
clasohm@1459
    93
                  (Cla.fast_tac FOL_cs 1) ]));
lcp@745
    94
paulson@1953
    95
(*Avoids duplication of subgoals after expand_if, when the true and false 
paulson@1953
    96
  cases boil down to the same thing.*) 
paulson@1953
    97
val cases_simp = prove_fun "(P --> Q) & (~P --> Q) <-> Q";
paulson@1953
    98
paulson@1953
    99
(*At present, miniscoping is for classical logic only.  We do NOT include
paulson@1953
   100
  distribution of ALL over &, or dually that of EX over |.*)
clasohm@0
   101
paulson@1953
   102
(*Miniscoping: pushing in existential quantifiers*)
paulson@1953
   103
val ex_simps = map prove_fun 
paulson@2065
   104
                ["(EX x. x=t & P(x)) <-> P(t)",
paulson@2065
   105
                 "(EX x. t=x & P(x)) <-> P(t)",
paulson@2065
   106
                 "(EX x. P(x) & Q) <-> (EX x.P(x)) & Q",
paulson@1953
   107
                 "(EX x. P & Q(x)) <-> P & (EX x.Q(x))",
paulson@1953
   108
                 "(EX x. P(x) | Q) <-> (EX x.P(x)) | Q",
paulson@1953
   109
                 "(EX x. P | Q(x)) <-> P | (EX x.Q(x))",
paulson@1953
   110
                 "(EX x. P(x) --> Q) <-> (ALL x.P(x)) --> Q",
paulson@1953
   111
                 "(EX x. P --> Q(x)) <-> P --> (EX x.Q(x))"];
paulson@1953
   112
paulson@1953
   113
(*Miniscoping: pushing in universal quantifiers*)
paulson@1953
   114
val all_simps = map prove_fun
paulson@2065
   115
                ["(ALL x. x=t --> P(x)) <-> P(t)",
paulson@2065
   116
                 "(ALL x. t=x --> P(x)) <-> P(t)",
paulson@2065
   117
                 "(ALL x. P(x) & Q) <-> (ALL x.P(x)) & Q",
paulson@1953
   118
                 "(ALL x. P & Q(x)) <-> P & (ALL x.Q(x))",
paulson@1953
   119
                 "(ALL x. P(x) | Q) <-> (ALL x.P(x)) | Q",
paulson@1953
   120
                 "(ALL x. P | Q(x)) <-> P | (ALL x.Q(x))",
paulson@1953
   121
                 "(ALL x. P(x) --> Q) <-> (EX x.P(x)) --> Q",
paulson@1953
   122
                 "(ALL x. P --> Q(x)) <-> P --> (ALL x.Q(x))"];
paulson@1953
   123
paulson@1914
   124
fun int_prove nm thm  = qed_goal nm IFOL.thy thm
paulson@1914
   125
    (fn prems => [ (cut_facts_tac prems 1), 
paulson@1914
   126
                   (Int.fast_tac 1) ]);
paulson@1914
   127
paulson@1914
   128
fun prove nm thm  = qed_goal nm FOL.thy thm (fn _ => [fast_tac FOL_cs 1]);
paulson@1914
   129
paulson@1914
   130
int_prove "conj_commute" "P&Q <-> Q&P";
paulson@1914
   131
int_prove "conj_left_commute" "P&(Q&R) <-> Q&(P&R)";
paulson@1914
   132
val conj_comms = [conj_commute, conj_left_commute];
paulson@1914
   133
paulson@1914
   134
int_prove "disj_commute" "P|Q <-> Q|P";
paulson@1914
   135
int_prove "disj_left_commute" "P|(Q|R) <-> Q|(P|R)";
paulson@1914
   136
val disj_comms = [disj_commute, disj_left_commute];
paulson@1914
   137
paulson@1914
   138
int_prove "conj_disj_distribL" "P&(Q|R) <-> (P&Q | P&R)";
paulson@1914
   139
int_prove "conj_disj_distribR" "(P|Q)&R <-> (P&R | Q&R)";
paulson@1914
   140
paulson@1914
   141
int_prove "disj_conj_distribL" "P|(Q&R) <-> (P|Q) & (P|R)";
paulson@1914
   142
int_prove "disj_conj_distribR" "(P&Q)|R <-> (P|R) & (Q|R)";
paulson@1914
   143
paulson@1914
   144
int_prove "imp_conj_distrib" "(P --> (Q&R)) <-> (P-->Q) & (P-->R)";
paulson@1914
   145
int_prove "imp_conj"         "((P&Q)-->R)   <-> (P --> (Q --> R))";
paulson@1914
   146
int_prove "imp_disj"         "(P|Q --> R)   <-> (P-->R) & (Q-->R)";
paulson@1914
   147
paulson@1914
   148
int_prove "de_Morgan_disj" "(~(P | Q)) <-> (~P & ~Q)";
paulson@1914
   149
prove     "de_Morgan_conj" "(~(P & Q)) <-> (~P | ~Q)";
paulson@1914
   150
paulson@1914
   151
prove     "not_iff" "~(P <-> Q) <-> (P <-> ~Q)";
paulson@1914
   152
paulson@1914
   153
prove     "not_all" "(~ (ALL x.P(x))) <-> (EX x.~P(x))";
paulson@1914
   154
prove     "imp_all" "((ALL x.P(x)) --> Q) <-> (EX x.P(x) --> Q)";
paulson@1914
   155
int_prove "not_ex"  "(~ (EX x.P(x))) <-> (ALL x.~P(x))";
paulson@1914
   156
int_prove "imp_ex" "((EX x. P(x)) --> Q) <-> (ALL x. P(x) --> Q)";
paulson@1914
   157
paulson@1914
   158
int_prove "ex_disj_distrib"
paulson@1914
   159
    "(EX x. P(x) | Q(x)) <-> ((EX x. P(x)) | (EX x. Q(x)))";
paulson@1914
   160
int_prove "all_conj_distrib"
paulson@1914
   161
    "(ALL x. P(x) & Q(x)) <-> ((ALL x. P(x)) & (ALL x. Q(x)))";
paulson@1914
   162
paulson@1914
   163
lcp@1088
   164
(*Used in ZF, perhaps elsewhere?*)
lcp@1088
   165
val meta_eq_to_obj_eq = prove_goal IFOL.thy "x==y ==> x=y"
lcp@1088
   166
  (fn [prem] => [rewtac prem, rtac refl 1]);
lcp@1088
   167
clasohm@0
   168
(*** case splitting ***)
clasohm@0
   169
lcp@1088
   170
qed_goal "meta_iffD" IFOL.thy "[| P==Q; Q |] ==> P"
clasohm@756
   171
        (fn [prem1,prem2] => [rewtac prem1, rtac prem2 1]);
lcp@282
   172
nipkow@942
   173
local val mktac = mk_case_split_tac meta_iffD
nipkow@942
   174
in
nipkow@942
   175
fun split_tac splits = mktac (map mk_meta_eq splits)
nipkow@942
   176
end;
berghofe@1722
   177
berghofe@1722
   178
local val mktac = mk_case_split_inside_tac meta_iffD
berghofe@1722
   179
in
berghofe@1722
   180
fun split_inside_tac splits = mktac (map mk_meta_eq splits)
berghofe@1722
   181
end;
berghofe@1722
   182
berghofe@1722
   183
paulson@2074
   184
(*** Standard simpsets ***)
paulson@2074
   185
paulson@2074
   186
structure Induction = InductionFun(struct val spec=IFOL.spec end);
paulson@2074
   187
paulson@2074
   188
open Simplifier Induction;
paulson@2074
   189
paulson@2074
   190
(*Add congruence rules for = or <-> (instead of ==) *)
paulson@2074
   191
infix 4 addcongs;
paulson@2074
   192
fun ss addcongs congs =
paulson@2074
   193
    ss addeqcongs (congs RL [eq_reflection,iff_reflection]);
paulson@2074
   194
paulson@2074
   195
(*Add a simpset to a classical set!*)
paulson@2074
   196
infix 4 addss;
paulson@2074
   197
fun cs addss ss = cs addbefore asm_full_simp_tac ss 1;
paulson@2074
   198
paulson@2074
   199
val IFOL_simps =
paulson@2074
   200
   [refl RS P_iff_T] @ conj_simps @ disj_simps @ not_simps @ 
paulson@2074
   201
    imp_simps @ iff_simps @ quant_simps;
paulson@2074
   202
paulson@2074
   203
val notFalseI = int_prove_fun "~False";
paulson@2074
   204
val triv_rls = [TrueI,refl,iff_refl,notFalseI];
paulson@2074
   205
paulson@2074
   206
val IFOL_ss = 
paulson@2074
   207
  empty_ss 
paulson@2074
   208
  setmksimps (map mk_meta_eq o atomize o gen_all)
paulson@2074
   209
  setsolver  (fn prems => resolve_tac (triv_rls@prems) 
paulson@2074
   210
                          ORELSE' assume_tac
paulson@2074
   211
                          ORELSE' etac FalseE)
paulson@2074
   212
  setsubgoaler asm_simp_tac
paulson@2074
   213
  addsimps IFOL_simps
paulson@2074
   214
  addcongs [imp_cong];
paulson@2074
   215
paulson@2074
   216
val cla_simps = 
paulson@2074
   217
    [de_Morgan_conj, de_Morgan_disj, not_all, not_ex, cases_simp] @
paulson@2074
   218
    map prove_fun
paulson@2074
   219
     ["~(P&Q)  <-> ~P | ~Q",
paulson@2074
   220
      "P | ~P",             "~P | P",
paulson@2074
   221
      "~ ~ P <-> P",        "(~P --> P) <-> P",
paulson@2074
   222
      "(~P <-> ~Q) <-> (P<->Q)"];
paulson@2074
   223
paulson@2074
   224
val FOL_ss = IFOL_ss addsimps (cla_simps @ ex_simps @ all_simps);
paulson@2074
   225