src/Provers/clasimp.ML
author wenzelm
Tue, 21 Sep 1999 17:26:50 +0200
changeset 7559 1d2c099e98f7
parent 7437 0f99a2103ea0
child 7957 0196b2302e21
permissions -rw-r--r--
setup for refined facts handling;
Method.bang_sectioned_args / Args.bang_facts;
     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   val setup	  : (theory -> theory) list
    48 end;
    49 
    50 functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP =
    51 struct
    52 
    53 open Data;
    54 
    55 type claset = Classical.claset;
    56 type simpset = Simplifier.simpset;
    57 type clasimpset = claset * simpset;
    58 
    59 
    60 (* clasimpset operations *)
    61 
    62 (*this interface for updating a clasimpset is rudimentary and just for
    63   convenience for the most common cases*)
    64 
    65 fun pair_upd1 f ((a,b),x) = (f(a,x), b);
    66 fun pair_upd2 f ((a,b),x) = (a, f(b,x));
    67 
    68 fun op addSIs2   arg = pair_upd1 Classical.addSIs arg;
    69 fun op addSEs2   arg = pair_upd1 Classical.addSEs arg;
    70 fun op addSDs2   arg = pair_upd1 Classical.addSDs arg;
    71 fun op addIs2    arg = pair_upd1 Classical.addIs arg;
    72 fun op addEs2    arg = pair_upd1 Classical.addEs arg;
    73 fun op addDs2    arg = pair_upd1 Classical.addDs arg;
    74 fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
    75 fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg;
    76 
    77 (*Add a simpset to a classical set!*)
    78 (*Caution: only one simpset added can be added by each of addSss and addss*)
    79 fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
    80 			    CHANGED o Simplifier.safe_asm_full_simp_tac ss));
    81 fun cs addss  ss = Classical.addbefore  (cs, ("asm_full_simp_tac", 
    82 			    CHANGED o Simplifier.asm_full_simp_tac ss));
    83 
    84 (* tacticals *)
    85 
    86 fun CLASIMPSET tacf state =
    87   Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
    88 
    89 fun CLASIMPSET' tacf i state =
    90   Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
    91 
    92 
    93 fun clarsimp_tac (cs, ss) = Simplifier.safe_asm_full_simp_tac ss THEN_MAYBE'
    94 			    Classical.clarify_tac (cs addSss ss);
    95 fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
    96 
    97 
    98 (* auto_tac *)
    99 
   100 fun blast_depth_tac cs m i thm =
   101     Blast.depth_tac cs m i thm 
   102       handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
   103  
   104 (* a variant of depth_tac that avoids interference of the simplifier 
   105    with dup_step_tac when they are combined by auto_tac *)
   106 local
   107 fun slow_step_tac' cs = Classical.appWrappers cs 
   108 	(Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs);
   109 in fun nodup_depth_tac cs m i state = SELECT_GOAL 
   110    (Classical.safe_steps_tac cs 1 THEN_ELSE 
   111 	(DEPTH_SOLVE (nodup_depth_tac cs m 1),
   112 	 Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac
   113 	     (slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1))
   114         )) i state;
   115 end;
   116 
   117 (*Designed to be idempotent, except if best_tac instantiates variables
   118   in some of the subgoals*)
   119 fun mk_auto_tac (cs, ss) m n =
   120     let val cs' = cs addss ss
   121         val maintac = 
   122           blast_depth_tac cs m		     (* fast but can't use wrappers *)
   123           ORELSE'
   124           (CHANGED o nodup_depth_tac cs' n); (* slower but more general *)
   125     in  EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
   126 	       TRY (Classical.safe_tac cs),
   127 	       REPEAT (FIRSTGOAL maintac),
   128                TRY (Classical.safe_tac (cs addSss ss)),
   129 	       prune_params_tac] 
   130     end;
   131 
   132 fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
   133 
   134 fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st;
   135 
   136 fun auto () = by Auto_tac;
   137 
   138 
   139 (* force_tac *)
   140 
   141 (* aimed to solve the given subgoal totally, using whatever tools possible *)
   142 fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
   143 	Classical.clarify_tac cs' 1,
   144 	IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
   145 	ALLGOALS (Classical.best_tac cs')]) end;
   146 fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i;
   147 fun force i = by (Force_tac i);
   148 
   149 
   150 (* methods *)
   151 
   152 fun get_local_clasimpset ctxt =
   153   (Classical.get_local_claset ctxt, Simplifier.get_local_simpset ctxt);
   154 
   155 val clasimp_modifiers = Classical.cla_modifiers @ Simplifier.simp_modifiers;
   156 
   157 fun clasimp_meth tac prems ctxt = Method.METHOD (fn facts =>
   158   ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_clasimpset ctxt));
   159 
   160 fun clasimp_meth' tac prems ctxt = Method.METHOD (fn facts =>
   161   FIRSTGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_clasimpset ctxt)));
   162 
   163 val clasimp_method = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth;
   164 val clasimp_method' = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth';
   165 
   166 
   167 val setup =
   168  [Method.add_methods
   169    [("clarsimp_tac", clasimp_method' clarsimp_tac, "clarsimp (improper!)"),
   170     ("auto", clasimp_method (CHANGED o auto_tac), "auto"),
   171     ("force", clasimp_method' force_tac, "force")]];
   172     
   173 
   174 
   175 end;