src/Provers/clasimp.ML
author oheimb
Tue Mar 10 18:26:27 1998 +0100 (1998-03-10)
changeset 4717 1370ad043564
parent 4659 a78ecc7341e3
child 4884 1ec740e30811
permissions -rw-r--r--
renamed smart_tac to force_tac, slight improvement of force_tac
oheimb@4652
     1
(*  Title: 	Provers/clasimp.ML
oheimb@4652
     2
    ID:         $Id$
oheimb@4652
     3
    Author:     David von Oheimb, TU Muenchen
oheimb@4652
     4
oheimb@4652
     5
Combination of classical reasoner and simplifier
oheimb@4652
     6
to be used after installing both of them
oheimb@4652
     7
*)
oheimb@4652
     8
oheimb@4659
     9
type clasimpset = claset * simpset;
oheimb@4659
    10
oheimb@4652
    11
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2
oheimb@4652
    12
	addsimps2 delsimps2 addcongs2 delcongs2;
oheimb@4652
    13
infix 4 addSss addss;
oheimb@4652
    14
oheimb@4652
    15
signature CLASIMP =
oheimb@4652
    16
sig
oheimb@4652
    17
  val addSIs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    18
  val addSEs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    19
  val addSDs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    20
  val addIs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    21
  val addEs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    22
  val addDs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    23
  val addsimps2	: clasimpset * thm list -> clasimpset
oheimb@4652
    24
  val delsimps2	: clasimpset * thm list -> clasimpset
oheimb@4652
    25
  val addSss	: claset * simpset -> claset
oheimb@4652
    26
  val addss	: claset * simpset -> claset
oheimb@4652
    27
  val mk_auto_tac:clasimpset -> int -> int -> tactic
oheimb@4652
    28
  val auto_tac	: clasimpset -> tactic
oheimb@4652
    29
  val Auto_tac	: tactic
oheimb@4652
    30
  val auto	: unit -> unit
oheimb@4717
    31
  val force_tac	: clasimpset  -> int -> tactic
oheimb@4717
    32
  val Force_tac	: int -> tactic
oheimb@4717
    33
  val force	: int -> unit
oheimb@4652
    34
end;
oheimb@4652
    35
oheimb@4652
    36
structure Clasimp: CLASIMP =
oheimb@4652
    37
struct
oheimb@4652
    38
oheimb@4659
    39
(* this interface for updating a clasimpset is rudimentary and just for 
oheimb@4659
    40
   convenience for the most common cases. 
oheimb@4659
    41
   In other cases a clasimpset may be dealt with componentwise. *)
oheimb@4652
    42
local 
oheimb@4652
    43
  fun pair_upd1 f ((a,b),x) = (f(a,x), b);
oheimb@4652
    44
  fun pair_upd2 f ((a,b),x) = (a, f(b,x));
oheimb@4652
    45
in
oheimb@4652
    46
  fun op addSIs2   arg = pair_upd1 (op addSIs) arg;
oheimb@4652
    47
  fun op addSEs2   arg = pair_upd1 (op addSEs) arg;
oheimb@4652
    48
  fun op addSDs2   arg = pair_upd1 (op addSDs) arg;
oheimb@4652
    49
  fun op addIs2    arg = pair_upd1 (op addIs ) arg;
oheimb@4652
    50
  fun op addEs2    arg = pair_upd1 (op addEs ) arg;
oheimb@4652
    51
  fun op addDs2    arg = pair_upd1 (op addDs ) arg;
oheimb@4652
    52
  fun op addsimps2 arg = pair_upd2 (op addsimps) arg;
oheimb@4652
    53
  fun op delsimps2 arg = pair_upd2 (op delsimps) arg;
oheimb@4652
    54
  fun op addcongs2 arg = pair_upd2 (op addcongs) arg;
oheimb@4652
    55
  fun op delcongs2 arg = pair_upd2 (op delcongs) arg;
oheimb@4652
    56
end;
oheimb@4652
    57
oheimb@4652
    58
(*an unsatisfactory fix for the incomplete safe_asm_full_simp_tac!
oheimb@4652
    59
  better: asm_really_full_simp_tac, a yet to be implemented version of
oheimb@4652
    60
			asm_full_simp_tac that applies all equalities in the
oheimb@4652
    61
			premises to all the premises *)
oheimb@4652
    62
fun safe_asm_more_full_simp_tac ss = TRY o rot_eq_tac THEN' 
oheimb@4652
    63
				     safe_asm_full_simp_tac ss;
oheimb@4652
    64
oheimb@4652
    65
(*Add a simpset to a classical set!*)
oheimb@4652
    66
(*Caution: only one simpset added can be added by each of addSss and addss*)
oheimb@4652
    67
fun cs addSss ss = cs addSaltern ("safe_asm_more_full_simp_tac",
oheimb@4652
    68
			CHANGED o (safe_asm_more_full_simp_tac ss));
oheimb@4652
    69
fun cs addss  ss = cs addbefore  (     "asm_full_simp_tac",
oheimb@4652
    70
					asm_full_simp_tac ss);
oheimb@4652
    71
oheimb@4652
    72
oheimb@4652
    73
local
oheimb@4652
    74
oheimb@4652
    75
	fun blast_depth_tac cs m i thm = Blast.depth_tac cs m i thm 
oheimb@4652
    76
		handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
oheimb@4652
    77
oheimb@4652
    78
	(* a variant of depth_tac that avoids interference of the simplifier 
oheimb@4652
    79
	   with dup_step_tac when they are combined by auto_tac *)
oheimb@4652
    80
	fun nodup_depth_tac cs m i state = 
oheimb@4652
    81
	  SELECT_GOAL 
oheimb@4652
    82
	   (appWrappers cs
oheimb@4652
    83
	    (fn i => REPEAT_DETERM1 (COND (has_fewer_prems i) no_tac
oheimb@4652
    84
	                             (safe_step_tac cs i)) THEN_ELSE
oheimb@4652
    85
	     (DEPTH_SOLVE (nodup_depth_tac cs m i),
oheimb@4652
    86
	      inst0_step_tac cs i  APPEND
oheimb@4652
    87
	      COND (K(m=0)) no_tac
oheimb@4652
    88
	        ((instp_step_tac cs i APPEND step_tac cs i)
oheimb@4652
    89
	         THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) i)))) 1)
oheimb@4652
    90
	  i state;
oheimb@4652
    91
oheimb@4652
    92
in
oheimb@4652
    93
oheimb@4652
    94
(*Designed to be idempotent, except if best_tac instantiates variables
oheimb@4652
    95
  in some of the subgoals*)
oheimb@4652
    96
fun mk_auto_tac (cs, ss) m n =
oheimb@4652
    97
    let val cs' = cs addss ss 
oheimb@4652
    98
        val maintac = 
oheimb@4652
    99
          blast_depth_tac cs m		(*fast but can't use addss*)
oheimb@4652
   100
          ORELSE'
oheimb@4652
   101
          nodup_depth_tac cs' n;	(*slower but more general*)
oheimb@4652
   102
    in  EVERY [ALLGOALS (asm_full_simp_tac ss),
oheimb@4652
   103
	       TRY (safe_tac cs'),
oheimb@4652
   104
	       REPEAT (FIRSTGOAL maintac),
oheimb@4652
   105
               TRY (safe_tac (cs addSss ss)),
oheimb@4652
   106
	       prune_params_tac] 
oheimb@4652
   107
    end;
oheimb@4652
   108
end;
oheimb@4652
   109
oheimb@4652
   110
fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
oheimb@4652
   111
oheimb@4652
   112
fun Auto_tac st = auto_tac (claset(), simpset()) st;
oheimb@4652
   113
oheimb@4652
   114
fun auto () = by Auto_tac;
oheimb@4652
   115
oheimb@4659
   116
(* aimed to solve the given subgoal totally, using whatever tools possible *)
oheimb@4717
   117
fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
oheimb@4659
   118
	clarify_tac cs' 1,
oheimb@4659
   119
	IF_UNSOLVED (asm_full_simp_tac ss 1),
oheimb@4717
   120
	ALLGOALS (fast_tac cs')]) end;
oheimb@4717
   121
fun Force_tac i = force_tac (claset(), simpset()) i;
oheimb@4717
   122
fun force i = by (Force_tac i);
oheimb@4659
   123
oheimb@4652
   124
end;