src/FOL/simpdata.ML
author paulson
Fri Nov 28 10:54:13 1997 +0100 (1997-11-28)
changeset 4325 e72cba5af6c5
parent 4203 ca73de799b73
child 4349 50403e5a44c0
permissions -rw-r--r--
addsplits now in FOL, ZF too
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), 
paulson@2601
    15
                  (IntPr.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",
nipkow@2801
    20
  "P & P <-> P", "P & P & Q <-> P & Q",
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",
nipkow@2801
    27
  "P | P <-> P", "P | P | Q <-> P | Q",
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
wenzelm@3835
    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)",
wenzelm@3835
   106
                 "(EX x. P(x) & Q) <-> (EX x. P(x)) & Q",
wenzelm@3835
   107
                 "(EX x. P & Q(x)) <-> P & (EX x. Q(x))",
wenzelm@3835
   108
                 "(EX x. P(x) | Q) <-> (EX x. P(x)) | Q",
wenzelm@3835
   109
                 "(EX x. P | Q(x)) <-> P | (EX x. Q(x))",
wenzelm@3835
   110
                 "(EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q",
wenzelm@3835
   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)",
wenzelm@3835
   117
                 "(ALL x. P(x) & Q) <-> (ALL x. P(x)) & Q",
wenzelm@3835
   118
                 "(ALL x. P & Q(x)) <-> P & (ALL x. Q(x))",
wenzelm@3835
   119
                 "(ALL x. P(x) | Q) <-> (ALL x. P(x)) | Q",
wenzelm@3835
   120
                 "(ALL x. P | Q(x)) <-> P | (ALL x. Q(x))",
wenzelm@3835
   121
                 "(ALL x. P(x) --> Q) <-> (EX x. P(x)) --> Q",
wenzelm@3835
   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@2601
   126
                   (IntPr.fast_tac 1) ]);
paulson@1914
   127
paulson@3910
   128
fun prove nm thm  = qed_goal nm FOL.thy thm (fn _ => [Blast_tac 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@3910
   148
prove "imp_disj1" "(P-->Q) | R <-> (P-->Q | R)";
paulson@3910
   149
prove "imp_disj2" "Q | (P-->R) <-> (P-->Q | R)";
paulson@3910
   150
paulson@1914
   151
int_prove "de_Morgan_disj" "(~(P | Q)) <-> (~P & ~Q)";
paulson@1914
   152
prove     "de_Morgan_conj" "(~(P & Q)) <-> (~P | ~Q)";
paulson@1914
   153
paulson@1914
   154
prove     "not_iff" "~(P <-> Q) <-> (P <-> ~Q)";
paulson@1914
   155
wenzelm@3835
   156
prove     "not_all" "(~ (ALL x. P(x))) <-> (EX x.~P(x))";
wenzelm@3835
   157
prove     "imp_all" "((ALL x. P(x)) --> Q) <-> (EX x. P(x) --> Q)";
wenzelm@3835
   158
int_prove "not_ex"  "(~ (EX x. P(x))) <-> (ALL x.~P(x))";
paulson@1914
   159
int_prove "imp_ex" "((EX x. P(x)) --> Q) <-> (ALL x. P(x) --> Q)";
paulson@1914
   160
paulson@1914
   161
int_prove "ex_disj_distrib"
paulson@1914
   162
    "(EX x. P(x) | Q(x)) <-> ((EX x. P(x)) | (EX x. Q(x)))";
paulson@1914
   163
int_prove "all_conj_distrib"
paulson@1914
   164
    "(ALL x. P(x) & Q(x)) <-> ((ALL x. P(x)) & (ALL x. Q(x)))";
paulson@1914
   165
paulson@1914
   166
lcp@1088
   167
(*Used in ZF, perhaps elsewhere?*)
lcp@1088
   168
val meta_eq_to_obj_eq = prove_goal IFOL.thy "x==y ==> x=y"
lcp@1088
   169
  (fn [prem] => [rewtac prem, rtac refl 1]);
lcp@1088
   170
clasohm@0
   171
(*** case splitting ***)
clasohm@0
   172
lcp@1088
   173
qed_goal "meta_iffD" IFOL.thy "[| P==Q; Q |] ==> P"
clasohm@756
   174
        (fn [prem1,prem2] => [rewtac prem1, rtac prem2 1]);
lcp@282
   175
nipkow@942
   176
local val mktac = mk_case_split_tac meta_iffD
nipkow@942
   177
in
nipkow@942
   178
fun split_tac splits = mktac (map mk_meta_eq splits)
nipkow@942
   179
end;
berghofe@1722
   180
berghofe@1722
   181
local val mktac = mk_case_split_inside_tac meta_iffD
berghofe@1722
   182
in
berghofe@1722
   183
fun split_inside_tac splits = mktac (map mk_meta_eq splits)
berghofe@1722
   184
end;
berghofe@1722
   185
oheimb@4203
   186
val split_asm_tac = mk_case_split_asm_tac split_tac 
oheimb@4203
   187
			(disjE,conjE,exE,contrapos,contrapos2,notnotD);
berghofe@1722
   188
paulson@4325
   189
paulson@4325
   190
paulson@2074
   191
(*** Standard simpsets ***)
paulson@2074
   192
paulson@2074
   193
structure Induction = InductionFun(struct val spec=IFOL.spec end);
paulson@2074
   194
paulson@2074
   195
open Simplifier Induction;
paulson@2074
   196
paulson@2074
   197
(*Add congruence rules for = or <-> (instead of ==) *)
oheimb@2633
   198
infix 4 addcongs delcongs;
paulson@2074
   199
fun ss addcongs congs =
wenzelm@3566
   200
        ss addeqcongs (map standard (congs RL [eq_reflection,iff_reflection]));
oheimb@2633
   201
fun ss delcongs congs =
wenzelm@3566
   202
        ss deleqcongs (map standard (congs RL [eq_reflection,iff_reflection]));
paulson@2469
   203
wenzelm@4094
   204
fun Addcongs congs = (simpset_ref() := simpset() addcongs congs);
wenzelm@4094
   205
fun Delcongs congs = (simpset_ref() := simpset() delcongs congs);
paulson@2074
   206
paulson@4325
   207
infix 4 addsplits;
paulson@4325
   208
fun ss addsplits splits = ss addloop (split_tac splits);
paulson@4325
   209
paulson@2074
   210
val IFOL_simps =
paulson@2074
   211
   [refl RS P_iff_T] @ conj_simps @ disj_simps @ not_simps @ 
paulson@2074
   212
    imp_simps @ iff_simps @ quant_simps;
paulson@2074
   213
paulson@2074
   214
val notFalseI = int_prove_fun "~False";
paulson@2074
   215
val triv_rls = [TrueI,refl,iff_refl,notFalseI];
paulson@2074
   216
oheimb@2633
   217
fun unsafe_solver prems = FIRST'[resolve_tac (triv_rls@prems),
oheimb@2633
   218
				 atac, etac FalseE];
oheimb@2633
   219
(*No premature instantiation of variables during simplification*)
oheimb@2633
   220
fun   safe_solver prems = FIRST'[match_tac (triv_rls@prems),
oheimb@2633
   221
				 eq_assume_tac, ematch_tac [FalseE]];
oheimb@2633
   222
paulson@3910
   223
(*No simprules, but basic infastructure for simplification*)
oheimb@2633
   224
val FOL_basic_ss = empty_ss setsubgoaler asm_simp_tac
oheimb@2633
   225
			    setSSolver   safe_solver
oheimb@2633
   226
			    setSolver  unsafe_solver
oheimb@2633
   227
			    setmksimps (map mk_meta_eq o atomize o gen_all);
oheimb@2633
   228
paulson@3910
   229
(*intuitionistic simprules only*)
oheimb@2633
   230
val IFOL_ss = FOL_basic_ss addsimps IFOL_simps
oheimb@2633
   231
			   addcongs [imp_cong];
paulson@2074
   232
paulson@2074
   233
val cla_simps = 
paulson@3910
   234
    [de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2,
paulson@3910
   235
     not_all, not_ex, cases_simp] @
paulson@2074
   236
    map prove_fun
paulson@2074
   237
     ["~(P&Q)  <-> ~P | ~Q",
paulson@2074
   238
      "P | ~P",             "~P | P",
paulson@2074
   239
      "~ ~ P <-> P",        "(~P --> P) <-> P",
paulson@2074
   240
      "(~P <-> ~Q) <-> (P<->Q)"];
paulson@2074
   241
paulson@3910
   242
(*classical simprules too*)
paulson@2074
   243
val FOL_ss = IFOL_ss addsimps (cla_simps @ ex_simps @ all_simps);
paulson@2074
   244
wenzelm@4094
   245
simpset_ref() := FOL_ss;
oheimb@2633
   246
oheimb@2633
   247
oheimb@2633
   248
oheimb@2633
   249
(*** Integration of simplifier with classical reasoner ***)
oheimb@2633
   250
oheimb@2633
   251
(* rot_eq_tac rotates the first equality premise of subgoal i to the front,
oheimb@2633
   252
   fails if there is no equaliy or if an equality is already at the front *)
paulson@3537
   253
local
oheimb@2633
   254
  fun is_eq (Const ("Trueprop", _) $ (Const("op ="  ,_) $ _ $ _)) = true
paulson@3537
   255
    | is_eq (Const ("Trueprop", _) $ (Const("op <->",_) $ _ $ _)) = true
paulson@3537
   256
    | is_eq _ = false;
oheimb@4188
   257
  val find_eq = find_index is_eq;
paulson@3537
   258
in
paulson@3537
   259
val rot_eq_tac = 
oheimb@4188
   260
     SUBGOAL (fn (Bi,i) => let val n = find_eq (Logic.strip_assums_hyp Bi) in
oheimb@4188
   261
		if n>0 then rotate_tac n i else no_tac end)
paulson@3537
   262
end;
oheimb@2633
   263
oheimb@2633
   264
oheimb@2633
   265
fun safe_asm_more_full_simp_tac ss = TRY o rot_eq_tac THEN' 
oheimb@2633
   266
				     safe_asm_full_simp_tac ss;
oheimb@2633
   267
(*an unsatisfactory fix for the incomplete asm_full_simp_tac!
oheimb@2633
   268
  better: asm_really_full_simp_tac, a yet to be implemented version of
oheimb@2633
   269
			asm_full_simp_tac that applies all equalities in the
oheimb@2633
   270
			premises to all the premises *)
oheimb@2633
   271
oheimb@2633
   272
(*Add a simpset to a classical set!*)
oheimb@3206
   273
infix 4 addSss addss;
oheimb@3206
   274
fun cs addSss ss = cs addSaltern (CHANGED o (safe_asm_more_full_simp_tac ss));
oheimb@3206
   275
fun cs addss  ss = cs addbefore                        asm_full_simp_tac ss;
oheimb@2633
   276
wenzelm@4094
   277
fun Addss ss = (claset_ref() := claset() addss ss);
oheimb@2633
   278
oheimb@2633
   279
(*Designed to be idempotent, except if best_tac instantiates variables
oheimb@2633
   280
  in some of the subgoals*)
oheimb@2633
   281
oheimb@2633
   282
type clasimpset = (claset * simpset);
oheimb@2633
   283
oheimb@2633
   284
val FOL_css = (FOL_cs, FOL_ss);
oheimb@2633
   285
oheimb@2633
   286
fun pair_upd1 f ((a,b),x) = (f(a,x), b);
oheimb@2633
   287
fun pair_upd2 f ((a,b),x) = (a, f(b,x));
oheimb@2633
   288
oheimb@2633
   289
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2
oheimb@2633
   290
	addsimps2 delsimps2 addcongs2 delcongs2;
paulson@2727
   291
fun op addSIs2   arg = pair_upd1 (op addSIs) arg;
paulson@2727
   292
fun op addSEs2   arg = pair_upd1 (op addSEs) arg;
paulson@2727
   293
fun op addSDs2   arg = pair_upd1 (op addSDs) arg;
paulson@2727
   294
fun op addIs2    arg = pair_upd1 (op addIs ) arg;
paulson@2727
   295
fun op addEs2    arg = pair_upd1 (op addEs ) arg;
paulson@2727
   296
fun op addDs2    arg = pair_upd1 (op addDs ) arg;
paulson@2727
   297
fun op addsimps2 arg = pair_upd2 (op addsimps) arg;
paulson@2727
   298
fun op delsimps2 arg = pair_upd2 (op delsimps) arg;
paulson@2727
   299
fun op addcongs2 arg = pair_upd2 (op addcongs) arg;
paulson@2727
   300
fun op delcongs2 arg = pair_upd2 (op delcongs) arg;
oheimb@2633
   301
oheimb@3206
   302
fun auto_tac (cs,ss) = 
oheimb@3206
   303
    let val cs' = cs addss ss 
oheimb@3206
   304
    in  EVERY [TRY (safe_tac cs'),
oheimb@3206
   305
	       REPEAT (FIRSTGOAL (fast_tac cs')),
oheimb@3206
   306
               TRY (safe_tac (cs addSss ss)),
oheimb@3206
   307
	       prune_params_tac] 
oheimb@3206
   308
    end;
oheimb@2633
   309
wenzelm@4094
   310
fun Auto_tac () = auto_tac (claset(), simpset());
oheimb@2633
   311
oheimb@2633
   312
fun auto () = by (Auto_tac ());