src/HOL/simpdata.ML
author paulson
Fri Nov 28 11:00:42 1997 +0100 (1997-11-28)
changeset 4327 2335f6584a1b
parent 4321 2a2956ccb86c
child 4351 36b28f78ed1b
permissions -rw-r--r--
Added comments
clasohm@1465
     1
(*  Title:      HOL/simpdata.ML
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Tobias Nipkow
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
clasohm@923
     6
Instantiation of the generic simplifier
clasohm@923
     7
*)
clasohm@923
     8
paulson@1984
     9
section "Simplifier";
paulson@1984
    10
clasohm@923
    11
open Simplifier;
clasohm@923
    12
paulson@1984
    13
(*** Addition of rules to simpsets and clasets simultaneously ***)
paulson@1984
    14
paulson@1984
    15
(*Takes UNCONDITIONAL theorems of the form A<->B to 
paulson@2031
    16
        the Safe Intr     rule B==>A and 
paulson@2031
    17
        the Safe Destruct rule A==>B.
paulson@1984
    18
  Also ~A goes to the Safe Elim rule A ==> ?R
paulson@1984
    19
  Failing other cases, A is added as a Safe Intr rule*)
paulson@1984
    20
local
paulson@1984
    21
  val iff_const = HOLogic.eq_const HOLogic.boolT;
paulson@1984
    22
paulson@1984
    23
  fun addIff th = 
paulson@1984
    24
      (case HOLogic.dest_Trueprop (#prop(rep_thm th)) of
paulson@2718
    25
                (Const("Not",_) $ A) =>
paulson@2031
    26
                    AddSEs [zero_var_indexes (th RS notE)]
paulson@2031
    27
              | (con $ _ $ _) =>
paulson@2031
    28
                    if con=iff_const
paulson@2031
    29
                    then (AddSIs [zero_var_indexes (th RS iffD2)];  
paulson@2031
    30
                          AddSDs [zero_var_indexes (th RS iffD1)])
paulson@2031
    31
                    else  AddSIs [th]
paulson@2031
    32
              | _ => AddSIs [th];
paulson@1984
    33
       Addsimps [th])
paulson@1984
    34
      handle _ => error ("AddIffs: theorem must be unconditional\n" ^ 
paulson@2031
    35
                         string_of_thm th)
paulson@1984
    36
paulson@1984
    37
  fun delIff th = 
paulson@1984
    38
      (case HOLogic.dest_Trueprop (#prop(rep_thm th)) of
paulson@2718
    39
                (Const("Not",_) $ A) =>
paulson@2031
    40
                    Delrules [zero_var_indexes (th RS notE)]
paulson@2031
    41
              | (con $ _ $ _) =>
paulson@2031
    42
                    if con=iff_const
paulson@2031
    43
                    then Delrules [zero_var_indexes (th RS iffD2),
paulson@3518
    44
                                   make_elim (zero_var_indexes (th RS iffD1))]
paulson@2031
    45
                    else Delrules [th]
paulson@2031
    46
              | _ => Delrules [th];
paulson@1984
    47
       Delsimps [th])
paulson@1984
    48
      handle _ => warning("DelIffs: ignoring conditional theorem\n" ^ 
paulson@2031
    49
                          string_of_thm th)
paulson@1984
    50
in
paulson@1984
    51
val AddIffs = seq addIff
paulson@1984
    52
val DelIffs = seq delIff
paulson@1984
    53
end;
paulson@1984
    54
nipkow@4320
    55
(** instantiate generic simp procs for `quantifier elimination': **)
nipkow@4320
    56
structure Quantifier1 = Quantifier1Fun(
nipkow@4320
    57
struct
nipkow@4320
    58
  (*abstract syntax*)
nipkow@4320
    59
  fun dest_eq((c as Const("op =",_)) $ s $ t) = Some(c,s,t)
nipkow@4320
    60
    | dest_eq _ = None;
nipkow@4320
    61
  fun dest_conj((c as Const("op &",_)) $ s $ t) = Some(c,s,t)
nipkow@4320
    62
    | dest_conj _ = None;
nipkow@4320
    63
  val conj = HOLogic.conj
nipkow@4320
    64
  val imp  = HOLogic.imp
nipkow@4320
    65
  (*rules*)
nipkow@4320
    66
  val iff_reflection = eq_reflection
nipkow@4320
    67
  val iffI = iffI
nipkow@4320
    68
  val sym  = sym
nipkow@4320
    69
  val conjI= conjI
nipkow@4320
    70
  val conjE= conjE
nipkow@4320
    71
  val impI = impI
nipkow@4320
    72
  val impE = impE
nipkow@4320
    73
  val mp   = mp
nipkow@4320
    74
  val exI  = exI
nipkow@4320
    75
  val exE  = exE
nipkow@4320
    76
  val allI = allI
nipkow@4320
    77
  val allE = allE
nipkow@4320
    78
end);
nipkow@4320
    79
paulson@1984
    80
clasohm@923
    81
local
clasohm@923
    82
paulson@2935
    83
  fun prover s = prove_goal HOL.thy s (fn _ => [blast_tac HOL_cs 1]);
clasohm@923
    84
paulson@1922
    85
  val P_imp_P_iff_True = prover "P --> (P = True)" RS mp;
paulson@1922
    86
  val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection;
clasohm@923
    87
paulson@1922
    88
  val not_P_imp_P_iff_F = prover "~P --> (P = False)" RS mp;
paulson@1922
    89
  val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection;
clasohm@923
    90
paulson@1922
    91
  fun atomize pairs =
paulson@1922
    92
    let fun atoms th =
paulson@2031
    93
          (case concl_of th of
paulson@2031
    94
             Const("Trueprop",_) $ p =>
paulson@2031
    95
               (case head_of p of
paulson@2031
    96
                  Const(a,_) =>
paulson@2031
    97
                    (case assoc(pairs,a) of
paulson@2031
    98
                       Some(rls) => flat (map atoms ([th] RL rls))
paulson@2031
    99
                     | None => [th])
paulson@2031
   100
                | _ => [th])
paulson@2031
   101
           | _ => [th])
paulson@1922
   102
    in atoms end;
clasohm@923
   103
nipkow@2134
   104
  fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
nipkow@2134
   105
nipkow@2134
   106
in
nipkow@2134
   107
nipkow@3896
   108
  fun mk_meta_eq r = r RS eq_reflection;
nipkow@3896
   109
nipkow@3896
   110
  fun mk_meta_eq_simp r = case concl_of r of
paulson@2031
   111
          Const("==",_)$_$_ => r
nipkow@3896
   112
      |   _$(Const("op =",_)$lhs$rhs) =>
nipkow@4117
   113
             (case fst(Logic.rewrite_rule_ok (#sign(rep_thm r)) (prems_of r) lhs rhs) of
nipkow@3896
   114
                None => mk_meta_eq r
nipkow@3896
   115
              | Some _ => r RS P_imp_P_eq_True)
paulson@2718
   116
      |   _$(Const("Not",_)$_) => r RS not_P_imp_P_eq_False
paulson@1922
   117
      |   _ => r RS P_imp_P_eq_True;
paulson@1922
   118
  (* last 2 lines requires all formulae to be of the from Trueprop(.) *)
clasohm@923
   119
paulson@2082
   120
val simp_thms = map prover
paulson@2082
   121
 [ "(x=x) = True",
paulson@2082
   122
   "(~True) = False", "(~False) = True", "(~ ~ P) = P",
paulson@2082
   123
   "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
paulson@2082
   124
   "(True=P) = P", "(P=True) = P",
paulson@2082
   125
   "(True --> P) = P", "(False --> P) = True", 
paulson@2082
   126
   "(P --> True) = True", "(P --> P) = True",
paulson@2082
   127
   "(P --> False) = (~P)", "(P --> ~P) = (~P)",
paulson@2082
   128
   "(P & True) = P", "(True & P) = P", 
nipkow@2800
   129
   "(P & False) = False", "(False & P) = False",
nipkow@2800
   130
   "(P & P) = P", "(P & (P & Q)) = (P & Q)",
paulson@3913
   131
   "(P & ~P) = False",    "(~P & P) = False",
paulson@2082
   132
   "(P | True) = True", "(True | P) = True", 
nipkow@2800
   133
   "(P | False) = P", "(False | P) = P",
nipkow@2800
   134
   "(P | P) = P", "(P | (P | Q)) = (P | Q)",
paulson@3913
   135
   "(P | ~P) = True",    "(~P | P) = True",
paulson@2082
   136
   "((~P) = (~Q)) = (P=Q)",
wenzelm@3842
   137
   "(!x. P) = P", "(? x. P) = P", "? x. x=t", "? x. t=x", 
nipkow@3573
   138
   "(? x. x=t & P(x)) = P(t)",
nipkow@3568
   139
   "(! x. t=x --> P(x)) = P(t)" ];
clasohm@923
   140
lcp@988
   141
(*Add congruence rules for = (instead of ==) *)
oheimb@2636
   142
infix 4 addcongs delcongs;
wenzelm@3559
   143
fun ss addcongs congs = ss addeqcongs (map standard (congs RL [eq_reflection]));
wenzelm@3559
   144
fun ss delcongs congs = ss deleqcongs (map standard (congs RL [eq_reflection]));
clasohm@923
   145
wenzelm@4086
   146
fun Addcongs congs = (simpset_ref() := simpset() addcongs congs);
wenzelm@4086
   147
fun Delcongs congs = (simpset_ref() := simpset() delcongs congs);
clasohm@1264
   148
nipkow@3896
   149
fun mksimps pairs = map mk_meta_eq_simp o atomize pairs o gen_all;
clasohm@923
   150
paulson@1922
   151
val imp_cong = impI RSN
paulson@1922
   152
    (2, prove_goal HOL.thy "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
paulson@2935
   153
        (fn _=> [blast_tac HOL_cs 1]) RS mp RS mp);
paulson@1922
   154
paulson@1948
   155
(*Miniscoping: pushing in existential quantifiers*)
paulson@1948
   156
val ex_simps = map prover 
wenzelm@3842
   157
                ["(EX x. P x & Q)   = ((EX x. P x) & Q)",
wenzelm@3842
   158
                 "(EX x. P & Q x)   = (P & (EX x. Q x))",
wenzelm@3842
   159
                 "(EX x. P x | Q)   = ((EX x. P x) | Q)",
wenzelm@3842
   160
                 "(EX x. P | Q x)   = (P | (EX x. Q x))",
wenzelm@3842
   161
                 "(EX x. P x --> Q) = ((ALL x. P x) --> Q)",
wenzelm@3842
   162
                 "(EX x. P --> Q x) = (P --> (EX x. Q x))"];
paulson@1948
   163
paulson@1948
   164
(*Miniscoping: pushing in universal quantifiers*)
paulson@1948
   165
val all_simps = map prover
wenzelm@3842
   166
                ["(ALL x. P x & Q)   = ((ALL x. P x) & Q)",
wenzelm@3842
   167
                 "(ALL x. P & Q x)   = (P & (ALL x. Q x))",
wenzelm@3842
   168
                 "(ALL x. P x | Q)   = ((ALL x. P x) | Q)",
wenzelm@3842
   169
                 "(ALL x. P | Q x)   = (P | (ALL x. Q x))",
wenzelm@3842
   170
                 "(ALL x. P x --> Q) = ((EX x. P x) --> Q)",
wenzelm@3842
   171
                 "(ALL x. P --> Q x) = (P --> (ALL x. Q x))"];
paulson@1948
   172
clasohm@923
   173
paulson@2022
   174
(* elimination of existential quantifiers in assumptions *)
clasohm@923
   175
clasohm@923
   176
val ex_all_equiv =
clasohm@923
   177
  let val lemma1 = prove_goal HOL.thy
clasohm@923
   178
        "(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)"
clasohm@923
   179
        (fn prems => [resolve_tac prems 1, etac exI 1]);
clasohm@923
   180
      val lemma2 = prove_goalw HOL.thy [Ex_def]
clasohm@923
   181
        "(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)"
clasohm@923
   182
        (fn prems => [REPEAT(resolve_tac prems 1)])
clasohm@923
   183
  in equal_intr lemma1 lemma2 end;
clasohm@923
   184
clasohm@923
   185
end;
clasohm@923
   186
nipkow@3654
   187
(* Elimination of True from asumptions: *)
nipkow@3654
   188
nipkow@3654
   189
val True_implies_equals = prove_goal HOL.thy
nipkow@3654
   190
 "(True ==> PROP P) == PROP P"
nipkow@3654
   191
(fn _ => [rtac equal_intr_rule 1, atac 2,
nipkow@3654
   192
          METAHYPS (fn prems => resolve_tac prems 1) 1,
nipkow@3654
   193
          rtac TrueI 1]);
nipkow@3654
   194
paulson@2935
   195
fun prove nm thm  = qed_goal nm HOL.thy thm (fn _ => [blast_tac HOL_cs 1]);
clasohm@923
   196
clasohm@923
   197
prove "conj_commute" "(P&Q) = (Q&P)";
clasohm@923
   198
prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
clasohm@923
   199
val conj_comms = [conj_commute, conj_left_commute];
nipkow@2134
   200
prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
clasohm@923
   201
paulson@1922
   202
prove "disj_commute" "(P|Q) = (Q|P)";
paulson@1922
   203
prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
paulson@1922
   204
val disj_comms = [disj_commute, disj_left_commute];
nipkow@2134
   205
prove "disj_assoc" "((P|Q)|R) = (P|(Q|R))";
paulson@1922
   206
clasohm@923
   207
prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
clasohm@923
   208
prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
nipkow@1485
   209
paulson@1892
   210
prove "disj_conj_distribL" "(P|(Q&R)) = ((P|Q) & (P|R))";
paulson@1892
   211
prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
paulson@1892
   212
nipkow@2134
   213
prove "imp_conjR" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
nipkow@2134
   214
prove "imp_conjL" "((P&Q) -->R)  = (P --> (Q --> R))";
nipkow@2134
   215
prove "imp_disjL" "((P|Q) --> R) = ((P-->R)&(Q-->R))";
paulson@1892
   216
paulson@3448
   217
(*These two are specialized, but imp_disj_not1 is useful in Auth/Yahalom.ML*)
paulson@3448
   218
prove "imp_disj_not1" "((P --> Q | R)) = (~Q --> P --> R)";
paulson@3448
   219
prove "imp_disj_not2" "((P --> Q | R)) = (~R --> P --> Q)";
paulson@3448
   220
paulson@3904
   221
prove "imp_disj1" "((P-->Q)|R) = (P--> Q|R)";
paulson@3904
   222
prove "imp_disj2" "(Q|(P-->R)) = (P--> Q|R)";
paulson@3904
   223
nipkow@1485
   224
prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
nipkow@1485
   225
prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
paulson@3446
   226
prove "not_imp" "(~(P --> Q)) = (P & ~Q)";
paulson@1922
   227
prove "not_iff" "(P~=Q) = (P = (~Q))";
nipkow@1485
   228
nipkow@2134
   229
(*Avoids duplication of subgoals after expand_if, when the true and false 
nipkow@2134
   230
  cases boil down to the same thing.*) 
nipkow@2134
   231
prove "cases_simp" "((P --> Q) & (~P --> Q)) = Q";
nipkow@2134
   232
wenzelm@3842
   233
prove "not_all" "(~ (! x. P(x))) = (? x.~P(x))";
paulson@1922
   234
prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
wenzelm@3842
   235
prove "not_ex"  "(~ (? x. P(x))) = (! x.~P(x))";
paulson@1922
   236
prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
oheimb@1660
   237
nipkow@1655
   238
prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
nipkow@1655
   239
prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
nipkow@1655
   240
nipkow@2134
   241
(* '&' congruence rule: not included by default!
nipkow@2134
   242
   May slow rewrite proofs down by as much as 50% *)
nipkow@2134
   243
nipkow@2134
   244
let val th = prove_goal HOL.thy 
nipkow@2134
   245
                "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
paulson@2935
   246
                (fn _=> [blast_tac HOL_cs 1])
nipkow@2134
   247
in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   248
nipkow@2134
   249
let val th = prove_goal HOL.thy 
nipkow@2134
   250
                "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
paulson@2935
   251
                (fn _=> [blast_tac HOL_cs 1])
nipkow@2134
   252
in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   253
nipkow@2134
   254
(* '|' congruence rule: not included by default! *)
nipkow@2134
   255
nipkow@2134
   256
let val th = prove_goal HOL.thy 
nipkow@2134
   257
                "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
paulson@2935
   258
                (fn _=> [blast_tac HOL_cs 1])
nipkow@2134
   259
in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   260
nipkow@2134
   261
prove "eq_sym_conv" "(x=y) = (y=x)";
nipkow@2134
   262
nipkow@2134
   263
qed_goalw "o_apply" HOL.thy [o_def] "(f o g) x = f (g x)"
nipkow@2134
   264
 (fn _ => [rtac refl 1]);
nipkow@2134
   265
nipkow@2134
   266
qed_goal "meta_eq_to_obj_eq" HOL.thy "x==y ==> x=y"
nipkow@2134
   267
  (fn [prem] => [rewtac prem, rtac refl 1]);
nipkow@2134
   268
nipkow@2134
   269
qed_goalw "if_True" HOL.thy [if_def] "(if True then x else y) = x"
paulson@2935
   270
 (fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   271
nipkow@2134
   272
qed_goalw "if_False" HOL.thy [if_def] "(if False then x else y) = y"
paulson@2935
   273
 (fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   274
nipkow@2134
   275
qed_goal "if_P" HOL.thy "P ==> (if P then x else y) = x"
nipkow@2134
   276
 (fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]);
nipkow@2134
   277
(*
nipkow@2134
   278
qed_goal "if_not_P" HOL.thy "~P ==> (if P then x else y) = y"
nipkow@2134
   279
 (fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]);
nipkow@2134
   280
*)
nipkow@2134
   281
qed_goalw "if_not_P" HOL.thy [if_def] "!!P. ~P ==> (if P then x else y) = y"
paulson@2935
   282
 (fn _ => [blast_tac (HOL_cs addIs [select_equality]) 1]);
nipkow@2134
   283
nipkow@2134
   284
qed_goal "expand_if" HOL.thy
oheimb@4205
   285
    "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))" (K [
oheimb@4205
   286
	res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1,
nipkow@2134
   287
         stac if_P 2,
nipkow@2134
   288
         stac if_not_P 1,
oheimb@4205
   289
         ALLGOALS (blast_tac HOL_cs)]);
oheimb@4205
   290
oheimb@4205
   291
qed_goal "split_if_asm" HOL.thy
oheimb@4205
   292
    "P(if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))" (K [
oheimb@4205
   293
	stac expand_if 1,
oheimb@4205
   294
        blast_tac HOL_cs 1]);
nipkow@2134
   295
nipkow@2134
   296
qed_goal "if_bool_eq" HOL.thy
nipkow@2134
   297
                   "(if P then Q else R) = ((P-->Q) & (~P-->R))"
nipkow@2134
   298
                   (fn _ => [rtac expand_if 1]);
nipkow@2134
   299
nipkow@4320
   300
(** make simp procs for quantifier elimination **)
nipkow@4320
   301
local
nipkow@4320
   302
val ex_pattern =
nipkow@4320
   303
  read_cterm (sign_of HOL.thy) ("? x. P(x) & Q(x)",HOLogic.boolT)
paulson@3913
   304
nipkow@4320
   305
val all_pattern =
nipkow@4320
   306
  read_cterm (sign_of HOL.thy) ("! x. P(x) & P'(x) --> Q(x)",HOLogic.boolT)
nipkow@4320
   307
nipkow@4320
   308
in
nipkow@4320
   309
val defEX_regroup =
nipkow@4320
   310
  mk_simproc "defined EX" [ex_pattern] Quantifier1.rearrange_ex;
nipkow@4320
   311
val defALL_regroup =
nipkow@4320
   312
  mk_simproc "defined ALL" [all_pattern] Quantifier1.rearrange_all;
nipkow@4320
   313
end;
paulson@3913
   314
paulson@3913
   315
(** Case splitting **)
paulson@3913
   316
oheimb@2263
   317
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2)
oheimb@2263
   318
in
oheimb@2263
   319
fun split_tac splits = mktac (map mk_meta_eq splits)
oheimb@2263
   320
end;
oheimb@2263
   321
oheimb@2263
   322
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2)
oheimb@2263
   323
in
oheimb@2263
   324
fun split_inside_tac splits = mktac (map mk_meta_eq splits)
oheimb@2263
   325
end;
oheimb@2263
   326
oheimb@4205
   327
val split_asm_tac = mk_case_split_asm_tac split_tac 
oheimb@4205
   328
			(disjE,conjE,exE,contrapos,contrapos2,notnotD);
oheimb@4189
   329
nipkow@3919
   330
infix 4 addsplits;
nipkow@3919
   331
fun ss addsplits splits = ss addloop (split_tac splits);
nipkow@3919
   332
oheimb@2263
   333
oheimb@2251
   334
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x"
paulson@2935
   335
  (fn _ => [split_tac [expand_if] 1, blast_tac HOL_cs 1]);
oheimb@2251
   336
nipkow@2134
   337
(** 'if' congruence rules: neither included by default! *)
nipkow@2134
   338
nipkow@2134
   339
(*Simplifies x assuming c and y assuming ~c*)
nipkow@2134
   340
qed_goal "if_cong" HOL.thy
nipkow@2134
   341
  "[| b=c; c ==> x=u; ~c ==> y=v |] ==>\
nipkow@2134
   342
\  (if b then x else y) = (if c then u else v)"
nipkow@2134
   343
  (fn rew::prems =>
nipkow@2134
   344
   [stac rew 1, stac expand_if 1, stac expand_if 1,
paulson@2935
   345
    blast_tac (HOL_cs addDs prems) 1]);
nipkow@2134
   346
nipkow@2134
   347
(*Prevents simplification of x and y: much faster*)
nipkow@2134
   348
qed_goal "if_weak_cong" HOL.thy
nipkow@2134
   349
  "b=c ==> (if b then x else y) = (if c then x else y)"
nipkow@2134
   350
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
nipkow@2134
   351
nipkow@2134
   352
(*Prevents simplification of t: much faster*)
nipkow@2134
   353
qed_goal "let_weak_cong" HOL.thy
nipkow@2134
   354
  "a = b ==> (let x=a in t(x)) = (let x=b in t(x))"
nipkow@2134
   355
  (fn [prem] => [rtac (prem RS arg_cong) 1]);
nipkow@2134
   356
nipkow@2134
   357
(*In general it seems wrong to add distributive laws by default: they
nipkow@2134
   358
  might cause exponential blow-up.  But imp_disjL has been in for a while
nipkow@2134
   359
  and cannot be removed without affecting existing proofs.  Moreover, 
nipkow@2134
   360
  rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
nipkow@2134
   361
  grounds that it allows simplification of R in the two cases.*)
nipkow@2134
   362
nipkow@2134
   363
val mksimps_pairs =
nipkow@2134
   364
  [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
nipkow@2134
   365
   ("All", [spec]), ("True", []), ("False", []),
nipkow@2134
   366
   ("If", [if_bool_eq RS iffD1])];
nipkow@1758
   367
oheimb@2636
   368
fun unsafe_solver prems = FIRST'[resolve_tac (TrueI::refl::prems),
oheimb@2636
   369
				 atac, etac FalseE];
oheimb@2636
   370
(*No premature instantiation of variables during simplification*)
oheimb@2636
   371
fun   safe_solver prems = FIRST'[match_tac (TrueI::refl::prems),
oheimb@2636
   372
				 eq_assume_tac, ematch_tac [FalseE]];
oheimb@2443
   373
oheimb@2636
   374
val HOL_basic_ss = empty_ss setsubgoaler asm_simp_tac
oheimb@2636
   375
			    setSSolver   safe_solver
oheimb@2636
   376
			    setSolver  unsafe_solver
oheimb@2636
   377
			    setmksimps (mksimps mksimps_pairs);
oheimb@2443
   378
paulson@3446
   379
val HOL_ss = 
paulson@3446
   380
    HOL_basic_ss addsimps 
paulson@3446
   381
     ([triv_forall_equality, (* prunes params *)
nipkow@3654
   382
       True_implies_equals, (* prune asms `True' *)
paulson@3446
   383
       if_True, if_False, if_cancel,
paulson@3446
   384
       o_apply, imp_disjL, conj_assoc, disj_assoc,
paulson@3904
   385
       de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2, not_imp,
paulson@3446
   386
       not_all, not_ex, cases_simp]
paulson@3446
   387
     @ ex_simps @ all_simps @ simp_thms)
nipkow@4032
   388
     addsimprocs [defALL_regroup,defEX_regroup]
paulson@3446
   389
     addcongs [imp_cong];
paulson@2082
   390
nipkow@1655
   391
qed_goal "if_distrib" HOL.thy
nipkow@1655
   392
  "f(if c then x else y) = (if c then f x else f y)" 
nipkow@1655
   393
  (fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]);
nipkow@1655
   394
oheimb@2097
   395
qed_goalw "o_assoc" HOL.thy [o_def] "f o (g o h) = f o g o h"
oheimb@2098
   396
  (fn _ => [rtac ext 1, rtac refl 1]);
paulson@1984
   397
paulson@1984
   398
paulson@4327
   399
(*For expand_case_tac*)
paulson@2948
   400
val prems = goal HOL.thy "[| P ==> Q(True); ~P ==> Q(False) |] ==> Q(P)";
paulson@2948
   401
by (case_tac "P" 1);
paulson@2948
   402
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps prems)));
paulson@2948
   403
val expand_case = result();
paulson@2948
   404
paulson@4327
   405
(*Used in Auth proofs.  Typically P contains Vars that become instantiated
paulson@4327
   406
  during unification.*)
paulson@2948
   407
fun expand_case_tac P i =
paulson@2948
   408
    res_inst_tac [("P",P)] expand_case i THEN
paulson@2948
   409
    Simp_tac (i+1) THEN 
paulson@2948
   410
    Simp_tac i;
paulson@2948
   411
paulson@2948
   412
wenzelm@4119
   413
(* install implicit simpset *)
paulson@1984
   414
wenzelm@4086
   415
simpset_ref() := HOL_ss;
paulson@1984
   416
berghofe@3615
   417
oheimb@2636
   418
(*** Integration of simplifier with classical reasoner ***)
oheimb@2636
   419
oheimb@2636
   420
(* rot_eq_tac rotates the first equality premise of subgoal i to the front,
oheimb@2636
   421
   fails if there is no equaliy or if an equality is already at the front *)
paulson@3538
   422
local
paulson@3538
   423
  fun is_eq (Const ("Trueprop", _) $ (Const("op ="  ,_) $ _ $ _)) = true
paulson@3538
   424
    | is_eq _ = false;
oheimb@4188
   425
  val find_eq = find_index is_eq;
paulson@3538
   426
in
paulson@3538
   427
val rot_eq_tac = 
oheimb@4188
   428
     SUBGOAL (fn (Bi,i) => let val n = find_eq (Logic.strip_assums_hyp Bi) in
oheimb@4188
   429
		if n>0 then rotate_tac n i else no_tac end)
paulson@3538
   430
end;
oheimb@2636
   431
oheimb@2636
   432
(*an unsatisfactory fix for the incomplete asm_full_simp_tac!
oheimb@2636
   433
  better: asm_really_full_simp_tac, a yet to be implemented version of
oheimb@2636
   434
			asm_full_simp_tac that applies all equalities in the
oheimb@2636
   435
			premises to all the premises *)
oheimb@2636
   436
fun safe_asm_more_full_simp_tac ss = TRY o rot_eq_tac THEN' 
oheimb@2636
   437
				     safe_asm_full_simp_tac ss;
oheimb@2636
   438
oheimb@2636
   439
(*Add a simpset to a classical set!*)
oheimb@3206
   440
infix 4 addSss addss;
oheimb@3206
   441
fun cs addSss ss = cs addSaltern (CHANGED o (safe_asm_more_full_simp_tac ss));
oheimb@3206
   442
fun cs addss  ss = cs addbefore                        asm_full_simp_tac ss;
oheimb@2636
   443
wenzelm@4086
   444
fun Addss ss = (claset_ref() := claset() addss ss);
oheimb@2636
   445
oheimb@2636
   446
(*Designed to be idempotent, except if best_tac instantiates variables
oheimb@2636
   447
  in some of the subgoals*)
oheimb@2636
   448
oheimb@2636
   449
type clasimpset = (claset * simpset);
oheimb@2636
   450
oheimb@2636
   451
val HOL_css = (HOL_cs, HOL_ss);
oheimb@2636
   452
oheimb@2636
   453
fun pair_upd1 f ((a,b),x) = (f(a,x), b);
oheimb@2636
   454
fun pair_upd2 f ((a,b),x) = (a, f(b,x));
oheimb@2636
   455
oheimb@2636
   456
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2
oheimb@2636
   457
	addsimps2 delsimps2 addcongs2 delcongs2;
paulson@2748
   458
fun op addSIs2   arg = pair_upd1 (op addSIs) arg;
paulson@2748
   459
fun op addSEs2   arg = pair_upd1 (op addSEs) arg;
paulson@2748
   460
fun op addSDs2   arg = pair_upd1 (op addSDs) arg;
paulson@2748
   461
fun op addIs2    arg = pair_upd1 (op addIs ) arg;
paulson@2748
   462
fun op addEs2    arg = pair_upd1 (op addEs ) arg;
paulson@2748
   463
fun op addDs2    arg = pair_upd1 (op addDs ) arg;
paulson@2748
   464
fun op addsimps2 arg = pair_upd2 (op addsimps) arg;
paulson@2748
   465
fun op delsimps2 arg = pair_upd2 (op delsimps) arg;
paulson@2748
   466
fun op addcongs2 arg = pair_upd2 (op addcongs) arg;
paulson@2748
   467
fun op delcongs2 arg = pair_upd2 (op delcongs) arg;
oheimb@2636
   468
paulson@2805
   469
fun auto_tac (cs,ss) = 
paulson@2805
   470
    let val cs' = cs addss ss 
paulson@2805
   471
    in  EVERY [TRY (safe_tac cs'),
paulson@2805
   472
	       REPEAT (FIRSTGOAL (fast_tac cs')),
oheimb@3206
   473
               TRY (safe_tac (cs addSss ss)),
paulson@2805
   474
	       prune_params_tac] 
paulson@2805
   475
    end;
oheimb@2636
   476
wenzelm@4086
   477
fun Auto_tac () = auto_tac (claset(), simpset());
oheimb@2636
   478
oheimb@2636
   479
fun auto () = by (Auto_tac ());