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