src/Provers/clasimp.ML
author wenzelm
Wed, 15 Mar 2000 18:40:03 +0100
changeset 8469 482c301041b4
parent 8168 9d2ac5439089
child 8639 31bcb6b64d60
permissions -rw-r--r--
include Splitter.split_modifiers;
oheimb@4652
     1
(*  Title: 	Provers/clasimp.ML
oheimb@4652
     2
    ID:         $Id$
oheimb@4652
     3
    Author:     David von Oheimb, TU Muenchen
oheimb@4652
     4
wenzelm@5219
     5
Combination of classical reasoner and simplifier (depends on
wenzelm@8469
     6
simplifier.ML, splitter.ML classical.ML, blast.ML).
oheimb@4652
     7
*)
oheimb@4652
     8
oheimb@5554
     9
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2;
oheimb@4652
    10
infix 4 addSss addss;
oheimb@4652
    11
wenzelm@5219
    12
signature CLASIMP_DATA =
wenzelm@5219
    13
sig
wenzelm@5219
    14
  structure Simplifier: SIMPLIFIER
wenzelm@8469
    15
  structure Splitter: SPLITTER
wenzelm@5219
    16
  structure Classical: CLASSICAL
wenzelm@5219
    17
  structure Blast: BLAST
wenzelm@5219
    18
  sharing type Classical.claset = Blast.claset
wenzelm@5219
    19
end
wenzelm@5219
    20
oheimb@4652
    21
signature CLASIMP =
oheimb@4652
    22
sig
wenzelm@5219
    23
  include CLASIMP_DATA
wenzelm@5219
    24
  type claset
wenzelm@5219
    25
  type simpset
wenzelm@5219
    26
  type clasimpset
oheimb@4652
    27
  val addSIs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    28
  val addSEs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    29
  val addSDs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    30
  val addIs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    31
  val addEs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    32
  val addDs2	: clasimpset * thm list -> clasimpset
oheimb@4652
    33
  val addsimps2	: clasimpset * thm list -> clasimpset
oheimb@4652
    34
  val delsimps2	: clasimpset * thm list -> clasimpset
oheimb@4652
    35
  val addSss	: claset * simpset -> claset
oheimb@4652
    36
  val addss	: claset * simpset -> claset
oheimb@5483
    37
  val CLASIMPSET  :(clasimpset -> tactic) -> tactic
oheimb@5483
    38
  val CLASIMPSET' :(clasimpset -> 'a -> tactic) -> 'a -> tactic
oheimb@5483
    39
  val clarsimp_tac: clasimpset -> int -> tactic
oheimb@5483
    40
  val Clarsimp_tac:               int -> tactic
oheimb@5483
    41
  val mk_auto_tac : clasimpset -> int -> int -> tactic
oheimb@5483
    42
  val auto_tac	  : clasimpset -> tactic
oheimb@5483
    43
  val Auto_tac	  : tactic
oheimb@5483
    44
  val auto	  : unit -> unit
oheimb@5483
    45
  val force_tac	  : clasimpset  -> int -> tactic
oheimb@5483
    46
  val Force_tac	  : int -> tactic
oheimb@5483
    47
  val force	  : int -> unit
wenzelm@5926
    48
  val setup	  : (theory -> theory) list
oheimb@4652
    49
end;
oheimb@4652
    50
wenzelm@5219
    51
functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP =
oheimb@4652
    52
struct
oheimb@4652
    53
wenzelm@5219
    54
open Data;
wenzelm@5219
    55
wenzelm@5219
    56
type claset = Classical.claset;
wenzelm@5219
    57
type simpset = Simplifier.simpset;
wenzelm@5219
    58
type clasimpset = claset * simpset;
wenzelm@5219
    59
wenzelm@5219
    60
wenzelm@5219
    61
(* clasimpset operations *)
wenzelm@5219
    62
wenzelm@5219
    63
(*this interface for updating a clasimpset is rudimentary and just for
wenzelm@5219
    64
  convenience for the most common cases*)
wenzelm@5219
    65
wenzelm@5219
    66
fun pair_upd1 f ((a,b),x) = (f(a,x), b);
wenzelm@5219
    67
fun pair_upd2 f ((a,b),x) = (a, f(b,x));
wenzelm@5219
    68
wenzelm@5219
    69
fun op addSIs2   arg = pair_upd1 Classical.addSIs arg;
wenzelm@5219
    70
fun op addSEs2   arg = pair_upd1 Classical.addSEs arg;
wenzelm@5219
    71
fun op addSDs2   arg = pair_upd1 Classical.addSDs arg;
wenzelm@5219
    72
fun op addIs2    arg = pair_upd1 Classical.addIs arg;
wenzelm@5219
    73
fun op addEs2    arg = pair_upd1 Classical.addEs arg;
wenzelm@5219
    74
fun op addDs2    arg = pair_upd1 Classical.addDs arg;
wenzelm@5219
    75
fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
wenzelm@5219
    76
fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg;
oheimb@4652
    77
oheimb@4652
    78
(*Add a simpset to a classical set!*)
oheimb@4652
    79
(*Caution: only one simpset added can be added by each of addSss and addss*)
paulson@5567
    80
fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
oheimb@5554
    81
			    CHANGED o Simplifier.safe_asm_full_simp_tac ss));
paulson@5567
    82
fun cs addss  ss = Classical.addbefore  (cs, ("asm_full_simp_tac", 
oheimb@5554
    83
			    CHANGED o Simplifier.asm_full_simp_tac ss));
oheimb@4652
    84
wenzelm@5219
    85
(* tacticals *)
wenzelm@4888
    86
wenzelm@5219
    87
fun CLASIMPSET tacf state =
wenzelm@5219
    88
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
wenzelm@4888
    89
wenzelm@5219
    90
fun CLASIMPSET' tacf i state =
wenzelm@5219
    91
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
oheimb@4652
    92
oheimb@4652
    93
oheimb@7957
    94
fun clarsimp_tac (cs, ss) = Simplifier.safe_asm_full_simp_tac ss THEN_ALL_NEW
oheimb@5483
    95
			    Classical.clarify_tac (cs addSss ss);
oheimb@5483
    96
fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
oheimb@5483
    97
oheimb@5483
    98
wenzelm@5219
    99
(* auto_tac *)
oheimb@4652
   100
wenzelm@5219
   101
fun blast_depth_tac cs m i thm =
oheimb@5554
   102
    Blast.depth_tac cs m i thm 
oheimb@5554
   103
      handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
oheimb@5756
   104
 
wenzelm@5219
   105
(* a variant of depth_tac that avoids interference of the simplifier 
wenzelm@5219
   106
   with dup_step_tac when they are combined by auto_tac *)
oheimb@5756
   107
local
oheimb@5756
   108
fun slow_step_tac' cs = Classical.appWrappers cs 
oheimb@5756
   109
	(Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs);
oheimb@5756
   110
in fun nodup_depth_tac cs m i state = SELECT_GOAL 
oheimb@5756
   111
   (Classical.safe_steps_tac cs 1 THEN_ELSE 
oheimb@5756
   112
	(DEPTH_SOLVE (nodup_depth_tac cs m 1),
oheimb@5756
   113
	 Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac
oheimb@5756
   114
	     (slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1))
oheimb@5756
   115
        )) i state;
oheimb@5756
   116
end;
oheimb@4652
   117
oheimb@4652
   118
(*Designed to be idempotent, except if best_tac instantiates variables
oheimb@4652
   119
  in some of the subgoals*)
oheimb@4652
   120
fun mk_auto_tac (cs, ss) m n =
wenzelm@5219
   121
    let val cs' = cs addss ss
oheimb@4652
   122
        val maintac = 
oheimb@5756
   123
          blast_depth_tac cs m		     (* fast but can't use wrappers *)
oheimb@4652
   124
          ORELSE'
oheimb@5756
   125
          (CHANGED o nodup_depth_tac cs' n); (* slower but more general *)
wenzelm@5219
   126
    in  EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
oheimb@5525
   127
	       TRY (Classical.safe_tac cs),
oheimb@4652
   128
	       REPEAT (FIRSTGOAL maintac),
wenzelm@5219
   129
               TRY (Classical.safe_tac (cs addSss ss)),
oheimb@4652
   130
	       prune_params_tac] 
oheimb@4652
   131
    end;
oheimb@4652
   132
oheimb@4652
   133
fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
oheimb@4652
   134
wenzelm@5219
   135
fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st;
oheimb@4652
   136
oheimb@4652
   137
fun auto () = by Auto_tac;
oheimb@4652
   138
wenzelm@5219
   139
wenzelm@5219
   140
(* force_tac *)
wenzelm@5219
   141
oheimb@4659
   142
(* aimed to solve the given subgoal totally, using whatever tools possible *)
oheimb@4717
   143
fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
wenzelm@5219
   144
	Classical.clarify_tac cs' 1,
wenzelm@5219
   145
	IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
wenzelm@5219
   146
	ALLGOALS (Classical.best_tac cs')]) end;
wenzelm@5219
   147
fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i;
oheimb@4717
   148
fun force i = by (Force_tac i);
oheimb@4659
   149
wenzelm@5219
   150
wenzelm@5926
   151
(* methods *)
wenzelm@5926
   152
wenzelm@7153
   153
fun get_local_clasimpset ctxt =
wenzelm@7153
   154
  (Classical.get_local_claset ctxt, Simplifier.get_local_simpset ctxt);
wenzelm@5926
   155
wenzelm@8469
   156
val clasimp_modifiers =
wenzelm@8469
   157
  Simplifier.simp_modifiers @ Splitter.split_modifiers @ Classical.cla_modifiers;
wenzelm@5926
   158
wenzelm@7559
   159
fun clasimp_meth tac prems ctxt = Method.METHOD (fn facts =>
wenzelm@7559
   160
  ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_clasimpset ctxt));
wenzelm@7132
   161
wenzelm@7559
   162
fun clasimp_meth' tac prems ctxt = Method.METHOD (fn facts =>
wenzelm@8168
   163
  HEADGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_clasimpset ctxt)));
wenzelm@5926
   164
wenzelm@7559
   165
val clasimp_method = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth;
wenzelm@7559
   166
val clasimp_method' = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth';
wenzelm@5926
   167
wenzelm@5926
   168
wenzelm@5926
   169
val setup =
wenzelm@5926
   170
 [Method.add_methods
wenzelm@7437
   171
   [("clarsimp_tac", clasimp_method' clarsimp_tac, "clarsimp (improper!)"),
wenzelm@7394
   172
    ("auto", clasimp_method (CHANGED o auto_tac), "auto"),
wenzelm@7272
   173
    ("force", clasimp_method' force_tac, "force")]];
wenzelm@7272
   174
    
wenzelm@5926
   175
wenzelm@5926
   176
oheimb@4652
   177
end;