src/Provers/clasimp.ML
author oheimb
Fri Oct 23 20:35:56 1998 +0200 (1998-10-23)
changeset 5756 8ef5288c24b0
parent 5567 99c6ef61288f
child 5926 58f9ca06b76b
permissions -rw-r--r--
corrected auto_tac (applications of unsafe wrappers)
by correcting (and simplifying) nodup_depth_tac
     1 (*  Title: 	Provers/clasimp.ML
     2     ID:         $Id$
     3     Author:     David von Oheimb, TU Muenchen
     4 
     5 Combination of classical reasoner and simplifier (depends on
     6 simplifier.ML, classical.ML, blast.ML).
     7 *)
     8 
     9 infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2;
    10 infix 4 addSss addss;
    11 
    12 signature CLASIMP_DATA =
    13 sig
    14   structure Simplifier: SIMPLIFIER
    15   structure Classical: CLASSICAL
    16   structure Blast: BLAST
    17   sharing type Classical.claset = Blast.claset
    18 end
    19 
    20 signature CLASIMP =
    21 sig
    22   include CLASIMP_DATA
    23   type claset
    24   type simpset
    25   type clasimpset
    26   val addSIs2	: clasimpset * thm list -> clasimpset
    27   val addSEs2	: clasimpset * thm list -> clasimpset
    28   val addSDs2	: clasimpset * thm list -> clasimpset
    29   val addIs2	: clasimpset * thm list -> clasimpset
    30   val addEs2	: clasimpset * thm list -> clasimpset
    31   val addDs2	: clasimpset * thm list -> clasimpset
    32   val addsimps2	: clasimpset * thm list -> clasimpset
    33   val delsimps2	: clasimpset * thm list -> clasimpset
    34   val addSss	: claset * simpset -> claset
    35   val addss	: claset * simpset -> claset
    36   val CLASIMPSET  :(clasimpset -> tactic) -> tactic
    37   val CLASIMPSET' :(clasimpset -> 'a -> tactic) -> 'a -> tactic
    38   val clarsimp_tac: clasimpset -> int -> tactic
    39   val Clarsimp_tac:               int -> tactic
    40   val mk_auto_tac : clasimpset -> int -> int -> tactic
    41   val auto_tac	  : clasimpset -> tactic
    42   val Auto_tac	  : tactic
    43   val auto	  : unit -> unit
    44   val force_tac	  : clasimpset  -> int -> tactic
    45   val Force_tac	  : int -> tactic
    46   val force	  : int -> unit
    47 end;
    48 
    49 functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP =
    50 struct
    51 
    52 open Data;
    53 
    54 type claset = Classical.claset;
    55 type simpset = Simplifier.simpset;
    56 type clasimpset = claset * simpset;
    57 
    58 
    59 (* clasimpset operations *)
    60 
    61 (*this interface for updating a clasimpset is rudimentary and just for
    62   convenience for the most common cases*)
    63 
    64 fun pair_upd1 f ((a,b),x) = (f(a,x), b);
    65 fun pair_upd2 f ((a,b),x) = (a, f(b,x));
    66 
    67 fun op addSIs2   arg = pair_upd1 Classical.addSIs arg;
    68 fun op addSEs2   arg = pair_upd1 Classical.addSEs arg;
    69 fun op addSDs2   arg = pair_upd1 Classical.addSDs arg;
    70 fun op addIs2    arg = pair_upd1 Classical.addIs arg;
    71 fun op addEs2    arg = pair_upd1 Classical.addEs arg;
    72 fun op addDs2    arg = pair_upd1 Classical.addDs arg;
    73 fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
    74 fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg;
    75 
    76 (*Add a simpset to a classical set!*)
    77 (*Caution: only one simpset added can be added by each of addSss and addss*)
    78 fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
    79 			    CHANGED o Simplifier.safe_asm_full_simp_tac ss));
    80 fun cs addss  ss = Classical.addbefore  (cs, ("asm_full_simp_tac", 
    81 			    CHANGED o Simplifier.asm_full_simp_tac ss));
    82 
    83 (* tacticals *)
    84 
    85 fun CLASIMPSET tacf state =
    86   Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
    87 
    88 fun CLASIMPSET' tacf i state =
    89   Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
    90 
    91 
    92 fun clarsimp_tac (cs, ss) = Simplifier.safe_asm_full_simp_tac ss THEN_MAYBE'
    93 			    Classical.clarify_tac (cs addSss ss);
    94 fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
    95 
    96 
    97 (* auto_tac *)
    98 
    99 fun blast_depth_tac cs m i thm =
   100     Blast.depth_tac cs m i thm 
   101       handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
   102  
   103 (* a variant of depth_tac that avoids interference of the simplifier 
   104    with dup_step_tac when they are combined by auto_tac *)
   105 local
   106 fun slow_step_tac' cs = Classical.appWrappers cs 
   107 	(Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs);
   108 in fun nodup_depth_tac cs m i state = SELECT_GOAL 
   109    (Classical.safe_steps_tac cs 1 THEN_ELSE 
   110 	(DEPTH_SOLVE (nodup_depth_tac cs m 1),
   111 	 Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac
   112 	     (slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1))
   113         )) i state;
   114 end;
   115 
   116 (*Designed to be idempotent, except if best_tac instantiates variables
   117   in some of the subgoals*)
   118 fun mk_auto_tac (cs, ss) m n =
   119     let val cs' = cs addss ss
   120         val maintac = 
   121           blast_depth_tac cs m		     (* fast but can't use wrappers *)
   122           ORELSE'
   123           (CHANGED o nodup_depth_tac cs' n); (* slower but more general *)
   124     in  EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
   125 	       TRY (Classical.safe_tac cs),
   126 	       REPEAT (FIRSTGOAL maintac),
   127                TRY (Classical.safe_tac (cs addSss ss)),
   128 	       prune_params_tac] 
   129     end;
   130 
   131 fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
   132 
   133 fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st;
   134 
   135 fun auto () = by Auto_tac;
   136 
   137 
   138 (* force_tac *)
   139 
   140 (* aimed to solve the given subgoal totally, using whatever tools possible *)
   141 fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
   142 	Classical.clarify_tac cs' 1,
   143 	IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
   144 	ALLGOALS (Classical.best_tac cs')]) end;
   145 fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i;
   146 fun force i = by (Force_tac i);
   147 
   148 
   149 end;