src/Provers/classical.ML
author paulson
Fri Mar 15 18:47:05 1996 +0100 (1996-03-15)
changeset 1587 e7d8a4957bac
parent 1524 524879632d88
child 1711 c06d01f75764
permissions -rw-r--r--
Now provides astar versions (thanks to Norbert Voelker)
clasohm@0
     1
(*  Title: 	Provers/classical
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Theorem prover for classical reasoning, including predicate calculus, set
clasohm@0
     7
theory, etc.
clasohm@0
     8
clasohm@0
     9
Rules must be classified as intr, elim, safe, hazardous.
clasohm@0
    10
clasohm@0
    11
A rule is unsafe unless it can be applied blindly without harmful results.
clasohm@0
    12
For a rule to be safe, its premises and conclusion should be logically
clasohm@0
    13
equivalent.  There should be no variables in the premises that are not in
clasohm@0
    14
the conclusion.
clasohm@0
    15
*)
clasohm@0
    16
lcp@982
    17
infix 1 THEN_MAYBE;
lcp@982
    18
clasohm@0
    19
signature CLASSICAL_DATA =
clasohm@0
    20
  sig
lcp@681
    21
  val mp	: thm    	(* [| P-->Q;  P |] ==> Q *)
lcp@681
    22
  val not_elim	: thm		(* [| ~P;  P |] ==> R *)
lcp@681
    23
  val classical	: thm		(* (~P ==> P) ==> P *)
lcp@681
    24
  val sizef 	: thm -> int	(* size function for BEST_FIRST *)
clasohm@0
    25
  val hyp_subst_tacs: (int -> tactic) list
clasohm@0
    26
  end;
clasohm@0
    27
clasohm@0
    28
(*Higher precedence than := facilitates use of references*)
lcp@982
    29
infix 4 addSIs addSEs addSDs addIs addEs addDs 
lcp@982
    30
        setwrapper compwrapper addbefore addafter;
clasohm@0
    31
clasohm@0
    32
clasohm@0
    33
signature CLASSICAL =
clasohm@0
    34
  sig
clasohm@0
    35
  type claset
lcp@1073
    36
  type netpair
lcp@681
    37
  val empty_cs		: claset
lcp@681
    38
  val addDs 		: claset * thm list -> claset
lcp@681
    39
  val addEs 		: claset * thm list -> claset
lcp@681
    40
  val addIs 		: claset * thm list -> claset
lcp@681
    41
  val addSDs		: claset * thm list -> claset
lcp@681
    42
  val addSEs		: claset * thm list -> claset
lcp@681
    43
  val addSIs		: claset * thm list -> claset
lcp@982
    44
  val setwrapper 	: claset * (tactic->tactic) -> claset
lcp@982
    45
  val compwrapper 	: claset * (tactic->tactic) -> claset
lcp@982
    46
  val addbefore 	: claset * tactic -> claset
lcp@982
    47
  val addafter 		: claset * tactic -> claset
lcp@982
    48
lcp@681
    49
  val print_cs		: claset -> unit
lcp@1073
    50
  val rep_claset	: 
lcp@1073
    51
      claset -> {safeIs: thm list, safeEs: thm list, 
lcp@1073
    52
		 hazIs: thm list, hazEs: thm list,
lcp@1073
    53
		 wrapper: tactic -> tactic,
lcp@1073
    54
		 safe0_netpair: netpair, safep_netpair: netpair,
lcp@1073
    55
		 haz_netpair: netpair, dup_netpair: netpair}
lcp@982
    56
  val getwrapper	: claset -> tactic -> tactic
lcp@982
    57
  val THEN_MAYBE	: tactic * tactic -> tactic
lcp@982
    58
paulson@1587
    59
  val fast_tac 		: claset -> int -> tactic
paulson@1587
    60
  val slow_tac 		: claset -> int -> tactic
paulson@1587
    61
  val weight_ASTAR	: int ref
paulson@1587
    62
  val astar_tac		: claset -> int -> tactic
paulson@1587
    63
  val slow_astar_tac 	: claset -> int -> tactic
lcp@681
    64
  val best_tac 		: claset -> int -> tactic
paulson@1587
    65
  val slow_best_tac 	: claset -> int -> tactic
lcp@681
    66
  val depth_tac		: claset -> int -> int -> tactic
lcp@681
    67
  val deepen_tac	: claset -> int -> int -> tactic
paulson@1587
    68
paulson@1587
    69
  val contr_tac 	: int -> tactic
lcp@681
    70
  val dup_elim		: thm -> thm
lcp@681
    71
  val dup_intr		: thm -> thm
lcp@681
    72
  val dup_step_tac	: claset -> int -> tactic
lcp@681
    73
  val eq_mp_tac		: int -> tactic
lcp@681
    74
  val haz_step_tac 	: claset -> int -> tactic
lcp@681
    75
  val joinrules 	: thm list * thm list -> (bool * thm) list
lcp@681
    76
  val mp_tac		: int -> tactic
lcp@681
    77
  val safe_tac 		: claset -> tactic
lcp@681
    78
  val safe_step_tac 	: claset -> int -> tactic
lcp@681
    79
  val step_tac 		: claset -> int -> tactic
lcp@681
    80
  val swap		: thm                 (* ~P ==> (~Q ==> P) ==> Q *)
lcp@681
    81
  val swapify 		: thm list -> thm list
lcp@681
    82
  val swap_res_tac 	: thm list -> int -> tactic
lcp@681
    83
  val inst_step_tac 	: claset -> int -> tactic
lcp@747
    84
  val inst0_step_tac 	: claset -> int -> tactic
lcp@747
    85
  val instp_step_tac 	: claset -> int -> tactic
clasohm@0
    86
  end;
clasohm@0
    87
clasohm@0
    88
clasohm@0
    89
functor ClassicalFun(Data: CLASSICAL_DATA): CLASSICAL = 
clasohm@0
    90
struct
clasohm@0
    91
clasohm@0
    92
local open Data in
clasohm@0
    93
clasohm@0
    94
(** Useful tactics for classical reasoning **)
clasohm@0
    95
paulson@1524
    96
val imp_elim = (*cannot use bind_thm within a structure!*)
paulson@1524
    97
  store_thm ("imp_elim", make_elim mp);
clasohm@0
    98
clasohm@0
    99
(*Solve goal that assumes both P and ~P. *)
clasohm@0
   100
val contr_tac = eresolve_tac [not_elim]  THEN'  assume_tac;
clasohm@0
   101
lcp@681
   102
(*Finds P-->Q and P in the assumptions, replaces implication by Q.
lcp@681
   103
  Could do the same thing for P<->Q and P... *)
lcp@681
   104
fun mp_tac i = eresolve_tac [not_elim, imp_elim] i  THEN  assume_tac i;
clasohm@0
   105
clasohm@0
   106
(*Like mp_tac but instantiates no variables*)
lcp@681
   107
fun eq_mp_tac i = ematch_tac [not_elim, imp_elim] i  THEN  eq_assume_tac i;
lcp@681
   108
paulson@1524
   109
val swap =
paulson@1524
   110
  store_thm ("swap", rule_by_tactic (etac thin_rl 1) (not_elim RS classical));
clasohm@0
   111
clasohm@0
   112
(*Creates rules to eliminate ~A, from rules to introduce A*)
clasohm@0
   113
fun swapify intrs = intrs RLN (2, [swap]);
clasohm@0
   114
clasohm@0
   115
(*Uses introduction rules in the normal way, or on negated assumptions,
clasohm@0
   116
  trying rules in order. *)
clasohm@0
   117
fun swap_res_tac rls = 
lcp@54
   118
    let fun addrl (rl,brls) = (false, rl) :: (true, rl RSN (2,swap)) :: brls
lcp@54
   119
    in  assume_tac 	ORELSE' 
lcp@54
   120
	contr_tac 	ORELSE' 
lcp@54
   121
        biresolve_tac (foldr addrl (rls,[]))
clasohm@0
   122
    end;
clasohm@0
   123
lcp@681
   124
(*Duplication of hazardous rules, for complete provers*)
lcp@681
   125
fun dup_intr th = standard (th RS classical);
lcp@681
   126
lcp@681
   127
fun dup_elim th = th RSN (2, revcut_rl) |> assumption 2 |> Sequence.hd |> 
lcp@681
   128
                  rule_by_tactic (TRYALL (etac revcut_rl));
clasohm@0
   129
lcp@1073
   130
clasohm@0
   131
(*** Classical rule sets ***)
clasohm@0
   132
clasohm@0
   133
type netpair = (int*(bool*thm)) Net.net * (int*(bool*thm)) Net.net;
clasohm@0
   134
clasohm@0
   135
datatype claset =
lcp@982
   136
  CS of {safeIs		: thm list,		(*safe introduction rules*)
lcp@982
   137
	 safeEs		: thm list,		(*safe elimination rules*)
lcp@982
   138
	 hazIs		: thm list,		(*unsafe introduction rules*)
lcp@982
   139
	 hazEs		: thm list,		(*unsafe elimination rules*)
lcp@982
   140
	 wrapper	: tactic->tactic,	(*for transforming step_tac*)
lcp@982
   141
	 safe0_netpair	: netpair,		(*nets for trivial cases*)
lcp@982
   142
	 safep_netpair	: netpair,		(*nets for >0 subgoals*)
lcp@982
   143
	 haz_netpair  	: netpair,		(*nets for unsafe rules*)
lcp@982
   144
	 dup_netpair	: netpair};		(*nets for duplication*)
clasohm@0
   145
lcp@1073
   146
(*Desired invariants are
lcp@681
   147
	safe0_netpair = build safe0_brls,
lcp@681
   148
	safep_netpair = build safep_brls,
lcp@681
   149
	haz_netpair = build (joinrules(hazIs, hazEs)),
lcp@681
   150
	dup_netpair = build (joinrules(map dup_intr hazIs, 
lcp@681
   151
				       map dup_elim hazEs))}
lcp@1073
   152
lcp@1073
   153
where build = build_netpair(Net.empty,Net.empty), 
lcp@1073
   154
      safe0_brls contains all brules that solve the subgoal, and
lcp@1073
   155
      safep_brls contains all brules that generate 1 or more new subgoals.
lcp@1073
   156
Nets must be built incrementally, to save space and time.
lcp@1073
   157
*)
clasohm@0
   158
lcp@1073
   159
val empty_cs = 
lcp@1073
   160
  CS{safeIs	= [],
lcp@1073
   161
     safeEs	= [],
lcp@1073
   162
     hazIs	= [],
lcp@1073
   163
     hazEs	= [],
lcp@1073
   164
     wrapper 	= I,
lcp@1073
   165
     safe0_netpair = (Net.empty,Net.empty),
lcp@1073
   166
     safep_netpair = (Net.empty,Net.empty),
lcp@1073
   167
     haz_netpair   = (Net.empty,Net.empty),
lcp@1073
   168
     dup_netpair   = (Net.empty,Net.empty)};
clasohm@0
   169
clasohm@0
   170
fun print_cs (CS{safeIs,safeEs,hazIs,hazEs,...}) =
lcp@1073
   171
 (writeln"Introduction rules";  	prths hazIs;
lcp@1073
   172
  writeln"Safe introduction rules";  	prths safeIs;
lcp@1073
   173
  writeln"Elimination rules";  		prths hazEs;
lcp@1073
   174
  writeln"Safe elimination rules";  	prths safeEs;
clasohm@0
   175
  ());
clasohm@0
   176
lcp@1073
   177
fun rep_claset (CS args) = args;
lcp@1073
   178
lcp@1073
   179
fun getwrapper (CS{wrapper,...}) = wrapper;
lcp@1073
   180
lcp@1073
   181
lcp@1073
   182
(** Adding (un)safe introduction or elimination rules.
lcp@1073
   183
lcp@1073
   184
    In case of overlap, new rules are tried BEFORE old ones!!
lcp@1010
   185
**)
clasohm@0
   186
lcp@1073
   187
(*For use with biresolve_tac.  Combines intr rules with swap to handle negated
lcp@1073
   188
  assumptions.  Pairs elim rules with true. *)
lcp@1073
   189
fun joinrules (intrs,elims) =  
lcp@1073
   190
    (map (pair true) (elims @ swapify intrs)  @
lcp@1073
   191
     map (pair false) intrs);
lcp@1073
   192
lcp@1073
   193
(*Priority: prefer rules with fewest subgoals, 
paulson@1231
   194
  then rules added most recently (preferring the head of the list).*)
lcp@1073
   195
fun tag_brls k [] = []
lcp@1073
   196
  | tag_brls k (brl::brls) =
lcp@1073
   197
      (1000000*subgoals_of_brl brl + k, brl) :: 
lcp@1073
   198
      tag_brls (k+1) brls;
lcp@1073
   199
lcp@1073
   200
fun insert_tagged_list kbrls np = foldr insert_tagged_brl (kbrls, np);
lcp@1073
   201
lcp@1073
   202
(*Insert into netpair that already has nI intr rules and nE elim rules.
lcp@1073
   203
  Count the intr rules double (to account for swapify).  Negate to give the
lcp@1073
   204
  new insertions the lowest priority.*)
lcp@1073
   205
fun insert (nI,nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules;
lcp@1073
   206
lcp@1073
   207
lcp@1073
   208
(** Safe rules **)
lcp@982
   209
lcp@1073
   210
fun (CS{safeIs, safeEs, hazIs, hazEs, wrapper, 
lcp@1073
   211
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) 
lcp@1073
   212
    addSIs  ths  =
lcp@1073
   213
  let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
lcp@1073
   214
          take_prefix (fn rl => nprems_of rl=0) ths
lcp@1073
   215
      val nI = length safeIs + length ths
lcp@1073
   216
      and nE = length safeEs
lcp@1073
   217
  in CS{safeIs	= ths@safeIs,
lcp@1073
   218
        safe0_netpair = insert (nI,nE) (safe0_rls, []) safe0_netpair,
lcp@1073
   219
	safep_netpair = insert (nI,nE) (safep_rls, []) safep_netpair,
lcp@1073
   220
	safeEs	= safeEs,
lcp@1073
   221
	hazIs	= hazIs,
lcp@1073
   222
	hazEs	= hazEs,
lcp@1073
   223
	wrapper = wrapper,
lcp@1073
   224
	haz_netpair = haz_netpair,
lcp@1073
   225
	dup_netpair = dup_netpair}
lcp@1073
   226
  end;
lcp@1073
   227
lcp@1073
   228
fun (CS{safeIs, safeEs, hazIs, hazEs, wrapper, 
lcp@1073
   229
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) 
lcp@1073
   230
    addSEs  ths  =
lcp@1073
   231
  let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
lcp@1073
   232
          take_prefix (fn rl => nprems_of rl=1) ths
lcp@1073
   233
      val nI = length safeIs
lcp@1073
   234
      and nE = length safeEs + length ths
lcp@1073
   235
  in 
lcp@1073
   236
     CS{safeEs	= ths@safeEs,
lcp@1073
   237
        safe0_netpair = insert (nI,nE) ([], safe0_rls) safe0_netpair,
lcp@1073
   238
	safep_netpair = insert (nI,nE) ([], safep_rls) safep_netpair,
lcp@1073
   239
	safeIs	= safeIs,
lcp@1073
   240
	hazIs	= hazIs,
lcp@1073
   241
	hazEs	= hazEs,
lcp@1073
   242
	wrapper = wrapper,
lcp@1073
   243
	haz_netpair = haz_netpair,
lcp@1073
   244
	dup_netpair = dup_netpair}
lcp@1073
   245
  end;
clasohm@0
   246
clasohm@0
   247
fun cs addSDs ths = cs addSEs (map make_elim ths);
clasohm@0
   248
lcp@1073
   249
lcp@1073
   250
(** Hazardous (unsafe) rules **)
clasohm@0
   251
lcp@1073
   252
fun (CS{safeIs, safeEs, hazIs, hazEs, wrapper, 
lcp@1073
   253
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) 
lcp@1073
   254
    addIs  ths  =
lcp@1073
   255
  let val nI = length hazIs + length ths
lcp@1073
   256
      and nE = length hazEs
lcp@1073
   257
  in 
lcp@1073
   258
     CS{hazIs	= ths@hazIs,
lcp@1073
   259
	haz_netpair = insert (nI,nE) (ths, []) haz_netpair,
lcp@1073
   260
	dup_netpair = insert (nI,nE) (map dup_intr ths, []) dup_netpair,
lcp@1073
   261
	safeIs 	= safeIs, 
lcp@1073
   262
	safeEs	= safeEs,
lcp@1073
   263
	hazEs	= hazEs,
lcp@1073
   264
	wrapper 	= wrapper,
lcp@1073
   265
	safe0_netpair = safe0_netpair,
lcp@1073
   266
	safep_netpair = safep_netpair}
lcp@1073
   267
  end;
lcp@1073
   268
lcp@1073
   269
fun (CS{safeIs, safeEs, hazIs, hazEs, wrapper, 
lcp@1073
   270
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) 
lcp@1073
   271
    addEs  ths  =
lcp@1073
   272
  let val nI = length hazIs 
lcp@1073
   273
      and nE = length hazEs + length ths
lcp@1073
   274
  in 
lcp@1073
   275
     CS{hazEs	= ths@hazEs,
lcp@1073
   276
	haz_netpair = insert (nI,nE) ([], ths) haz_netpair,
lcp@1073
   277
	dup_netpair = insert (nI,nE) ([], map dup_elim ths) dup_netpair,
lcp@1073
   278
	safeIs	= safeIs, 
lcp@1073
   279
	safeEs	= safeEs,
lcp@1073
   280
	hazIs	= hazIs,
lcp@1073
   281
	wrapper	= wrapper,
lcp@1073
   282
	safe0_netpair = safe0_netpair,
lcp@1073
   283
	safep_netpair = safep_netpair}
lcp@1073
   284
  end;
clasohm@0
   285
clasohm@0
   286
fun cs addDs ths = cs addEs (map make_elim ths);
clasohm@0
   287
lcp@1073
   288
lcp@982
   289
(** Setting or modifying the wrapper tactical **)
lcp@982
   290
lcp@982
   291
(*Set a new wrapper*)
lcp@1073
   292
fun (CS{safeIs, safeEs, hazIs, hazEs, 
lcp@1073
   293
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair, ...}) 
lcp@1073
   294
    setwrapper new_wrapper  =
lcp@1073
   295
  CS{wrapper 	= new_wrapper,
lcp@1073
   296
     safeIs	= safeIs,
lcp@1073
   297
     safeEs	= safeEs,
lcp@1073
   298
     hazIs	= hazIs,
lcp@1073
   299
     hazEs	= hazEs,
lcp@1073
   300
     safe0_netpair = safe0_netpair,
lcp@1073
   301
     safep_netpair = safep_netpair,
lcp@1073
   302
     haz_netpair = haz_netpair,
lcp@1073
   303
     dup_netpair = dup_netpair};
lcp@982
   304
lcp@982
   305
(*Compose a tactical with the existing wrapper*)
lcp@982
   306
fun cs compwrapper wrapper' = cs setwrapper (wrapper' o getwrapper cs);
lcp@982
   307
lcp@982
   308
(*Execute tac1, but only execute tac2 if there are at least as many subgoals
lcp@982
   309
  as before.  This ensures that tac2 is only applied to an outcome of tac1.*)
lcp@982
   310
fun tac1 THEN_MAYBE tac2 = 
lcp@982
   311
  STATE (fn state =>
lcp@982
   312
	 tac1  THEN  
lcp@982
   313
	 COND (has_fewer_prems (nprems_of state)) all_tac tac2);
lcp@982
   314
lcp@982
   315
(*Cause a tactic to be executed before/after the step tactic*)
lcp@982
   316
fun cs addbefore tac2 = cs compwrapper (fn tac1 => tac2 THEN_MAYBE tac1);
lcp@982
   317
fun cs addafter tac2  = cs compwrapper (fn tac1 => tac1 THEN_MAYBE tac2);
lcp@982
   318
lcp@982
   319
lcp@982
   320
clasohm@0
   321
(*** Simple tactics for theorem proving ***)
clasohm@0
   322
clasohm@0
   323
(*Attack subgoals using safe inferences -- matching, not resolution*)
clasohm@0
   324
fun safe_step_tac (CS{safe0_netpair,safep_netpair,...}) = 
clasohm@0
   325
  FIRST' [eq_assume_tac,
clasohm@0
   326
	  eq_mp_tac,
clasohm@0
   327
	  bimatch_from_nets_tac safe0_netpair,
clasohm@0
   328
	  FIRST' hyp_subst_tacs,
clasohm@0
   329
	  bimatch_from_nets_tac safep_netpair] ;
clasohm@0
   330
clasohm@0
   331
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*)
lcp@747
   332
fun safe_tac cs = REPEAT_DETERM_FIRST (safe_step_tac cs);
lcp@747
   333
lcp@747
   334
(*But these unsafe steps at least solve a subgoal!*)
lcp@747
   335
fun inst0_step_tac (CS{safe0_netpair,safep_netpair,...}) =
lcp@747
   336
  assume_tac 			  APPEND' 
lcp@747
   337
  contr_tac 			  APPEND' 
lcp@747
   338
  biresolve_from_nets_tac safe0_netpair;
lcp@747
   339
lcp@747
   340
(*These are much worse since they could generate more and more subgoals*)
lcp@747
   341
fun instp_step_tac (CS{safep_netpair,...}) =
lcp@747
   342
  biresolve_from_nets_tac safep_netpair;
clasohm@0
   343
clasohm@0
   344
(*These steps could instantiate variables and are therefore unsafe.*)
lcp@747
   345
fun inst_step_tac cs = inst0_step_tac cs APPEND' instp_step_tac cs;
clasohm@0
   346
lcp@982
   347
fun haz_step_tac (CS{haz_netpair,...}) = 
lcp@681
   348
  biresolve_from_nets_tac haz_netpair;
lcp@681
   349
clasohm@0
   350
(*Single step for the prover.  FAILS unless it makes progress. *)
lcp@681
   351
fun step_tac cs i = 
lcp@982
   352
  getwrapper cs 
lcp@982
   353
    (FIRST [safe_tac cs, inst_step_tac cs i, haz_step_tac cs i]);
clasohm@0
   354
clasohm@0
   355
(*Using a "safe" rule to instantiate variables is unsafe.  This tactic
clasohm@0
   356
  allows backtracking from "safe" rules to "unsafe" rules here.*)
lcp@681
   357
fun slow_step_tac cs i = 
lcp@982
   358
  getwrapper cs 
lcp@982
   359
    (safe_tac cs ORELSE (inst_step_tac cs i APPEND haz_step_tac cs i));
clasohm@0
   360
clasohm@0
   361
(*** The following tactics all fail unless they solve one goal ***)
clasohm@0
   362
clasohm@0
   363
(*Dumb but fast*)
clasohm@0
   364
fun fast_tac cs = SELECT_GOAL (DEPTH_SOLVE (step_tac cs 1));
clasohm@0
   365
clasohm@0
   366
(*Slower but smarter than fast_tac*)
clasohm@0
   367
fun best_tac cs = 
clasohm@0
   368
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (step_tac cs 1));
clasohm@0
   369
clasohm@0
   370
fun slow_tac cs = SELECT_GOAL (DEPTH_SOLVE (slow_step_tac cs 1));
clasohm@0
   371
clasohm@0
   372
fun slow_best_tac cs = 
clasohm@0
   373
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (slow_step_tac cs 1));
clasohm@0
   374
lcp@681
   375
paulson@1587
   376
(**ASTAR with weight weight_ASTAR, by Norbert Voelker*) 
paulson@1587
   377
val weight_ASTAR = ref 5; 
paulson@1587
   378
paulson@1587
   379
fun astar_tac cs = 
paulson@1587
   380
  SELECT_GOAL ( ASTAR (has_fewer_prems 1
paulson@1587
   381
	      , fn level =>(fn thm =>size_of_thm thm + !weight_ASTAR *level)) 
paulson@1587
   382
	      (step_tac cs 1));
paulson@1587
   383
paulson@1587
   384
fun slow_astar_tac cs = 
paulson@1587
   385
  SELECT_GOAL ( ASTAR (has_fewer_prems 1
paulson@1587
   386
	      , fn level =>(fn thm =>size_of_thm thm + !weight_ASTAR *level)) 
paulson@1587
   387
	      (slow_step_tac cs 1));
paulson@1587
   388
lcp@982
   389
(*** Complete tactic, loosely based upon LeanTaP.  This tactic is the outcome
lcp@747
   390
  of much experimentation!  Changing APPEND to ORELSE below would prove
lcp@747
   391
  easy theorems faster, but loses completeness -- and many of the harder
lcp@747
   392
  theorems such as 43. ***)
lcp@681
   393
lcp@747
   394
(*Non-deterministic!  Could always expand the first unsafe connective.
lcp@747
   395
  That's hard to implement and did not perform better in experiments, due to
lcp@747
   396
  greater search depth required.*)
lcp@681
   397
fun dup_step_tac (cs as (CS{dup_netpair,...})) = 
lcp@681
   398
  biresolve_from_nets_tac dup_netpair;
lcp@681
   399
lcp@747
   400
(*Searching to depth m.*)
lcp@747
   401
fun depth_tac cs m i = STATE(fn state => 
lcp@747
   402
  SELECT_GOAL 
lcp@747
   403
    (REPEAT_DETERM1 (safe_step_tac cs 1) THEN_ELSE
lcp@747
   404
     (DEPTH_SOLVE (depth_tac cs m 1),
lcp@747
   405
      inst0_step_tac cs 1  APPEND
lcp@747
   406
      COND (K(m=0)) no_tac
lcp@747
   407
        ((instp_step_tac cs 1 APPEND dup_step_tac cs 1)
lcp@747
   408
	 THEN DEPTH_SOLVE (depth_tac cs (m-1) 1))))
lcp@747
   409
  i);
lcp@747
   410
lcp@747
   411
(*Iterative deepening tactical.  Allows us to "deepen" any search tactic*)
lcp@747
   412
fun DEEPEN tacf m i = STATE(fn state => 
lcp@747
   413
   if has_fewer_prems i state then no_tac
lcp@747
   414
   else (writeln ("Depth = " ^ string_of_int m);
lcp@747
   415
	 tacf m i  ORELSE  DEEPEN tacf (m+2) i));
lcp@747
   416
lcp@747
   417
fun safe_depth_tac cs m = 
lcp@681
   418
  SUBGOAL 
lcp@681
   419
    (fn (prem,i) =>
lcp@681
   420
      let val deti =
lcp@681
   421
	  (*No Vars in the goal?  No need to backtrack between goals.*)
lcp@681
   422
	  case term_vars prem of
lcp@681
   423
	      []	=> DETERM 
lcp@681
   424
	    | _::_	=> I
lcp@681
   425
      in  SELECT_GOAL (TRY (safe_tac cs) THEN 
lcp@747
   426
		       DEPTH_SOLVE (deti (depth_tac cs m 1))) i
lcp@747
   427
      end);
lcp@681
   428
lcp@747
   429
fun deepen_tac cs = DEEPEN (safe_depth_tac cs);
lcp@681
   430
clasohm@0
   431
end; 
clasohm@0
   432
end;