src/HOL/simpdata.ML
 author wenzelm Tue Jul 18 21:08:40 2000 +0200 (2000-07-18) changeset 9384 8e8941c491e6 parent 9164 88e0f647b9c2 child 9511 bb029080ff8b permissions -rw-r--r--
* HOL: removed obsolete expand_if = split_if; theorems if_splits =
split_if split_if_asm;
```     1 (*  Title:      HOL/simpdata.ML
```
```     2     ID:         \$Id\$
```
```     3     Author:     Tobias Nipkow
```
```     4     Copyright   1991  University of Cambridge
```
```     5
```
```     6 Instantiation of the generic simplifier for HOL.
```
```     7 *)
```
```     8
```
```     9 section "Simplifier";
```
```    10
```
```    11 (*** Addition of rules to simpsets and clasets simultaneously ***)	(* FIXME move to Provers/clasimp.ML? *)
```
```    12
```
```    13 infix 4 addIffs delIffs;
```
```    14
```
```    15 (*Takes UNCONDITIONAL theorems of the form A<->B to
```
```    16         the Safe Intr     rule B==>A and
```
```    17         the Safe Destruct rule A==>B.
```
```    18   Also ~A goes to the Safe Elim rule A ==> ?R
```
```    19   Failing other cases, A is added as a Safe Intr rule*)
```
```    20 local
```
```    21   val iff_const = HOLogic.eq_const HOLogic.boolT;
```
```    22
```
```    23   fun addIff ((cla, simp), th) =
```
```    24       (case HOLogic.dest_Trueprop (#prop (rep_thm th)) of
```
```    25                 (Const("Not", _) \$ A) =>
```
```    26                     cla addSEs [zero_var_indexes (th RS notE)]
```
```    27               | (con \$ _ \$ _) =>
```
```    28                     if con = iff_const
```
```    29                     then cla addSIs [zero_var_indexes (th RS iffD2)]
```
```    30                               addSDs [zero_var_indexes (th RS iffD1)]
```
```    31                     else  cla addSIs [th]
```
```    32               | _ => cla addSIs [th],
```
```    33        simp addsimps [th])
```
```    34       handle TERM _ => error ("AddIffs: theorem must be unconditional\n" ^
```
```    35                          string_of_thm th);
```
```    36
```
```    37   fun delIff ((cla, simp), th) =
```
```    38       (case HOLogic.dest_Trueprop (#prop (rep_thm th)) of
```
```    39 	   (Const ("Not", _) \$ A) =>
```
```    40 	       cla delrules [zero_var_indexes (th RS notE)]
```
```    41 	 | (con \$ _ \$ _) =>
```
```    42 	       if con = iff_const
```
```    43 	       then cla delrules
```
```    44 		        [zero_var_indexes (th RS iffD2),
```
```    45 			 cla_make_elim (zero_var_indexes (th RS iffD1))]
```
```    46 	       else cla delrules [th]
```
```    47 	 | _ => cla delrules [th],
```
```    48        simp delsimps [th])
```
```    49       handle TERM _ => (warning("DelIffs: ignoring conditional theorem\n" ^
```
```    50 				string_of_thm th); (cla, simp));
```
```    51
```
```    52   fun store_clasimp (cla, simp) = (claset_ref () := cla; simpset_ref () := simp)
```
```    53 in
```
```    54 val op addIffs = foldl addIff;
```
```    55 val op delIffs = foldl delIff;
```
```    56 fun AddIffs thms = store_clasimp ((claset (), simpset ()) addIffs thms);
```
```    57 fun DelIffs thms = store_clasimp ((claset (), simpset ()) delIffs thms);
```
```    58 end;
```
```    59
```
```    60
```
```    61 val [prem] = goal (the_context ()) "x==y ==> x=y";
```
```    62 by (rewtac prem);
```
```    63 by (rtac refl 1);
```
```    64 qed "meta_eq_to_obj_eq";
```
```    65
```
```    66 Goal "(%s. f s) = f";
```
```    67 br refl 1;
```
```    68 qed "eta_contract_eq";
```
```    69
```
```    70 local
```
```    71
```
```    72   fun prover s = prove_goal (the_context ()) s (fn _ => [(Blast_tac 1)]);
```
```    73
```
```    74 in
```
```    75
```
```    76 (*Make meta-equalities.  The operator below is Trueprop*)
```
```    77
```
```    78 fun mk_meta_eq r = r RS eq_reflection;
```
```    79
```
```    80 val Eq_TrueI  = mk_meta_eq(prover  "P --> (P = True)"  RS mp);
```
```    81 val Eq_FalseI = mk_meta_eq(prover "~P --> (P = False)" RS mp);
```
```    82
```
```    83 fun mk_eq th = case concl_of th of
```
```    84         Const("==",_)\$_\$_       => th
```
```    85     |   _\$(Const("op =",_)\$_\$_) => mk_meta_eq th
```
```    86     |   _\$(Const("Not",_)\$_)    => th RS Eq_FalseI
```
```    87     |   _                       => th RS Eq_TrueI;
```
```    88 (* last 2 lines requires all formulae to be of the from Trueprop(.) *)
```
```    89
```
```    90 fun mk_eq_True r = Some(r RS meta_eq_to_obj_eq RS Eq_TrueI);
```
```    91
```
```    92 fun mk_meta_cong rl =
```
```    93   standard(mk_meta_eq(replicate (nprems_of rl) meta_eq_to_obj_eq MRS rl))
```
```    94   handle THM _ =>
```
```    95   error("Premises and conclusion of congruence rules must be =-equalities");
```
```    96
```
```    97 val not_not = prover "(~ ~ P) = P";
```
```    98
```
```    99 val simp_thms = [not_not] @ map prover
```
```   100  [ "(x=x) = True",
```
```   101    "(~True) = False", "(~False) = True",
```
```   102    "(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))",
```
```   103    "(True=P) = P", "(P=True) = P", "(False=P) = (~P)", "(P=False) = (~P)",
```
```   104    "(True --> P) = P", "(False --> P) = True",
```
```   105    "(P --> True) = True", "(P --> P) = True",
```
```   106    "(P --> False) = (~P)", "(P --> ~P) = (~P)",
```
```   107    "(P & True) = P", "(True & P) = P",
```
```   108    "(P & False) = False", "(False & P) = False",
```
```   109    "(P & P) = P", "(P & (P & Q)) = (P & Q)",
```
```   110    "(P & ~P) = False",    "(~P & P) = False",
```
```   111    "(P | True) = True", "(True | P) = True",
```
```   112    "(P | False) = P", "(False | P) = P",
```
```   113    "(P | P) = P", "(P | (P | Q)) = (P | Q)",
```
```   114    "(P | ~P) = True",    "(~P | P) = True",
```
```   115    "((~P) = (~Q)) = (P=Q)",
```
```   116    "(!x. P) = P", "(? x. P) = P", "? x. x=t", "? x. t=x",
```
```   117 (*two needed for the one-point-rule quantifier simplification procs*)
```
```   118    "(? x. x=t & P(x)) = P(t)",		(*essential for termination!!*)
```
```   119    "(! x. t=x --> P(x)) = P(t)" ];      (*covers a stray case*)
```
```   120
```
```   121 (* Add congruence rules for = (instead of ==) *)
```
```   122
```
```   123 (* ###FIXME: Move to simplifier,
```
```   124    taking mk_meta_cong as input, eliminating addeqcongs and deleqcongs *)
```
```   125 infix 4 addcongs delcongs;
```
```   126 fun ss addcongs congs = ss addeqcongs (map mk_meta_cong congs);
```
```   127 fun ss delcongs congs = ss deleqcongs (map mk_meta_cong congs);
```
```   128 fun Addcongs congs = (simpset_ref() := simpset() addcongs congs);
```
```   129 fun Delcongs congs = (simpset_ref() := simpset() delcongs congs);
```
```   130
```
```   131 val cong_add_global = Simplifier.change_global_ss (op addcongs);
```
```   132 val cong_del_global = Simplifier.change_global_ss (op delcongs);
```
```   133 val cong_add_local = Simplifier.change_local_ss (op addcongs);
```
```   134 val cong_del_local = Simplifier.change_local_ss (op delcongs);
```
```   135
```
```   136 val cong_attrib_setup =
```
```   137  [Attrib.add_attributes [("cong",
```
```   138    (Attrib.add_del_args cong_add_global cong_del_global,
```
```   139     Attrib.add_del_args cong_add_local cong_del_local),
```
```   140     "declare Simplifier congruence rules")]];
```
```   141
```
```   142
```
```   143 val imp_cong = impI RSN
```
```   144     (2, prove_goal (the_context ()) "(P=P')--> (P'--> (Q=Q'))--> ((P-->Q) = (P'-->Q'))"
```
```   145         (fn _=> [(Blast_tac 1)]) RS mp RS mp);
```
```   146
```
```   147 (*Miniscoping: pushing in existential quantifiers*)
```
```   148 val ex_simps = map prover
```
```   149                 ["(EX x. P x & Q)   = ((EX x. P x) & Q)",
```
```   150                  "(EX x. P & Q x)   = (P & (EX x. Q x))",
```
```   151                  "(EX x. P x | Q)   = ((EX x. P x) | Q)",
```
```   152                  "(EX x. P | Q x)   = (P | (EX x. Q x))",
```
```   153                  "(EX x. P x --> Q) = ((ALL x. P x) --> Q)",
```
```   154                  "(EX x. P --> Q x) = (P --> (EX x. Q x))"];
```
```   155
```
```   156 (*Miniscoping: pushing in universal quantifiers*)
```
```   157 val all_simps = map prover
```
```   158                 ["(ALL x. P x & Q)   = ((ALL x. P x) & Q)",
```
```   159                  "(ALL x. P & Q x)   = (P & (ALL x. Q x))",
```
```   160                  "(ALL x. P x | Q)   = ((ALL x. P x) | Q)",
```
```   161                  "(ALL x. P | Q x)   = (P | (ALL x. Q x))",
```
```   162                  "(ALL x. P x --> Q) = ((EX x. P x) --> Q)",
```
```   163                  "(ALL x. P --> Q x) = (P --> (ALL x. Q x))"];
```
```   164
```
```   165
```
```   166 (* elimination of existential quantifiers in assumptions *)
```
```   167
```
```   168 val ex_all_equiv =
```
```   169   let val lemma1 = prove_goal (the_context ())
```
```   170         "(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)"
```
```   171         (fn prems => [resolve_tac prems 1, etac exI 1]);
```
```   172       val lemma2 = prove_goalw (the_context ()) [Ex_def]
```
```   173         "(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)"
```
```   174         (fn prems => [(REPEAT(resolve_tac prems 1))])
```
```   175   in equal_intr lemma1 lemma2 end;
```
```   176
```
```   177 end;
```
```   178
```
```   179 bind_thms ("ex_simps", ex_simps);
```
```   180 bind_thms ("all_simps", all_simps);
```
```   181 bind_thm ("not_not", not_not);
```
```   182
```
```   183 (* Elimination of True from asumptions: *)
```
```   184
```
```   185 val True_implies_equals = prove_goal (the_context ())
```
```   186  "(True ==> PROP P) == PROP P"
```
```   187 (fn _ => [rtac equal_intr_rule 1, atac 2,
```
```   188           METAHYPS (fn prems => resolve_tac prems 1) 1,
```
```   189           rtac TrueI 1]);
```
```   190
```
```   191 fun prove nm thm  = qed_goal nm (the_context ()) thm (fn _ => [(Blast_tac 1)]);
```
```   192
```
```   193 prove "eq_commute" "(a=b)=(b=a)";
```
```   194 prove "eq_left_commute" "(P=(Q=R)) = (Q=(P=R))";
```
```   195 prove "eq_assoc" "((P=Q)=R) = (P=(Q=R))";
```
```   196 val eq_ac = [eq_commute, eq_left_commute, eq_assoc];
```
```   197
```
```   198 prove "conj_commute" "(P&Q) = (Q&P)";
```
```   199 prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))";
```
```   200 val conj_comms = [conj_commute, conj_left_commute];
```
```   201 prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))";
```
```   202
```
```   203 prove "disj_commute" "(P|Q) = (Q|P)";
```
```   204 prove "disj_left_commute" "(P|(Q|R)) = (Q|(P|R))";
```
```   205 val disj_comms = [disj_commute, disj_left_commute];
```
```   206 prove "disj_assoc" "((P|Q)|R) = (P|(Q|R))";
```
```   207
```
```   208 prove "conj_disj_distribL" "(P&(Q|R)) = (P&Q | P&R)";
```
```   209 prove "conj_disj_distribR" "((P|Q)&R) = (P&R | Q&R)";
```
```   210
```
```   211 prove "disj_conj_distribL" "(P|(Q&R)) = ((P|Q) & (P|R))";
```
```   212 prove "disj_conj_distribR" "((P&Q)|R) = ((P|R) & (Q|R))";
```
```   213
```
```   214 prove "imp_conjR" "(P --> (Q&R)) = ((P-->Q) & (P-->R))";
```
```   215 prove "imp_conjL" "((P&Q) -->R)  = (P --> (Q --> R))";
```
```   216 prove "imp_disjL" "((P|Q) --> R) = ((P-->R)&(Q-->R))";
```
```   217
```
```   218 (*These two are specialized, but imp_disj_not1 is useful in Auth/Yahalom.ML*)
```
```   219 prove "imp_disj_not1" "(P --> Q | R) = (~Q --> P --> R)";
```
```   220 prove "imp_disj_not2" "(P --> Q | R) = (~R --> P --> Q)";
```
```   221
```
```   222 prove "imp_disj1" "((P-->Q)|R) = (P--> Q|R)";
```
```   223 prove "imp_disj2" "(Q|(P-->R)) = (P--> Q|R)";
```
```   224
```
```   225 prove "de_Morgan_disj" "(~(P | Q)) = (~P & ~Q)";
```
```   226 prove "de_Morgan_conj" "(~(P & Q)) = (~P | ~Q)";
```
```   227 prove "not_imp" "(~(P --> Q)) = (P & ~Q)";
```
```   228 prove "not_iff" "(P~=Q) = (P = (~Q))";
```
```   229 prove "disj_not1" "(~P | Q) = (P --> Q)";
```
```   230 prove "disj_not2" "(P | ~Q) = (Q --> P)"; (* changes orientation :-( *)
```
```   231 prove "imp_conv_disj" "(P --> Q) = ((~P) | Q)";
```
```   232
```
```   233 prove "iff_conv_conj_imp" "(P = Q) = ((P --> Q) & (Q --> P))";
```
```   234
```
```   235
```
```   236 (*Avoids duplication of subgoals after split_if, when the true and false
```
```   237   cases boil down to the same thing.*)
```
```   238 prove "cases_simp" "((P --> Q) & (~P --> Q)) = Q";
```
```   239
```
```   240 prove "not_all" "(~ (! x. P(x))) = (? x.~P(x))";
```
```   241 prove "imp_all" "((! x. P x) --> Q) = (? x. P x --> Q)";
```
```   242 prove "not_ex"  "(~ (? x. P(x))) = (! x.~P(x))";
```
```   243 prove "imp_ex" "((? x. P x) --> Q) = (! x. P x --> Q)";
```
```   244
```
```   245 prove "ex_disj_distrib" "(? x. P(x) | Q(x)) = ((? x. P(x)) | (? x. Q(x)))";
```
```   246 prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))";
```
```   247
```
```   248 (* '&' congruence rule: not included by default!
```
```   249    May slow rewrite proofs down by as much as 50% *)
```
```   250
```
```   251 let val th = prove_goal (the_context ())
```
```   252                 "(P=P')--> (P'--> (Q=Q'))--> ((P&Q) = (P'&Q'))"
```
```   253                 (fn _=> [(Blast_tac 1)])
```
```   254 in  bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
```
```   255
```
```   256 let val th = prove_goal (the_context ())
```
```   257                 "(Q=Q')--> (Q'--> (P=P'))--> ((P&Q) = (P'&Q'))"
```
```   258                 (fn _=> [(Blast_tac 1)])
```
```   259 in  bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
```
```   260
```
```   261 (* '|' congruence rule: not included by default! *)
```
```   262
```
```   263 let val th = prove_goal (the_context ())
```
```   264                 "(P=P')--> (~P'--> (Q=Q'))--> ((P|Q) = (P'|Q'))"
```
```   265                 (fn _=> [(Blast_tac 1)])
```
```   266 in  bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp)))  end;
```
```   267
```
```   268 prove "eq_sym_conv" "(x=y) = (y=x)";
```
```   269
```
```   270
```
```   271 (** if-then-else rules **)
```
```   272
```
```   273 Goalw [if_def] "(if True then x else y) = x";
```
```   274 by (Blast_tac 1);
```
```   275 qed "if_True";
```
```   276
```
```   277 Goalw [if_def] "(if False then x else y) = y";
```
```   278 by (Blast_tac 1);
```
```   279 qed "if_False";
```
```   280
```
```   281 Goalw [if_def] "P ==> (if P then x else y) = x";
```
```   282 by (Blast_tac 1);
```
```   283 qed "if_P";
```
```   284
```
```   285 Goalw [if_def] "~P ==> (if P then x else y) = y";
```
```   286 by (Blast_tac 1);
```
```   287 qed "if_not_P";
```
```   288
```
```   289 Goal "P(if Q then x else y) = ((Q --> P(x)) & (~Q --> P(y)))";
```
```   290 by (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1);
```
```   291 by (stac if_P 2);
```
```   292 by (stac if_not_P 1);
```
```   293 by (ALLGOALS (Blast_tac));
```
```   294 qed "split_if";
```
```   295
```
```   296 Goal "P(if Q then x else y) = (~((Q & ~P x) | (~Q & ~P y)))";
```
```   297 by (stac split_if 1);
```
```   298 by (Blast_tac 1);
```
```   299 qed "split_if_asm";
```
```   300
```
```   301 bind_thms ("if_splits", [split_if, split_if_asm]);
```
```   302
```
```   303 Goal "(if c then x else x) = x";
```
```   304 by (stac split_if 1);
```
```   305 by (Blast_tac 1);
```
```   306 qed "if_cancel";
```
```   307
```
```   308 Goal "(if x = y then y else x) = x";
```
```   309 by (stac split_if 1);
```
```   310 by (Blast_tac 1);
```
```   311 qed "if_eq_cancel";
```
```   312
```
```   313 (*This form is useful for expanding IFs on the RIGHT of the ==> symbol*)
```
```   314 Goal "(if P then Q else R) = ((P-->Q) & (~P-->R))";
```
```   315 by (rtac split_if 1);
```
```   316 qed "if_bool_eq_conj";
```
```   317
```
```   318 (*And this form is useful for expanding IFs on the LEFT*)
```
```   319 Goal "(if P then Q else R) = ((P&Q) | (~P&R))";
```
```   320 by (stac split_if 1);
```
```   321 by (Blast_tac 1);
```
```   322 qed "if_bool_eq_disj";
```
```   323
```
```   324
```
```   325 (*** make simplification procedures for quantifier elimination ***)
```
```   326
```
```   327 structure Quantifier1 = Quantifier1Fun(
```
```   328 struct
```
```   329   (*abstract syntax*)
```
```   330   fun dest_eq((c as Const("op =",_)) \$ s \$ t) = Some(c,s,t)
```
```   331     | dest_eq _ = None;
```
```   332   fun dest_conj((c as Const("op &",_)) \$ s \$ t) = Some(c,s,t)
```
```   333     | dest_conj _ = None;
```
```   334   val conj = HOLogic.conj
```
```   335   val imp  = HOLogic.imp
```
```   336   (*rules*)
```
```   337   val iff_reflection = eq_reflection
```
```   338   val iffI = iffI
```
```   339   val sym  = sym
```
```   340   val conjI= conjI
```
```   341   val conjE= conjE
```
```   342   val impI = impI
```
```   343   val impE = impE
```
```   344   val mp   = mp
```
```   345   val exI  = exI
```
```   346   val exE  = exE
```
```   347   val allI = allI
```
```   348   val allE = allE
```
```   349 end);
```
```   350
```
```   351 local
```
```   352 val ex_pattern =
```
```   353   Thm.read_cterm (Theory.sign_of (the_context ())) ("EX x. P(x) & Q(x)",HOLogic.boolT)
```
```   354
```
```   355 val all_pattern =
```
```   356   Thm.read_cterm (Theory.sign_of (the_context ())) ("ALL x. P(x) & P'(x) --> Q(x)",HOLogic.boolT)
```
```   357
```
```   358 in
```
```   359 val defEX_regroup =
```
```   360   mk_simproc "defined EX" [ex_pattern] Quantifier1.rearrange_ex;
```
```   361 val defALL_regroup =
```
```   362   mk_simproc "defined ALL" [all_pattern] Quantifier1.rearrange_all;
```
```   363 end;
```
```   364
```
```   365
```
```   366 (*** Case splitting ***)
```
```   367
```
```   368 structure SplitterData =
```
```   369   struct
```
```   370   structure Simplifier = Simplifier
```
```   371   val mk_eq          = mk_eq
```
```   372   val meta_eq_to_iff = meta_eq_to_obj_eq
```
```   373   val iffD           = iffD2
```
```   374   val disjE          = disjE
```
```   375   val conjE          = conjE
```
```   376   val exE            = exE
```
```   377   val contrapos      = contrapos
```
```   378   val contrapos2     = contrapos2
```
```   379   val notnotD        = notnotD
```
```   380   end;
```
```   381
```
```   382 structure Splitter = SplitterFun(SplitterData);
```
```   383
```
```   384 val split_tac        = Splitter.split_tac;
```
```   385 val split_inside_tac = Splitter.split_inside_tac;
```
```   386 val split_asm_tac    = Splitter.split_asm_tac;
```
```   387 val op addsplits     = Splitter.addsplits;
```
```   388 val op delsplits     = Splitter.delsplits;
```
```   389 val Addsplits        = Splitter.Addsplits;
```
```   390 val Delsplits        = Splitter.Delsplits;
```
```   391
```
```   392 (*In general it seems wrong to add distributive laws by default: they
```
```   393   might cause exponential blow-up.  But imp_disjL has been in for a while
```
```   394   and cannot be removed without affecting existing proofs.  Moreover,
```
```   395   rewriting by "(P|Q --> R) = ((P-->R)&(Q-->R))" might be justified on the
```
```   396   grounds that it allows simplification of R in the two cases.*)
```
```   397
```
```   398 fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th;
```
```   399
```
```   400 val mksimps_pairs =
```
```   401   [("op -->", [mp]), ("op &", [conjunct1,conjunct2]),
```
```   402    ("All", [spec]), ("True", []), ("False", []),
```
```   403    ("If", [if_bool_eq_conj RS iffD1])];
```
```   404
```
```   405 (* ###FIXME: move to Provers/simplifier.ML
```
```   406 val mk_atomize:      (string * thm list) list -> thm -> thm list
```
```   407 *)
```
```   408 (* ###FIXME: move to Provers/simplifier.ML *)
```
```   409 fun mk_atomize pairs =
```
```   410   let fun atoms th =
```
```   411         (case concl_of th of
```
```   412            Const("Trueprop",_) \$ p =>
```
```   413              (case head_of p of
```
```   414                 Const(a,_) =>
```
```   415                   (case assoc(pairs,a) of
```
```   416                      Some(rls) => flat (map atoms ([th] RL rls))
```
```   417                    | None => [th])
```
```   418               | _ => [th])
```
```   419          | _ => [th])
```
```   420   in atoms end;
```
```   421
```
```   422 fun mksimps pairs = (map mk_eq o mk_atomize pairs o gen_all);
```
```   423
```
```   424 fun unsafe_solver_tac prems =
```
```   425   FIRST'[resolve_tac(reflexive_thm::TrueI::refl::prems), atac, etac FalseE];
```
```   426 val unsafe_solver = mk_solver "HOL unsafe" unsafe_solver_tac;
```
```   427
```
```   428 (*No premature instantiation of variables during simplification*)
```
```   429 fun safe_solver_tac prems =
```
```   430   FIRST'[match_tac(reflexive_thm::TrueI::refl::prems),
```
```   431          eq_assume_tac, ematch_tac [FalseE]];
```
```   432 val safe_solver = mk_solver "HOL safe" safe_solver_tac;
```
```   433
```
```   434 val HOL_basic_ss = empty_ss setsubgoaler asm_simp_tac
```
```   435 			    setSSolver safe_solver
```
```   436 			    setSolver  unsafe_solver
```
```   437 			    setmksimps (mksimps mksimps_pairs)
```
```   438 			    setmkeqTrue mk_eq_True;
```
```   439
```
```   440 val HOL_ss =
```
```   441     HOL_basic_ss addsimps
```
```   442      ([triv_forall_equality, (* prunes params *)
```
```   443        True_implies_equals, (* prune asms `True' *)
```
```   444        eta_contract_eq, (* prunes eta-expansions *)
```
```   445        if_True, if_False, if_cancel, if_eq_cancel,
```
```   446        imp_disjL, conj_assoc, disj_assoc,
```
```   447        de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2, not_imp,
```
```   448        disj_not1, not_all, not_ex, cases_simp, Eps_eq, Eps_sym_eq,
```
```   449        thm"plus_ac0.zero", thm"plus_ac0_zero_right"]
```
```   450      @ ex_simps @ all_simps @ simp_thms)
```
```   451      addsimprocs [defALL_regroup,defEX_regroup]
```
```   452      addcongs [imp_cong]
```
```   453      addsplits [split_if];
```
```   454
```
```   455 (*Simplifies x assuming c and y assuming ~c*)
```
```   456 val prems = Goalw [if_def]
```
```   457   "[| b=c; c ==> x=u; ~c ==> y=v |] ==> \
```
```   458 \  (if b then x else y) = (if c then u else v)";
```
```   459 by (asm_simp_tac (HOL_ss addsimps prems) 1);
```
```   460 qed "if_cong";
```
```   461
```
```   462 (*Prevents simplification of x and y: faster and allows the execution
```
```   463   of functional programs. NOW THE DEFAULT.*)
```
```   464 Goal "b=c ==> (if b then x else y) = (if c then x else y)";
```
```   465 by (etac arg_cong 1);
```
```   466 qed "if_weak_cong";
```
```   467
```
```   468 (*Prevents simplification of t: much faster*)
```
```   469 Goal "a = b ==> (let x=a in t(x)) = (let x=b in t(x))";
```
```   470 by (etac arg_cong 1);
```
```   471 qed "let_weak_cong";
```
```   472
```
```   473 Goal "f(if c then x else y) = (if c then f x else f y)";
```
```   474 by (simp_tac (HOL_ss setloop (split_tac [split_if])) 1);
```
```   475 qed "if_distrib";
```
```   476
```
```   477 (*For expand_case_tac*)
```
```   478 val prems = Goal "[| P ==> Q(True); ~P ==> Q(False) |] ==> Q(P)";
```
```   479 by (case_tac "P" 1);
```
```   480 by (ALLGOALS (asm_simp_tac (HOL_ss addsimps prems)));
```
```   481 qed "expand_case";
```
```   482
```
```   483 (*Used in Auth proofs.  Typically P contains Vars that become instantiated
```
```   484   during unification.*)
```
```   485 fun expand_case_tac P i =
```
```   486     res_inst_tac [("P",P)] expand_case i THEN
```
```   487     Simp_tac (i+1) THEN
```
```   488     Simp_tac i;
```
```   489
```
```   490 (*This lemma restricts the effect of the rewrite rule u=v to the left-hand
```
```   491   side of an equality.  Used in {Integ,Real}/simproc.ML*)
```
```   492 Goal "x=y ==> (x=z) = (y=z)";
```
```   493 by (asm_simp_tac HOL_ss 1);
```
```   494 qed "restrict_to_left";
```
```   495
```
```   496 (* default simpset *)
```
```   497 val simpsetup =
```
```   498     [fn thy => (simpset_ref_of thy := HOL_ss addcongs [if_weak_cong];
```
```   499 		thy)];
```
```   500
```
```   501
```
```   502 (*** integration of simplifier with classical reasoner ***)
```
```   503
```
```   504 structure Clasimp = ClasimpFun
```
```   505  (structure Simplifier = Simplifier and Splitter = Splitter
```
```   506    and Classical  = Classical and Blast = Blast);
```
```   507 open Clasimp;
```
```   508
```
```   509 val HOL_css = (HOL_cs, HOL_ss);
```
```   510
```
```   511
```
```   512 (* "iff" attribute *)
```
```   513
```
```   514 val iff_add_global = Clasimp.change_global_css (op addIffs);
```
```   515 val iff_add_local = Clasimp.change_local_css (op addIffs);
```
```   516
```
```   517 val iff_attrib_setup =
```
```   518   [Attrib.add_attributes [("iff", (Attrib.no_args iff_add_global, Attrib.no_args iff_add_local),
```
```   519     "add rules to simpset and claset simultaneously")]];
```
```   520
```
```   521
```
```   522
```
```   523 (*** A general refutation procedure ***)
```
```   524
```
```   525 (* Parameters:
```
```   526
```
```   527    test: term -> bool
```
```   528    tests if a term is at all relevant to the refutation proof;
```
```   529    if not, then it can be discarded. Can improve performance,
```
```   530    esp. if disjunctions can be discarded (no case distinction needed!).
```
```   531
```
```   532    prep_tac: int -> tactic
```
```   533    A preparation tactic to be applied to the goal once all relevant premises
```
```   534    have been moved to the conclusion.
```
```   535
```
```   536    ref_tac: int -> tactic
```
```   537    the actual refutation tactic. Should be able to deal with goals
```
```   538    [| A1; ...; An |] ==> False
```
```   539    where the Ai are atomic, i.e. no top-level &, | or ?
```
```   540 *)
```
```   541
```
```   542 fun refute_tac test prep_tac ref_tac =
```
```   543   let val nnf_simps =
```
```   544         [imp_conv_disj,iff_conv_conj_imp,de_Morgan_disj,de_Morgan_conj,
```
```   545          not_all,not_ex,not_not];
```
```   546       val nnf_simpset =
```
```   547         empty_ss setmkeqTrue mk_eq_True
```
```   548                  setmksimps (mksimps mksimps_pairs)
```
```   549                  addsimps nnf_simps;
```
```   550       val prem_nnf_tac = full_simp_tac nnf_simpset;
```
```   551
```
```   552       val refute_prems_tac =
```
```   553         REPEAT(eresolve_tac [conjE, exE] 1 ORELSE
```
```   554                filter_prems_tac test 1 ORELSE
```
```   555                etac disjE 1) THEN
```
```   556         ref_tac 1;
```
```   557   in EVERY'[TRY o filter_prems_tac test,
```
```   558             DETERM o REPEAT o etac rev_mp, prep_tac, rtac ccontr, prem_nnf_tac,
```
```   559             SELECT_GOAL (DEPTH_SOLVE refute_prems_tac)]
```
```   560   end;
```