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