src/HOL/simpdata.ML
author wenzelm
Sat Nov 03 18:42:38 2001 +0100 (2001-11-03)
changeset 12038 343a9888e875
parent 11684 abd396ca7ef9
child 12278 75103ba03035
permissions -rw-r--r--
proper use of bind_thm(s);
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
oheimb@5304
     6
Instantiation of the generic simplifier for HOL.
clasohm@923
     7
*)
clasohm@923
     8
paulson@1984
     9
section "Simplifier";
paulson@1984
    10
wenzelm@7357
    11
val [prem] = goal (the_context ()) "x==y ==> x=y";
paulson@7031
    12
by (rewtac prem);
paulson@7031
    13
by (rtac refl 1);
paulson@7031
    14
qed "meta_eq_to_obj_eq";
nipkow@4640
    15
oheimb@9023
    16
Goal "(%s. f s) = f";
oheimb@9023
    17
br refl 1;
oheimb@9023
    18
qed "eta_contract_eq";
oheimb@9023
    19
clasohm@923
    20
wenzelm@12038
    21
fun prover s = prove_goal (the_context ()) s (fn _ => [(Blast_tac 1)]);
nipkow@2134
    22
oheimb@5552
    23
(*Make meta-equalities.  The operator below is Trueprop*)
oheimb@5552
    24
nipkow@6128
    25
fun mk_meta_eq r = r RS eq_reflection;
wenzelm@9832
    26
fun safe_mk_meta_eq r = mk_meta_eq r handle Thm.THM _ => r;
nipkow@6128
    27
wenzelm@12038
    28
bind_thm ("Eq_TrueI", mk_meta_eq (prover  "P --> (P = True)"  RS mp));
wenzelm@12038
    29
bind_thm ("Eq_FalseI", mk_meta_eq(prover "~P --> (P = False)" RS mp));
oheimb@5304
    30
nipkow@6128
    31
fun mk_eq th = case concl_of th of
nipkow@6128
    32
        Const("==",_)$_$_       => th
nipkow@6128
    33
    |   _$(Const("op =",_)$_$_) => mk_meta_eq th
nipkow@6128
    34
    |   _$(Const("Not",_)$_)    => th RS Eq_FalseI
nipkow@6128
    35
    |   _                       => th RS Eq_TrueI;
nipkow@6128
    36
(* last 2 lines requires all formulae to be of the from Trueprop(.) *)
oheimb@5304
    37
berghofe@11624
    38
fun mk_eq_True r =
berghofe@11624
    39
  Some (r RS meta_eq_to_obj_eq RS Eq_TrueI) handle Thm.THM _ => None;
oheimb@5552
    40
wenzelm@9713
    41
(*Congruence rules for = (instead of ==)*)
nipkow@6128
    42
fun mk_meta_cong rl =
nipkow@6128
    43
  standard(mk_meta_eq(replicate (nprems_of rl) meta_eq_to_obj_eq MRS rl))
nipkow@6128
    44
  handle THM _ =>
nipkow@6128
    45
  error("Premises and conclusion of congruence rules must be =-equalities");
nipkow@3896
    46
wenzelm@12038
    47
bind_thm ("not_not", prover "(~ ~ P) = P");
clasohm@923
    48
wenzelm@12038
    49
bind_thms ("simp_thms", [not_not] @ map prover
wenzelm@12038
    50
 ["(x=x) = True",
wenzelm@12038
    51
  "(~True) = False", "(~False) = True",
wenzelm@12038
    52
  "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
wenzelm@12038
    53
  "(True=P) = P", "(P=True) = P", "(False=P) = (~P)", "(P=False) = (~P)",
wenzelm@12038
    54
  "(True --> P) = P", "(False --> P) = True",
wenzelm@12038
    55
  "(P --> True) = True", "(P --> P) = True",
wenzelm@12038
    56
  "(P --> False) = (~P)", "(P --> ~P) = (~P)",
wenzelm@12038
    57
  "(P & True) = P", "(True & P) = P",
wenzelm@12038
    58
  "(P & False) = False", "(False & P) = False",
wenzelm@12038
    59
  "(P & P) = P", "(P & (P & Q)) = (P & Q)",
wenzelm@12038
    60
  "(P & ~P) = False",    "(~P & P) = False",
wenzelm@12038
    61
  "(P | True) = True", "(True | P) = True",
wenzelm@12038
    62
  "(P | False) = P", "(False | P) = P",
wenzelm@12038
    63
  "(P | P) = P", "(P | (P | Q)) = (P | Q)",
wenzelm@12038
    64
  "(P | ~P) = True",    "(~P | P) = True",
wenzelm@12038
    65
  "((~P) = (~Q)) = (P=Q)",
wenzelm@12038
    66
  "(!x. P) = P", "(? x. P) = P", "? x. x=t", "? x. t=x",
nipkow@11232
    67
(* needed for the one-point-rule quantifier simplification procs*)
nipkow@11232
    68
(*essential for termination!!*)
wenzelm@12038
    69
  "(? x. x=t & P(x)) = P(t)",
wenzelm@12038
    70
  "(? x. t=x & P(x)) = P(t)",
wenzelm@12038
    71
  "(! x. x=t --> P(x)) = P(t)",
wenzelm@12038
    72
  "(! x. t=x --> P(x)) = P(t)"]);
clasohm@923
    73
wenzelm@12038
    74
bind_thm ("imp_cong", standard (impI RSN
wenzelm@7357
    75
    (2, prove_goal (the_context ()) "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
wenzelm@12038
    76
        (fn _=> [(Blast_tac 1)]) RS mp RS mp)));
paulson@1922
    77
paulson@1948
    78
(*Miniscoping: pushing in existential quantifiers*)
wenzelm@12038
    79
bind_thms ("ex_simps", map prover
wenzelm@12038
    80
 ["(EX x. P x & Q)   = ((EX x. P x) & Q)",
wenzelm@12038
    81
  "(EX x. P & Q x)   = (P & (EX x. Q x))",
wenzelm@12038
    82
  "(EX x. P x | Q)   = ((EX x. P x) | Q)",
wenzelm@12038
    83
  "(EX x. P | Q x)   = (P | (EX x. Q x))",
wenzelm@12038
    84
  "(EX x. P x --> Q) = ((ALL x. P x) --> Q)",
wenzelm@12038
    85
  "(EX x. P --> Q x) = (P --> (EX x. Q x))"]);
paulson@1948
    86
paulson@1948
    87
(*Miniscoping: pushing in universal quantifiers*)
wenzelm@12038
    88
bind_thms ("all_simps", map prover
wenzelm@12038
    89
 ["(ALL x. P x & Q)   = ((ALL x. P x) & Q)",
wenzelm@12038
    90
  "(ALL x. P & Q x)   = (P & (ALL x. Q x))",
wenzelm@12038
    91
  "(ALL x. P x | Q)   = ((ALL x. P x) | Q)",
wenzelm@12038
    92
  "(ALL x. P | Q x)   = (P | (ALL x. Q x))",
wenzelm@12038
    93
  "(ALL x. P x --> Q) = ((EX x. P x) --> Q)",
wenzelm@12038
    94
  "(ALL x. P --> Q x) = (P --> (ALL x. Q x))"]);
paulson@1948
    95
clasohm@923
    96
nipkow@3654
    97
(* Elimination of True from asumptions: *)
nipkow@3654
    98
berghofe@11534
    99
local fun rd s = read_cterm (sign_of (the_context())) (s, propT);
berghofe@11534
   100
in val True_implies_equals = standard' (equal_intr
berghofe@11534
   101
  (implies_intr_hyps (implies_elim (assume (rd "True ==> PROP P")) TrueI))
berghofe@11534
   102
  (implies_intr_hyps (implies_intr (rd "True") (assume (rd "PROP P")))));
berghofe@11534
   103
end;
nipkow@3654
   104
wenzelm@7357
   105
fun prove nm thm  = qed_goal nm (the_context ()) thm (fn _ => [(Blast_tac 1)]);
clasohm@923
   106
paulson@9511
   107
prove "eq_commute" "(a=b) = (b=a)";
paulson@7623
   108
prove "eq_left_commute" "(P=(Q=R)) = (Q=(P=R))";
paulson@7623
   109
prove "eq_assoc" "((P=Q)=R) = (P=(Q=R))";
wenzelm@12038
   110
bind_thms ("eq_ac", [eq_commute, eq_left_commute, eq_assoc]);
paulson@7623
   111
paulson@9511
   112
prove "neq_commute" "(a~=b) = (b~=a)";
paulson@9511
   113
clasohm@923
   114
prove "conj_commute" "(P&Q) = (Q&P)";
clasohm@923
   115
prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
wenzelm@12038
   116
bind_thms ("conj_comms", [conj_commute, conj_left_commute]);
nipkow@2134
   117
prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
clasohm@923
   118
paulson@1922
   119
prove "disj_commute" "(P|Q) = (Q|P)";
paulson@1922
   120
prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
wenzelm@12038
   121
bind_thms ("disj_comms", [disj_commute, disj_left_commute]);
nipkow@2134
   122
prove "disj_assoc" "((P|Q)|R) = (P|(Q|R))";
paulson@1922
   123
clasohm@923
   124
prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
clasohm@923
   125
prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
nipkow@1485
   126
paulson@1892
   127
prove "disj_conj_distribL" "(P|(Q&R)) = ((P|Q) & (P|R))";
paulson@1892
   128
prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
paulson@1892
   129
nipkow@2134
   130
prove "imp_conjR" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
nipkow@2134
   131
prove "imp_conjL" "((P&Q) -->R)  = (P --> (Q --> R))";
nipkow@2134
   132
prove "imp_disjL" "((P|Q) --> R) = ((P-->R)&(Q-->R))";
paulson@1892
   133
paulson@3448
   134
(*These two are specialized, but imp_disj_not1 is useful in Auth/Yahalom.ML*)
paulson@8114
   135
prove "imp_disj_not1" "(P --> Q | R) = (~Q --> P --> R)";
paulson@8114
   136
prove "imp_disj_not2" "(P --> Q | R) = (~R --> P --> Q)";
paulson@3448
   137
paulson@3904
   138
prove "imp_disj1" "((P-->Q)|R) = (P--> Q|R)";
paulson@3904
   139
prove "imp_disj2" "(Q|(P-->R)) = (P--> Q|R)";
paulson@3904
   140
nipkow@1485
   141
prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
nipkow@1485
   142
prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
paulson@3446
   143
prove "not_imp" "(~(P --> Q)) = (P & ~Q)";
paulson@1922
   144
prove "not_iff" "(P~=Q) = (P = (~Q))";
oheimb@4743
   145
prove "disj_not1" "(~P | Q) = (P --> Q)";
oheimb@4743
   146
prove "disj_not2" "(P | ~Q) = (Q --> P)"; (* changes orientation :-( *)
nipkow@5975
   147
prove "imp_conv_disj" "(P --> Q) = ((~P) | Q)";
nipkow@5975
   148
nipkow@5975
   149
prove "iff_conv_conj_imp" "(P = Q) = ((P --> Q) & (Q --> P))";
nipkow@5975
   150
nipkow@1485
   151
wenzelm@9713
   152
(*Avoids duplication of subgoals after split_if, when the true and false
wenzelm@9713
   153
  cases boil down to the same thing.*)
nipkow@2134
   154
prove "cases_simp" "((P --> Q) & (~P --> Q)) = Q";
nipkow@2134
   155
wenzelm@3842
   156
prove "not_all" "(~ (! x. P(x))) = (? x.~P(x))";
paulson@1922
   157
prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
wenzelm@3842
   158
prove "not_ex"  "(~ (? x. P(x))) = (! x.~P(x))";
paulson@1922
   159
prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
oheimb@1660
   160
nipkow@1655
   161
prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
nipkow@1655
   162
prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
nipkow@1655
   163
nipkow@2134
   164
(* '&' congruence rule: not included by default!
nipkow@2134
   165
   May slow rewrite proofs down by as much as 50% *)
nipkow@2134
   166
wenzelm@9713
   167
let val th = prove_goal (the_context ())
nipkow@2134
   168
                "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
paulson@7031
   169
                (fn _=> [(Blast_tac 1)])
nipkow@2134
   170
in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   171
wenzelm@9713
   172
let val th = prove_goal (the_context ())
nipkow@2134
   173
                "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
paulson@7031
   174
                (fn _=> [(Blast_tac 1)])
nipkow@2134
   175
in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   176
nipkow@2134
   177
(* '|' congruence rule: not included by default! *)
nipkow@2134
   178
wenzelm@9713
   179
let val th = prove_goal (the_context ())
nipkow@2134
   180
                "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
paulson@7031
   181
                (fn _=> [(Blast_tac 1)])
nipkow@2134
   182
in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
nipkow@2134
   183
nipkow@2134
   184
prove "eq_sym_conv" "(x=y) = (y=x)";
nipkow@2134
   185
paulson@5278
   186
paulson@5278
   187
(** if-then-else rules **)
paulson@5278
   188
paulson@7031
   189
Goalw [if_def] "(if True then x else y) = x";
paulson@7031
   190
by (Blast_tac 1);
paulson@7031
   191
qed "if_True";
nipkow@2134
   192
paulson@7031
   193
Goalw [if_def] "(if False then x else y) = y";
paulson@7031
   194
by (Blast_tac 1);
paulson@7031
   195
qed "if_False";
nipkow@2134
   196
paulson@7127
   197
Goalw [if_def] "P ==> (if P then x else y) = x";
paulson@7031
   198
by (Blast_tac 1);
paulson@7031
   199
qed "if_P";
oheimb@5304
   200
paulson@7127
   201
Goalw [if_def] "~P ==> (if P then x else y) = y";
paulson@7031
   202
by (Blast_tac 1);
paulson@7031
   203
qed "if_not_P";
nipkow@2134
   204
paulson@7031
   205
Goal "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))";
paulson@7031
   206
by (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1);
paulson@7031
   207
by (stac if_P 2);
paulson@7031
   208
by (stac if_not_P 1);
paulson@7031
   209
by (ALLGOALS (Blast_tac));
paulson@7031
   210
qed "split_if";
paulson@7031
   211
paulson@7031
   212
Goal "P(if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))";
paulson@7031
   213
by (stac split_if 1);
paulson@7031
   214
by (Blast_tac 1);
paulson@7031
   215
qed "split_if_asm";
nipkow@2134
   216
wenzelm@9384
   217
bind_thms ("if_splits", [split_if, split_if_asm]);
wenzelm@9384
   218
oheimb@11003
   219
bind_thm ("if_def2", read_instantiate [("P","\\<lambda>x. x")] split_if);
oheimb@11003
   220
paulson@7031
   221
Goal "(if c then x else x) = x";
paulson@7031
   222
by (stac split_if 1);
paulson@7031
   223
by (Blast_tac 1);
paulson@7031
   224
qed "if_cancel";
oheimb@5304
   225
paulson@7031
   226
Goal "(if x = y then y else x) = x";
paulson@7031
   227
by (stac split_if 1);
paulson@7031
   228
by (Blast_tac 1);
paulson@7031
   229
qed "if_eq_cancel";
oheimb@5304
   230
paulson@4769
   231
(*This form is useful for expanding IFs on the RIGHT of the ==> symbol*)
paulson@7127
   232
Goal "(if P then Q else R) = ((P-->Q) & (~P-->R))";
paulson@7031
   233
by (rtac split_if 1);
paulson@7031
   234
qed "if_bool_eq_conj";
paulson@4769
   235
paulson@4769
   236
(*And this form is useful for expanding IFs on the LEFT*)
paulson@7031
   237
Goal "(if P then Q else R) = ((P&Q) | (~P&R))";
paulson@7031
   238
by (stac split_if 1);
paulson@7031
   239
by (Blast_tac 1);
paulson@7031
   240
qed "if_bool_eq_disj";
nipkow@2134
   241
nipkow@11232
   242
local
nipkow@11232
   243
val uncurry = prove_goal (the_context()) "P --> Q --> R ==> P & Q --> R"
nipkow@11232
   244
              (fn prems => [cut_facts_tac prems 1, Blast_tac 1]);
nipkow@11232
   245
nipkow@11232
   246
val iff_allI = allI RS
nipkow@11232
   247
    prove_goal (the_context()) "!x. P x = Q x ==> (!x. P x) = (!x. Q x)"
nipkow@11232
   248
               (fn prems => [cut_facts_tac prems 1, Blast_tac 1])
nipkow@11232
   249
in
paulson@4351
   250
paulson@4351
   251
(*** make simplification procedures for quantifier elimination ***)
paulson@4351
   252
wenzelm@9851
   253
structure Quantifier1 = Quantifier1Fun
wenzelm@9851
   254
(struct
paulson@4351
   255
  (*abstract syntax*)
paulson@4351
   256
  fun dest_eq((c as Const("op =",_)) $ s $ t) = Some(c,s,t)
paulson@4351
   257
    | dest_eq _ = None;
paulson@4351
   258
  fun dest_conj((c as Const("op &",_)) $ s $ t) = Some(c,s,t)
paulson@4351
   259
    | dest_conj _ = None;
nipkow@11232
   260
  fun dest_imp((c as Const("op -->",_)) $ s $ t) = Some(c,s,t)
nipkow@11232
   261
    | dest_imp _ = None;
paulson@4351
   262
  val conj = HOLogic.conj
paulson@4351
   263
  val imp  = HOLogic.imp
paulson@4351
   264
  (*rules*)
paulson@4351
   265
  val iff_reflection = eq_reflection
paulson@4351
   266
  val iffI = iffI
paulson@4351
   267
  val conjI= conjI
paulson@4351
   268
  val conjE= conjE
paulson@4351
   269
  val impI = impI
paulson@4351
   270
  val mp   = mp
nipkow@11232
   271
  val uncurry = uncurry
paulson@4351
   272
  val exI  = exI
paulson@4351
   273
  val exE  = exE
nipkow@11232
   274
  val iff_allI = iff_allI
paulson@4351
   275
end);
paulson@4351
   276
nipkow@11232
   277
end;
nipkow@11232
   278
nipkow@4320
   279
local
nipkow@11220
   280
val ex_pattern = Thm.read_cterm (Theory.sign_of (the_context ()))
nipkow@11220
   281
    ("EX x. P(x) & Q(x)",HOLogic.boolT)
nipkow@11220
   282
val all_pattern = Thm.read_cterm (Theory.sign_of (the_context ()))
nipkow@11232
   283
    ("ALL x. P(x) --> Q(x)",HOLogic.boolT)
nipkow@4320
   284
in
nipkow@11220
   285
val defEX_regroup = mk_simproc "defined EX" [ex_pattern]
nipkow@11220
   286
      Quantifier1.rearrange_ex
nipkow@11220
   287
val defALL_regroup = mk_simproc "defined ALL" [all_pattern]
nipkow@11220
   288
      Quantifier1.rearrange_all
nipkow@4320
   289
end;
paulson@3913
   290
paulson@4351
   291
paulson@4351
   292
(*** Case splitting ***)
paulson@3913
   293
oheimb@5304
   294
structure SplitterData =
oheimb@5304
   295
  struct
oheimb@5304
   296
  structure Simplifier = Simplifier
oheimb@5552
   297
  val mk_eq          = mk_eq
oheimb@5304
   298
  val meta_eq_to_iff = meta_eq_to_obj_eq
oheimb@5304
   299
  val iffD           = iffD2
oheimb@5304
   300
  val disjE          = disjE
oheimb@5304
   301
  val conjE          = conjE
oheimb@5304
   302
  val exE            = exE
paulson@10231
   303
  val contrapos      = contrapos_nn
paulson@10231
   304
  val contrapos2     = contrapos_pp
oheimb@5304
   305
  val notnotD        = notnotD
oheimb@5304
   306
  end;
nipkow@4681
   307
oheimb@5304
   308
structure Splitter = SplitterFun(SplitterData);
oheimb@2263
   309
oheimb@5304
   310
val split_tac        = Splitter.split_tac;
oheimb@5304
   311
val split_inside_tac = Splitter.split_inside_tac;
oheimb@5304
   312
val split_asm_tac    = Splitter.split_asm_tac;
oheimb@5307
   313
val op addsplits     = Splitter.addsplits;
oheimb@5307
   314
val op delsplits     = Splitter.delsplits;
oheimb@5304
   315
val Addsplits        = Splitter.Addsplits;
oheimb@5304
   316
val Delsplits        = Splitter.Delsplits;
oheimb@4718
   317
nipkow@2134
   318
(*In general it seems wrong to add distributive laws by default: they
nipkow@2134
   319
  might cause exponential blow-up.  But imp_disjL has been in for a while
wenzelm@9713
   320
  and cannot be removed without affecting existing proofs.  Moreover,
nipkow@2134
   321
  rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
nipkow@2134
   322
  grounds that it allows simplification of R in the two cases.*)
nipkow@2134
   323
nipkow@2134
   324
val mksimps_pairs =
nipkow@2134
   325
  [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
nipkow@2134
   326
   ("All", [spec]), ("True", []), ("False", []),
paulson@4769
   327
   ("If", [if_bool_eq_conj RS iffD1])];
nipkow@1758
   328
oheimb@5552
   329
(* ###FIXME: move to Provers/simplifier.ML
oheimb@5304
   330
val mk_atomize:      (string * thm list) list -> thm -> thm list
oheimb@5304
   331
*)
oheimb@5552
   332
(* ###FIXME: move to Provers/simplifier.ML *)
oheimb@5304
   333
fun mk_atomize pairs =
oheimb@5304
   334
  let fun atoms th =
oheimb@5304
   335
        (case concl_of th of
oheimb@5304
   336
           Const("Trueprop",_) $ p =>
oheimb@5304
   337
             (case head_of p of
oheimb@5304
   338
                Const(a,_) =>
oheimb@5304
   339
                  (case assoc(pairs,a) of
oheimb@5304
   340
                     Some(rls) => flat (map atoms ([th] RL rls))
oheimb@5304
   341
                   | None => [th])
oheimb@5304
   342
              | _ => [th])
oheimb@5304
   343
         | _ => [th])
oheimb@5304
   344
  in atoms end;
oheimb@5304
   345
berghofe@11624
   346
fun mksimps pairs =
berghofe@11624
   347
  (mapfilter (try mk_eq) o mk_atomize pairs o forall_elim_vars_safe);
oheimb@5304
   348
nipkow@7570
   349
fun unsafe_solver_tac prems =
nipkow@7570
   350
  FIRST'[resolve_tac(reflexive_thm::TrueI::refl::prems), atac, etac FalseE];
nipkow@7570
   351
val unsafe_solver = mk_solver "HOL unsafe" unsafe_solver_tac;
nipkow@7570
   352
oheimb@2636
   353
(*No premature instantiation of variables during simplification*)
nipkow@7570
   354
fun safe_solver_tac prems =
nipkow@7570
   355
  FIRST'[match_tac(reflexive_thm::TrueI::refl::prems),
nipkow@7570
   356
         eq_assume_tac, ematch_tac [FalseE]];
nipkow@7570
   357
val safe_solver = mk_solver "HOL safe" safe_solver_tac;
oheimb@2443
   358
wenzelm@9713
   359
val HOL_basic_ss =
wenzelm@9713
   360
  empty_ss setsubgoaler asm_simp_tac
wenzelm@9713
   361
    setSSolver safe_solver
wenzelm@9713
   362
    setSolver unsafe_solver
wenzelm@9713
   363
    setmksimps (mksimps mksimps_pairs)
wenzelm@9713
   364
    setmkeqTrue mk_eq_True
wenzelm@9713
   365
    setmkcong mk_meta_cong;
oheimb@2443
   366
wenzelm@9713
   367
val HOL_ss =
wenzelm@9713
   368
    HOL_basic_ss addsimps
paulson@3446
   369
     ([triv_forall_equality, (* prunes params *)
nipkow@3654
   370
       True_implies_equals, (* prune asms `True' *)
oheimb@9023
   371
       eta_contract_eq, (* prunes eta-expansions *)
oheimb@4718
   372
       if_True, if_False, if_cancel, if_eq_cancel,
oheimb@5304
   373
       imp_disjL, conj_assoc, disj_assoc,
paulson@3904
   374
       de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2, not_imp,
paulson@11451
   375
       disj_not1, not_all, not_ex, cases_simp,
wenzelm@11434
   376
       thm "the_eq_trivial", the_sym_eq_trivial, thm "plus_ac0.zero", thm "plus_ac0_zero_right"]
paulson@3446
   377
     @ ex_simps @ all_simps @ simp_thms)
nipkow@4032
   378
     addsimprocs [defALL_regroup,defEX_regroup]
wenzelm@4744
   379
     addcongs [imp_cong]
nipkow@4830
   380
     addsplits [split_if];
paulson@2082
   381
wenzelm@11034
   382
fun hol_simplify rews = Simplifier.full_simplify (HOL_basic_ss addsimps rews);
wenzelm@11034
   383
wenzelm@11034
   384
paulson@6293
   385
(*Simplifies x assuming c and y assuming ~c*)
paulson@6293
   386
val prems = Goalw [if_def]
paulson@6293
   387
  "[| b=c; c ==> x=u; ~c ==> y=v |] ==> \
paulson@6293
   388
\  (if b then x else y) = (if c then u else v)";
paulson@6293
   389
by (asm_simp_tac (HOL_ss addsimps prems) 1);
paulson@6293
   390
qed "if_cong";
paulson@6293
   391
paulson@7127
   392
(*Prevents simplification of x and y: faster and allows the execution
paulson@7127
   393
  of functional programs. NOW THE DEFAULT.*)
paulson@7031
   394
Goal "b=c ==> (if b then x else y) = (if c then x else y)";
paulson@7031
   395
by (etac arg_cong 1);
paulson@7031
   396
qed "if_weak_cong";
paulson@6293
   397
paulson@6293
   398
(*Prevents simplification of t: much faster*)
paulson@7031
   399
Goal "a = b ==> (let x=a in t(x)) = (let x=b in t(x))";
paulson@7031
   400
by (etac arg_cong 1);
paulson@7031
   401
qed "let_weak_cong";
paulson@6293
   402
paulson@7031
   403
Goal "f(if c then x else y) = (if c then f x else f y)";
paulson@7031
   404
by (simp_tac (HOL_ss setloop (split_tac [split_if])) 1);
paulson@7031
   405
qed "if_distrib";
nipkow@1655
   406
paulson@4327
   407
(*For expand_case_tac*)
paulson@7584
   408
val prems = Goal "[| P ==> Q(True); ~P ==> Q(False) |] ==> Q(P)";
paulson@2948
   409
by (case_tac "P" 1);
paulson@2948
   410
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps prems)));
paulson@7584
   411
qed "expand_case";
paulson@2948
   412
paulson@4327
   413
(*Used in Auth proofs.  Typically P contains Vars that become instantiated
paulson@4327
   414
  during unification.*)
paulson@2948
   415
fun expand_case_tac P i =
paulson@2948
   416
    res_inst_tac [("P",P)] expand_case i THEN
wenzelm@9713
   417
    Simp_tac (i+1) THEN
paulson@2948
   418
    Simp_tac i;
paulson@2948
   419
paulson@7584
   420
(*This lemma restricts the effect of the rewrite rule u=v to the left-hand
paulson@7584
   421
  side of an equality.  Used in {Integ,Real}/simproc.ML*)
paulson@7584
   422
Goal "x=y ==> (x=z) = (y=z)";
paulson@7584
   423
by (asm_simp_tac HOL_ss 1);
paulson@7584
   424
qed "restrict_to_left";
paulson@2948
   425
wenzelm@7357
   426
(* default simpset *)
wenzelm@9713
   427
val simpsetup =
wenzelm@9713
   428
  [fn thy => (simpset_ref_of thy := HOL_ss addcongs [if_weak_cong]; thy)];
berghofe@3615
   429
oheimb@4652
   430
wenzelm@5219
   431
(*** integration of simplifier with classical reasoner ***)
oheimb@2636
   432
wenzelm@5219
   433
structure Clasimp = ClasimpFun
wenzelm@8473
   434
 (structure Simplifier = Simplifier and Splitter = Splitter
wenzelm@9851
   435
  and Classical  = Classical and Blast = Blast
oheimb@11344
   436
  val iffD1 = iffD1 val iffD2 = iffD2 val notE = notE
wenzelm@9851
   437
  val cla_make_elim = cla_make_elim);
oheimb@4652
   438
open Clasimp;
oheimb@2636
   439
oheimb@2636
   440
val HOL_css = (HOL_cs, HOL_ss);
nipkow@5975
   441
nipkow@5975
   442
wenzelm@8641
   443
nipkow@5975
   444
(*** A general refutation procedure ***)
wenzelm@9713
   445
nipkow@5975
   446
(* Parameters:
nipkow@5975
   447
nipkow@5975
   448
   test: term -> bool
nipkow@5975
   449
   tests if a term is at all relevant to the refutation proof;
nipkow@5975
   450
   if not, then it can be discarded. Can improve performance,
nipkow@5975
   451
   esp. if disjunctions can be discarded (no case distinction needed!).
nipkow@5975
   452
nipkow@5975
   453
   prep_tac: int -> tactic
nipkow@5975
   454
   A preparation tactic to be applied to the goal once all relevant premises
nipkow@5975
   455
   have been moved to the conclusion.
nipkow@5975
   456
nipkow@5975
   457
   ref_tac: int -> tactic
nipkow@5975
   458
   the actual refutation tactic. Should be able to deal with goals
nipkow@5975
   459
   [| A1; ...; An |] ==> False
wenzelm@9876
   460
   where the Ai are atomic, i.e. no top-level &, | or EX
nipkow@5975
   461
*)
nipkow@5975
   462
nipkow@5975
   463
fun refute_tac test prep_tac ref_tac =
nipkow@5975
   464
  let val nnf_simps =
nipkow@5975
   465
        [imp_conv_disj,iff_conv_conj_imp,de_Morgan_disj,de_Morgan_conj,
nipkow@5975
   466
         not_all,not_ex,not_not];
nipkow@5975
   467
      val nnf_simpset =
nipkow@5975
   468
        empty_ss setmkeqTrue mk_eq_True
nipkow@5975
   469
                 setmksimps (mksimps mksimps_pairs)
nipkow@5975
   470
                 addsimps nnf_simps;
nipkow@5975
   471
      val prem_nnf_tac = full_simp_tac nnf_simpset;
nipkow@5975
   472
nipkow@5975
   473
      val refute_prems_tac =
nipkow@5975
   474
        REPEAT(eresolve_tac [conjE, exE] 1 ORELSE
nipkow@5975
   475
               filter_prems_tac test 1 ORELSE
paulson@6301
   476
               etac disjE 1) THEN
nipkow@11200
   477
        ((etac notE 1 THEN eq_assume_tac 1) ORELSE
nipkow@11200
   478
         ref_tac 1);
nipkow@5975
   479
  in EVERY'[TRY o filter_prems_tac test,
nipkow@6128
   480
            DETERM o REPEAT o etac rev_mp, prep_tac, rtac ccontr, prem_nnf_tac,
nipkow@5975
   481
            SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)]
nipkow@5975
   482
  end;