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