src/Provers/classical.ML
author wenzelm
Mon Nov 03 11:56:36 1997 +0100 (1997-11-03 ago)
changeset 4079 9df5e4f22d96
parent 4066 7b508ac609f7
child 4124 1af16493c57f
permissions -rw-r--r--
new implicit claset mechanism based on Sign.sg anytype data;
tuned warnings;
wenzelm@4079
     1
(*  Title: 	Provers/classical.ML
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
wenzelm@4079
     9
Rules must be classified as intr, elim, safe, hazardous (unsafe).
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
wenzelm@4079
    17
(*higher precedence than := facilitates use of references*)
wenzelm@4079
    18
infix 4 addSIs addSEs addSDs addIs addEs addDs delrules
wenzelm@4079
    19
  setSWrapper compSWrapper setWrapper compWrapper
wenzelm@4079
    20
  addSbefore addSaltern addbefore addaltern;
wenzelm@4079
    21
wenzelm@4079
    22
wenzelm@4079
    23
(*should be a type abbreviation in signature CLASSICAL*)
wenzelm@4079
    24
type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net;
wenzelm@4079
    25
wenzelm@4079
    26
signature CLASET_THY_DATA =
wenzelm@4079
    27
sig
wenzelm@4079
    28
  val clasetK: string
wenzelm@4079
    29
  exception ClasetData of exn ref
wenzelm@4079
    30
  val thy_data: string * (exn * (exn -> exn) * (exn * exn -> exn) * (exn -> unit))
wenzelm@4079
    31
  val fix_methods: exn * (exn -> exn) * (exn * exn -> exn) * (exn -> unit) -> unit
wenzelm@4079
    32
end;
paulson@2868
    33
clasohm@0
    34
signature CLASSICAL_DATA =
wenzelm@4079
    35
sig
lcp@681
    36
  val mp	: thm    	(* [| P-->Q;  P |] ==> Q *)
lcp@681
    37
  val not_elim	: thm		(* [| ~P;  P |] ==> R *)
lcp@681
    38
  val classical	: thm		(* (~P ==> P) ==> P *)
lcp@681
    39
  val sizef 	: thm -> int	(* size function for BEST_FIRST *)
clasohm@0
    40
  val hyp_subst_tacs: (int -> tactic) list
wenzelm@4079
    41
end;
clasohm@0
    42
clasohm@0
    43
signature CLASSICAL =
wenzelm@4079
    44
sig
clasohm@0
    45
  type claset
wenzelm@4079
    46
  val empty_cs: claset
wenzelm@4079
    47
  val print_cs: claset -> unit
wenzelm@4079
    48
  val rep_claset:
wenzelm@4079
    49
    claset -> {safeIs: thm list, safeEs: thm list,
wenzelm@4079
    50
		 hazIs: thm list, hazEs: thm list,
wenzelm@4079
    51
		 uwrapper: (int -> tactic) -> (int -> tactic),
wenzelm@4079
    52
		 swrapper: (int -> tactic) -> (int -> tactic),
wenzelm@4079
    53
		 safe0_netpair: netpair, safep_netpair: netpair,
wenzelm@4079
    54
		 haz_netpair: netpair, dup_netpair: netpair}
paulson@1711
    55
  val merge_cs		: claset * claset -> claset
lcp@681
    56
  val addDs 		: claset * thm list -> claset
lcp@681
    57
  val addEs 		: claset * thm list -> claset
lcp@681
    58
  val addIs 		: claset * thm list -> claset
lcp@681
    59
  val addSDs		: claset * thm list -> claset
lcp@681
    60
  val addSEs		: claset * thm list -> claset
lcp@681
    61
  val addSIs		: claset * thm list -> claset
paulson@1800
    62
  val delrules		: claset * thm list -> claset
oheimb@2630
    63
  val setSWrapper 	: claset * ((int -> tactic) -> (int -> tactic)) ->claset
oheimb@2630
    64
  val compSWrapper 	: claset * ((int -> tactic) -> (int -> tactic)) ->claset
oheimb@2630
    65
  val setWrapper 	: claset * ((int -> tactic) -> (int -> tactic)) ->claset
oheimb@2630
    66
  val compWrapper 	: claset * ((int -> tactic) -> (int -> tactic)) ->claset
oheimb@2630
    67
  val addSbefore 	: claset * (int -> tactic) -> claset
oheimb@2630
    68
  val addSaltern 	: claset * (int -> tactic) -> claset
oheimb@2630
    69
  val addbefore 	: claset * (int -> tactic) -> claset
oheimb@2630
    70
  val addaltern	 	: claset * (int -> tactic) -> claset
oheimb@2630
    71
  val getWrapper	: claset -> (int -> tactic) -> (int -> tactic)
oheimb@2630
    72
  val getSWrapper	: claset -> (int -> tactic) -> (int -> tactic)
lcp@982
    73
wenzelm@4079
    74
  val claset_ref_of_sg: Sign.sg -> claset ref
wenzelm@4079
    75
  val claset_ref_of: theory -> claset ref
wenzelm@4079
    76
  val claset_of_sg: Sign.sg -> claset
wenzelm@4079
    77
  val claset_of: theory -> claset
wenzelm@4079
    78
  val CLASET: (claset -> tactic) -> tactic
wenzelm@4079
    79
  val CLASET': (claset -> 'a -> tactic) -> 'a -> tactic
wenzelm@4079
    80
  val claset: unit -> claset
wenzelm@4079
    81
  val claset_ref: unit -> claset ref
wenzelm@4079
    82
paulson@1587
    83
  val fast_tac 		: claset -> int -> tactic
paulson@1587
    84
  val slow_tac 		: claset -> int -> tactic
paulson@1587
    85
  val weight_ASTAR	: int ref
paulson@1587
    86
  val astar_tac		: claset -> int -> tactic
paulson@1587
    87
  val slow_astar_tac 	: claset -> int -> tactic
lcp@681
    88
  val best_tac 		: claset -> int -> tactic
paulson@1587
    89
  val slow_best_tac 	: claset -> int -> tactic
lcp@681
    90
  val depth_tac		: claset -> int -> int -> tactic
lcp@681
    91
  val deepen_tac	: claset -> int -> int -> tactic
paulson@1587
    92
paulson@1587
    93
  val contr_tac 	: int -> tactic
lcp@681
    94
  val dup_elim		: thm -> thm
lcp@681
    95
  val dup_intr		: thm -> thm
lcp@681
    96
  val dup_step_tac	: claset -> int -> tactic
lcp@681
    97
  val eq_mp_tac		: int -> tactic
lcp@681
    98
  val haz_step_tac 	: claset -> int -> tactic
lcp@681
    99
  val joinrules 	: thm list * thm list -> (bool * thm) list
lcp@681
   100
  val mp_tac		: int -> tactic
lcp@681
   101
  val safe_tac 		: claset -> tactic
lcp@681
   102
  val safe_step_tac 	: claset -> int -> tactic
paulson@3705
   103
  val clarify_tac 	: claset -> int -> tactic
paulson@3705
   104
  val clarify_step_tac 	: claset -> int -> tactic
lcp@681
   105
  val step_tac 		: claset -> int -> tactic
oheimb@2630
   106
  val slow_step_tac	: claset -> int -> tactic
lcp@681
   107
  val swap		: thm                 (* ~P ==> (~Q ==> P) ==> Q *)
lcp@681
   108
  val swapify 		: thm list -> thm list
lcp@681
   109
  val swap_res_tac 	: thm list -> int -> tactic
lcp@681
   110
  val inst_step_tac 	: claset -> int -> tactic
lcp@747
   111
  val inst0_step_tac 	: claset -> int -> tactic
lcp@747
   112
  val instp_step_tac 	: claset -> int -> tactic
berghofe@1724
   113
berghofe@1724
   114
  val AddDs 		: thm list -> unit
berghofe@1724
   115
  val AddEs 		: thm list -> unit
berghofe@1724
   116
  val AddIs 		: thm list -> unit
berghofe@1724
   117
  val AddSDs		: thm list -> unit
berghofe@1724
   118
  val AddSEs		: thm list -> unit
berghofe@1724
   119
  val AddSIs		: thm list -> unit
paulson@1807
   120
  val Delrules		: thm list -> unit
paulson@3727
   121
  val Safe_tac         	: tactic
paulson@1814
   122
  val Safe_step_tac	: int -> tactic
paulson@3705
   123
  val Clarify_tac 	: int -> tactic
paulson@3705
   124
  val Clarify_step_tac 	: int -> tactic
paulson@1800
   125
  val Step_tac 		: int -> tactic
berghofe@1724
   126
  val Fast_tac 		: int -> tactic
paulson@1800
   127
  val Best_tac 		: int -> tactic
paulson@2066
   128
  val Slow_tac 		: int -> tactic
paulson@2066
   129
  val Slow_best_tac     : int -> tactic
paulson@1800
   130
  val Deepen_tac	: int -> int -> tactic
wenzelm@4079
   131
end;
berghofe@1724
   132
wenzelm@4079
   133
wenzelm@4079
   134
structure ClasetThyData: CLASET_THY_DATA =
wenzelm@4079
   135
struct
wenzelm@4079
   136
wenzelm@4079
   137
(* data kind claset -- forward declaration *)
wenzelm@4079
   138
wenzelm@4079
   139
val clasetK = "claset";
wenzelm@4079
   140
exception ClasetData of exn ref;
wenzelm@4079
   141
wenzelm@4079
   142
local
wenzelm@4079
   143
  fun undef _ = raise Match;
wenzelm@4079
   144
wenzelm@4079
   145
  val empty_ref = ref ERROR;
wenzelm@4079
   146
  val prep_ext_fn = ref (undef: exn -> exn);
wenzelm@4079
   147
  val merge_fn = ref (undef: exn * exn -> exn);
wenzelm@4079
   148
  val print_fn = ref (undef: exn -> unit);
wenzelm@4079
   149
wenzelm@4079
   150
  val empty = ClasetData empty_ref;
wenzelm@4079
   151
  fun prep_ext exn = ! prep_ext_fn exn;
wenzelm@4079
   152
  fun merge exn = ! merge_fn exn;
wenzelm@4079
   153
  fun print exn = ! print_fn exn;
wenzelm@4079
   154
in
wenzelm@4079
   155
  val thy_data = (clasetK, (empty, prep_ext, merge, print));
wenzelm@4079
   156
  fun fix_methods (e, ext, mrg, prt) =
wenzelm@4079
   157
    (empty_ref := e; prep_ext_fn := ext; merge_fn := mrg; print_fn := prt);
wenzelm@4079
   158
end;
wenzelm@4079
   159
wenzelm@4079
   160
wenzelm@4079
   161
end;
clasohm@0
   162
clasohm@0
   163
clasohm@0
   164
functor ClassicalFun(Data: CLASSICAL_DATA): CLASSICAL = 
clasohm@0
   165
struct
clasohm@0
   166
wenzelm@4079
   167
local open ClasetThyData Data in
clasohm@0
   168
paulson@1800
   169
(*** Useful tactics for classical reasoning ***)
clasohm@0
   170
paulson@1524
   171
val imp_elim = (*cannot use bind_thm within a structure!*)
paulson@1524
   172
  store_thm ("imp_elim", make_elim mp);
clasohm@0
   173
clasohm@0
   174
(*Solve goal that assumes both P and ~P. *)
clasohm@0
   175
val contr_tac = eresolve_tac [not_elim]  THEN'  assume_tac;
clasohm@0
   176
lcp@681
   177
(*Finds P-->Q and P in the assumptions, replaces implication by Q.
lcp@681
   178
  Could do the same thing for P<->Q and P... *)
lcp@681
   179
fun mp_tac i = eresolve_tac [not_elim, imp_elim] i  THEN  assume_tac i;
clasohm@0
   180
clasohm@0
   181
(*Like mp_tac but instantiates no variables*)
lcp@681
   182
fun eq_mp_tac i = ematch_tac [not_elim, imp_elim] i  THEN  eq_assume_tac i;
lcp@681
   183
paulson@1524
   184
val swap =
paulson@1524
   185
  store_thm ("swap", rule_by_tactic (etac thin_rl 1) (not_elim RS classical));
clasohm@0
   186
clasohm@0
   187
(*Creates rules to eliminate ~A, from rules to introduce A*)
clasohm@0
   188
fun swapify intrs = intrs RLN (2, [swap]);
clasohm@0
   189
clasohm@0
   190
(*Uses introduction rules in the normal way, or on negated assumptions,
clasohm@0
   191
  trying rules in order. *)
clasohm@0
   192
fun swap_res_tac rls = 
lcp@54
   193
    let fun addrl (rl,brls) = (false, rl) :: (true, rl RSN (2,swap)) :: brls
lcp@54
   194
    in  assume_tac 	ORELSE' 
lcp@54
   195
	contr_tac 	ORELSE' 
lcp@54
   196
        biresolve_tac (foldr addrl (rls,[]))
clasohm@0
   197
    end;
clasohm@0
   198
lcp@681
   199
(*Duplication of hazardous rules, for complete provers*)
paulson@2689
   200
fun dup_intr th = zero_var_indexes (th RS classical);
lcp@681
   201
lcp@681
   202
fun dup_elim th = th RSN (2, revcut_rl) |> assumption 2 |> Sequence.hd |> 
lcp@681
   203
                  rule_by_tactic (TRYALL (etac revcut_rl));
clasohm@0
   204
lcp@1073
   205
paulson@1800
   206
(**** Classical rule sets ****)
clasohm@0
   207
clasohm@0
   208
datatype claset =
lcp@982
   209
  CS of {safeIs		: thm list,		(*safe introduction rules*)
lcp@982
   210
	 safeEs		: thm list,		(*safe elimination rules*)
lcp@982
   211
	 hazIs		: thm list,		(*unsafe introduction rules*)
lcp@982
   212
	 hazEs		: thm list,		(*unsafe elimination rules*)
oheimb@2630
   213
	 uwrapper	: (int -> tactic) ->
oheimb@2630
   214
			  (int -> tactic),	(*for transforming step_tac*)
oheimb@2630
   215
	 swrapper	: (int -> tactic) ->
oheimb@2630
   216
			  (int -> tactic),	(*for transform. safe_step_tac*)
lcp@982
   217
	 safe0_netpair	: netpair,		(*nets for trivial cases*)
lcp@982
   218
	 safep_netpair	: netpair,		(*nets for >0 subgoals*)
lcp@982
   219
	 haz_netpair  	: netpair,		(*nets for unsafe rules*)
lcp@982
   220
	 dup_netpair	: netpair};		(*nets for duplication*)
clasohm@0
   221
lcp@1073
   222
(*Desired invariants are
lcp@681
   223
	safe0_netpair = build safe0_brls,
lcp@681
   224
	safep_netpair = build safep_brls,
lcp@681
   225
	haz_netpair = build (joinrules(hazIs, hazEs)),
lcp@681
   226
	dup_netpair = build (joinrules(map dup_intr hazIs, 
lcp@681
   227
				       map dup_elim hazEs))}
lcp@1073
   228
lcp@1073
   229
where build = build_netpair(Net.empty,Net.empty), 
lcp@1073
   230
      safe0_brls contains all brules that solve the subgoal, and
lcp@1073
   231
      safep_brls contains all brules that generate 1 or more new subgoals.
wenzelm@4079
   232
The theorem lists are largely comments, though they are used in merge_cs and print_cs.
lcp@1073
   233
Nets must be built incrementally, to save space and time.
lcp@1073
   234
*)
clasohm@0
   235
lcp@1073
   236
val empty_cs = 
lcp@1073
   237
  CS{safeIs	= [],
lcp@1073
   238
     safeEs	= [],
lcp@1073
   239
     hazIs	= [],
lcp@1073
   240
     hazEs	= [],
oheimb@2630
   241
     uwrapper   = I,
oheimb@2630
   242
     swrapper   = I,
lcp@1073
   243
     safe0_netpair = (Net.empty,Net.empty),
lcp@1073
   244
     safep_netpair = (Net.empty,Net.empty),
lcp@1073
   245
     haz_netpair   = (Net.empty,Net.empty),
lcp@1073
   246
     dup_netpair   = (Net.empty,Net.empty)};
clasohm@0
   247
wenzelm@3546
   248
fun print_cs (CS {safeIs, safeEs, hazIs, hazEs, ...}) =
wenzelm@3546
   249
  let val pretty_thms = map Display.pretty_thm in
wenzelm@3546
   250
    Pretty.writeln (Pretty.big_list "introduction rules:" (pretty_thms hazIs));
wenzelm@3546
   251
    Pretty.writeln (Pretty.big_list "safe introduction rules:" (pretty_thms safeIs));
wenzelm@3546
   252
    Pretty.writeln (Pretty.big_list "elimination rules:" (pretty_thms hazEs));
wenzelm@3546
   253
    Pretty.writeln (Pretty.big_list "safe elimination rules:" (pretty_thms safeEs))
wenzelm@3546
   254
  end;
clasohm@0
   255
lcp@1073
   256
fun rep_claset (CS args) = args;
lcp@1073
   257
wenzelm@4079
   258
oheimb@2630
   259
fun getWrapper  (CS{uwrapper,...}) = uwrapper;
oheimb@2630
   260
oheimb@2630
   261
fun getSWrapper (CS{swrapper,...}) = swrapper;
lcp@1073
   262
lcp@1073
   263
wenzelm@4079
   264
paulson@1800
   265
(*** Adding (un)safe introduction or elimination rules.
lcp@1073
   266
lcp@1073
   267
    In case of overlap, new rules are tried BEFORE old ones!!
paulson@1800
   268
***)
clasohm@0
   269
lcp@1073
   270
(*For use with biresolve_tac.  Combines intr rules with swap to handle negated
lcp@1073
   271
  assumptions.  Pairs elim rules with true. *)
lcp@1073
   272
fun joinrules (intrs,elims) =  
lcp@1073
   273
    (map (pair true) (elims @ swapify intrs)  @
lcp@1073
   274
     map (pair false) intrs);
lcp@1073
   275
lcp@1073
   276
(*Priority: prefer rules with fewest subgoals, 
paulson@1231
   277
  then rules added most recently (preferring the head of the list).*)
lcp@1073
   278
fun tag_brls k [] = []
lcp@1073
   279
  | tag_brls k (brl::brls) =
lcp@1073
   280
      (1000000*subgoals_of_brl brl + k, brl) :: 
lcp@1073
   281
      tag_brls (k+1) brls;
lcp@1073
   282
paulson@1800
   283
fun insert_tagged_list kbrls netpr = foldr insert_tagged_brl (kbrls, netpr);
lcp@1073
   284
lcp@1073
   285
(*Insert into netpair that already has nI intr rules and nE elim rules.
lcp@1073
   286
  Count the intr rules double (to account for swapify).  Negate to give the
lcp@1073
   287
  new insertions the lowest priority.*)
lcp@1073
   288
fun insert (nI,nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules;
lcp@1073
   289
paulson@1800
   290
fun delete_tagged_list brls netpr = foldr delete_tagged_brl (brls, netpr);
lcp@1073
   291
paulson@1800
   292
val delete = delete_tagged_list o joinrules;
paulson@1800
   293
paulson@2813
   294
val mem_thm = gen_mem eq_thm
paulson@2813
   295
and rem_thm = gen_rem eq_thm;
paulson@2813
   296
paulson@1927
   297
(*Warn if the rule is already present ELSEWHERE in the claset.  The addition
paulson@1927
   298
  is still allowed.*)
paulson@1927
   299
fun warn_dup th (CS{safeIs, safeEs, hazIs, hazEs, ...}) = 
paulson@2813
   300
       if mem_thm (th, safeIs) then 
wenzelm@4079
   301
	 warning ("Rule already in claset as Safe Intr\n" ^ string_of_thm th)
paulson@2813
   302
  else if mem_thm (th, safeEs) then
wenzelm@4079
   303
         warning ("Rule already in claset as Safe Elim\n" ^ string_of_thm th)
paulson@2813
   304
  else if mem_thm (th, hazIs) then 
wenzelm@4079
   305
         warning ("Rule already in claset as unsafe Intr\n" ^ string_of_thm th)
paulson@2813
   306
  else if mem_thm (th, hazEs) then 
wenzelm@4079
   307
         warning ("Rule already in claset as unsafe Elim\n" ^ string_of_thm th)
paulson@1927
   308
  else ();
paulson@1927
   309
paulson@1800
   310
(*** Safe rules ***)
lcp@982
   311
oheimb@2630
   312
fun addSI (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@1927
   313
	      safe0_netpair, safep_netpair, haz_netpair, dup_netpair},
paulson@1927
   314
	   th)  =
paulson@2813
   315
  if mem_thm (th, safeIs) then 
wenzelm@4079
   316
	 (warning ("Ignoring duplicate Safe Intr\n" ^ string_of_thm th);
paulson@1927
   317
	  cs)
paulson@1927
   318
  else
lcp@1073
   319
  let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
paulson@1927
   320
          partition (fn rl => nprems_of rl=0) [th]
paulson@1927
   321
      val nI = length safeIs + 1
lcp@1073
   322
      and nE = length safeEs
paulson@1927
   323
  in warn_dup th cs;
paulson@1927
   324
     CS{safeIs	= th::safeIs,
lcp@1073
   325
        safe0_netpair = insert (nI,nE) (safe0_rls, []) safe0_netpair,
lcp@1073
   326
	safep_netpair = insert (nI,nE) (safep_rls, []) safep_netpair,
lcp@1073
   327
	safeEs	= safeEs,
lcp@1073
   328
	hazIs	= hazIs,
lcp@1073
   329
	hazEs	= hazEs,
oheimb@2630
   330
	uwrapper     = uwrapper,
oheimb@2630
   331
	swrapper     = swrapper,
oheimb@2630
   332
	haz_netpair  = haz_netpair,
oheimb@2630
   333
	dup_netpair  = dup_netpair}
lcp@1073
   334
  end;
lcp@1073
   335
oheimb@2630
   336
fun addSE (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@1927
   337
		    safe0_netpair, safep_netpair, haz_netpair, dup_netpair},
paulson@1927
   338
	   th)  =
paulson@2813
   339
  if mem_thm (th, safeEs) then 
wenzelm@4079
   340
	 (warning ("Ignoring duplicate Safe Elim\n" ^ string_of_thm th);
paulson@1927
   341
	  cs)
paulson@1927
   342
  else
lcp@1073
   343
  let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
paulson@1927
   344
          partition (fn rl => nprems_of rl=1) [th]
lcp@1073
   345
      val nI = length safeIs
paulson@1927
   346
      and nE = length safeEs + 1
paulson@1927
   347
  in warn_dup th cs;
paulson@1927
   348
     CS{safeEs	= th::safeEs,
lcp@1073
   349
        safe0_netpair = insert (nI,nE) ([], safe0_rls) safe0_netpair,
lcp@1073
   350
	safep_netpair = insert (nI,nE) ([], safep_rls) safep_netpair,
lcp@1073
   351
	safeIs	= safeIs,
lcp@1073
   352
	hazIs	= hazIs,
lcp@1073
   353
	hazEs	= hazEs,
oheimb@2630
   354
	uwrapper     = uwrapper,
oheimb@2630
   355
	swrapper     = swrapper,
oheimb@2630
   356
	haz_netpair  = haz_netpair,
oheimb@2630
   357
	dup_netpair  = dup_netpair}
lcp@1073
   358
  end;
clasohm@0
   359
paulson@1927
   360
fun rev_foldl f (e, l) = foldl f (e, rev l);
paulson@1927
   361
paulson@1927
   362
val op addSIs = rev_foldl addSI;
paulson@1927
   363
val op addSEs = rev_foldl addSE;
paulson@1927
   364
clasohm@0
   365
fun cs addSDs ths = cs addSEs (map make_elim ths);
clasohm@0
   366
lcp@1073
   367
paulson@1800
   368
(*** Hazardous (unsafe) rules ***)
clasohm@0
   369
oheimb@2630
   370
fun addI (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@1927
   371
		   safe0_netpair, safep_netpair, haz_netpair, dup_netpair},
paulson@1927
   372
	  th)=
paulson@2813
   373
  if mem_thm (th, hazIs) then 
wenzelm@4079
   374
	 (warning ("Ignoring duplicate unsafe Intr\n" ^ string_of_thm th);
paulson@1927
   375
	  cs)
paulson@1927
   376
  else
paulson@1927
   377
  let val nI = length hazIs + 1
lcp@1073
   378
      and nE = length hazEs
paulson@1927
   379
  in warn_dup th cs;
paulson@1927
   380
     CS{hazIs	= th::hazIs,
paulson@1927
   381
	haz_netpair = insert (nI,nE) ([th], []) haz_netpair,
paulson@1927
   382
	dup_netpair = insert (nI,nE) (map dup_intr [th], []) dup_netpair,
lcp@1073
   383
	safeIs 	= safeIs, 
lcp@1073
   384
	safeEs	= safeEs,
lcp@1073
   385
	hazEs	= hazEs,
oheimb@2630
   386
	uwrapper      = uwrapper,
oheimb@2630
   387
	swrapper      = swrapper,
lcp@1073
   388
	safe0_netpair = safe0_netpair,
lcp@1073
   389
	safep_netpair = safep_netpair}
lcp@1073
   390
  end;
lcp@1073
   391
oheimb@2630
   392
fun addE (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@1927
   393
		   safe0_netpair, safep_netpair, haz_netpair, dup_netpair},
paulson@1927
   394
	  th) =
paulson@2813
   395
  if mem_thm (th, hazEs) then 
wenzelm@4079
   396
	 (warning ("Ignoring duplicate unsafe Elim\n" ^ string_of_thm th);
paulson@1927
   397
	  cs)
paulson@1927
   398
  else
lcp@1073
   399
  let val nI = length hazIs 
paulson@1927
   400
      and nE = length hazEs + 1
paulson@1927
   401
  in warn_dup th cs;
paulson@1927
   402
     CS{hazEs	= th::hazEs,
paulson@1927
   403
	haz_netpair = insert (nI,nE) ([], [th]) haz_netpair,
paulson@1927
   404
	dup_netpair = insert (nI,nE) ([], map dup_elim [th]) dup_netpair,
lcp@1073
   405
	safeIs	= safeIs, 
lcp@1073
   406
	safeEs	= safeEs,
lcp@1073
   407
	hazIs	= hazIs,
oheimb@2630
   408
	uwrapper      = uwrapper,
oheimb@2630
   409
	swrapper      = swrapper,
lcp@1073
   410
	safe0_netpair = safe0_netpair,
lcp@1073
   411
	safep_netpair = safep_netpair}
lcp@1073
   412
  end;
clasohm@0
   413
paulson@1927
   414
val op addIs = rev_foldl addI;
paulson@1927
   415
val op addEs = rev_foldl addE;
paulson@1927
   416
clasohm@0
   417
fun cs addDs ths = cs addEs (map make_elim ths);
clasohm@0
   418
lcp@1073
   419
paulson@1800
   420
(*** Deletion of rules 
paulson@1800
   421
     Working out what to delete, requires repeating much of the code used
paulson@1800
   422
	to insert.
paulson@1927
   423
     Separate functions delSI, etc., are not exported; instead delrules
paulson@2813
   424
        searches in all the lists and chooses the relevant delXX functions.
paulson@1800
   425
***)
paulson@1800
   426
paulson@2813
   427
fun delSI th 
paulson@2813
   428
          (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@2813
   429
		    safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) =
paulson@2813
   430
 if mem_thm (th, safeIs) then
paulson@2813
   431
   let val (safe0_rls, safep_rls) = partition (fn rl => nprems_of rl=0) [th]
paulson@2813
   432
   in CS{safe0_netpair = delete (safe0_rls, []) safe0_netpair,
paulson@2813
   433
	 safep_netpair = delete (safep_rls, []) safep_netpair,
paulson@2813
   434
	 safeIs	= rem_thm (safeIs,th),
paulson@2813
   435
	 safeEs	= safeEs,
paulson@2813
   436
	 hazIs	= hazIs,
paulson@2813
   437
	 hazEs	= hazEs,
paulson@2813
   438
	 uwrapper     = uwrapper,
paulson@2813
   439
	 swrapper     = swrapper,
paulson@2813
   440
	 haz_netpair  = haz_netpair,
paulson@2813
   441
	 dup_netpair  = dup_netpair}
paulson@2813
   442
   end
paulson@2813
   443
 else cs;
paulson@1800
   444
paulson@2813
   445
fun delSE th
paulson@2813
   446
          (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@2813
   447
	            safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) =
paulson@2813
   448
 if mem_thm (th, safeEs) then
paulson@2813
   449
   let val (safe0_rls, safep_rls) = partition (fn rl => nprems_of rl=1) [th]
paulson@2813
   450
   in CS{safe0_netpair = delete ([], safe0_rls) safe0_netpair,
paulson@2813
   451
	 safep_netpair = delete ([], safep_rls) safep_netpair,
paulson@2813
   452
	 safeIs	= safeIs,
paulson@2813
   453
	 safeEs	= rem_thm (safeEs,th),
paulson@2813
   454
	 hazIs	= hazIs,
paulson@2813
   455
	 hazEs	= hazEs,
paulson@2813
   456
	 uwrapper     = uwrapper,
paulson@2813
   457
	 swrapper     = swrapper,
paulson@2813
   458
	 haz_netpair  = haz_netpair,
paulson@2813
   459
	 dup_netpair  = dup_netpair}
paulson@2813
   460
   end
paulson@2813
   461
 else cs;
paulson@1800
   462
paulson@1800
   463
paulson@2813
   464
fun delI th
paulson@2813
   465
         (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@2813
   466
	           safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) =
paulson@2813
   467
 if mem_thm (th, hazIs) then
paulson@2813
   468
     CS{haz_netpair = delete ([th], []) haz_netpair,
paulson@1800
   469
	dup_netpair = delete ([dup_intr th], []) dup_netpair,
paulson@1800
   470
	safeIs 	= safeIs, 
paulson@1800
   471
	safeEs	= safeEs,
paulson@2813
   472
	hazIs	= rem_thm (hazIs,th),
paulson@1800
   473
	hazEs	= hazEs,
oheimb@2630
   474
	uwrapper      = uwrapper,
oheimb@2630
   475
	swrapper      = swrapper,
paulson@1800
   476
	safe0_netpair = safe0_netpair,
paulson@2813
   477
	safep_netpair = safep_netpair}
paulson@2813
   478
 else cs;
paulson@1800
   479
paulson@2813
   480
fun delE th
paulson@2813
   481
	 (cs as CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper, 
paulson@2813
   482
	           safe0_netpair, safep_netpair, haz_netpair, dup_netpair}) =
paulson@2813
   483
 if mem_thm (th, hazEs) then
paulson@2813
   484
     CS{haz_netpair = delete ([], [th]) haz_netpair,
paulson@1800
   485
	dup_netpair = delete ([], [dup_elim th]) dup_netpair,
paulson@1800
   486
	safeIs	= safeIs, 
paulson@1800
   487
	safeEs	= safeEs,
paulson@1800
   488
	hazIs	= hazIs,
paulson@2813
   489
	hazEs	= rem_thm (hazEs,th),
oheimb@2630
   490
	uwrapper      = uwrapper,
oheimb@2630
   491
	swrapper      = swrapper,
paulson@1800
   492
	safe0_netpair = safe0_netpair,
paulson@2813
   493
	safep_netpair = safep_netpair}
paulson@2813
   494
 else cs;
paulson@1800
   495
paulson@2813
   496
(*Delete ALL occurrences of "th" in the claset (perhaps from several lists)*)
paulson@1800
   497
fun delrule (cs as CS{safeIs, safeEs, hazIs, hazEs, ...}, th) =
paulson@2813
   498
       if mem_thm (th, safeIs) orelse mem_thm (th, safeEs) orelse
paulson@2813
   499
	  mem_thm (th, hazIs)  orelse mem_thm (th, hazEs) 
paulson@2813
   500
       then delSI th (delSE th (delI th (delE th cs)))
wenzelm@4079
   501
       else (warning ("Rule not in claset\n" ^ (string_of_thm th)); 
paulson@2813
   502
	     cs);
paulson@1800
   503
paulson@1800
   504
val op delrules = foldl delrule;
paulson@1800
   505
paulson@1800
   506
oheimb@2630
   507
(*** Setting or modifying the wrapper tacticals ***)
lcp@982
   508
oheimb@2630
   509
(*Set a new uwrapper*)
oheimb@2630
   510
fun (CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper,
lcp@1073
   511
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair, ...}) 
oheimb@2630
   512
    setWrapper new_uwrapper  =
oheimb@2630
   513
  CS{safeIs	= safeIs,
lcp@1073
   514
     safeEs	= safeEs,
lcp@1073
   515
     hazIs	= hazIs,
lcp@1073
   516
     hazEs	= hazEs,
oheimb@2630
   517
     uwrapper 	= new_uwrapper,
oheimb@2630
   518
     swrapper   = swrapper,
lcp@1073
   519
     safe0_netpair = safe0_netpair,
lcp@1073
   520
     safep_netpair = safep_netpair,
lcp@1073
   521
     haz_netpair = haz_netpair,
lcp@1073
   522
     dup_netpair = dup_netpair};
lcp@982
   523
oheimb@2630
   524
(*Set a new swrapper*)
oheimb@2630
   525
fun (CS{safeIs, safeEs, hazIs, hazEs, uwrapper, swrapper,
oheimb@2630
   526
	safe0_netpair, safep_netpair, haz_netpair, dup_netpair, ...}) 
oheimb@2630
   527
    setSWrapper new_swrapper  =
oheimb@2630
   528
  CS{safeIs	= safeIs,
oheimb@2630
   529
     safeEs	= safeEs,
oheimb@2630
   530
     hazIs	= hazIs,
oheimb@2630
   531
     hazEs	= hazEs,
oheimb@2630
   532
     uwrapper   = uwrapper,
oheimb@2630
   533
     swrapper   = new_swrapper,
oheimb@2630
   534
     safe0_netpair = safe0_netpair,
oheimb@2630
   535
     safep_netpair = safep_netpair,
oheimb@2630
   536
     haz_netpair = haz_netpair,
oheimb@2630
   537
     dup_netpair = dup_netpair};
lcp@982
   538
oheimb@2630
   539
(*Compose a tactical with the existing uwrapper*)
oheimb@2630
   540
fun cs compWrapper  uwrapper' = cs setWrapper  (uwrapper' o getWrapper cs);
oheimb@2630
   541
oheimb@2630
   542
(*Compose a tactical with the existing swrapper*)
oheimb@2630
   543
fun cs compSWrapper swrapper' = cs setSWrapper (swrapper' o getSWrapper cs);
lcp@982
   544
oheimb@2630
   545
(*compose a safe tactic sequentially before/alternatively after safe_step_tac*)
oheimb@2630
   546
fun cs addSbefore tac1 = cs compSWrapper (fn tac2 => tac1 THEN_MAYBE' tac2);
oheimb@2630
   547
fun cs addSaltern tac2 = cs compSWrapper (fn tac1 => tac1 ORELSE'     tac2);
lcp@982
   548
oheimb@2630
   549
(*compose a tactic sequentially before/alternatively after the step tactic*)
oheimb@2630
   550
fun cs addbefore  tac1 = cs compWrapper  (fn tac2 => tac1 THEN_MAYBE' tac2);
oheimb@2630
   551
fun cs addaltern  tac2 = cs compWrapper  (fn tac1 => tac1 APPEND'     tac2);
lcp@982
   552
paulson@1711
   553
(*Merge works by adding all new rules of the 2nd claset into the 1st claset.
paulson@1711
   554
  Merging the term nets may look more efficient, but the rather delicate
paulson@1711
   555
  treatment of priority might get muddled up.*)
paulson@1711
   556
fun merge_cs
oheimb@2630
   557
    (cs as CS{safeIs, safeEs, hazIs, hazEs, ...},
paulson@1711
   558
     CS{safeIs=safeIs2, safeEs=safeEs2, hazIs=hazIs2, hazEs=hazEs2,...}) =
paulson@1711
   559
  let val safeIs' = gen_rems eq_thm (safeIs2,safeIs)
paulson@1711
   560
      val safeEs' = gen_rems eq_thm (safeEs2,safeEs)
oheimb@2630
   561
      val  hazIs' = gen_rems eq_thm ( hazIs2, hazIs)
oheimb@2630
   562
      val  hazEs' = gen_rems eq_thm ( hazEs2, hazEs)
paulson@1711
   563
  in cs addSIs safeIs'
paulson@1711
   564
        addSEs safeEs'
paulson@1711
   565
        addIs  hazIs'
paulson@1711
   566
        addEs  hazEs'
paulson@1711
   567
  end;
paulson@1711
   568
lcp@982
   569
paulson@1800
   570
(**** Simple tactics for theorem proving ****)
clasohm@0
   571
clasohm@0
   572
(*Attack subgoals using safe inferences -- matching, not resolution*)
oheimb@2630
   573
fun safe_step_tac (cs as CS{safe0_netpair,safep_netpair,...}) = 
oheimb@2630
   574
  getSWrapper cs (FIRST' [
oheimb@2630
   575
	eq_assume_tac,
oheimb@2630
   576
	eq_mp_tac,
oheimb@2630
   577
	bimatch_from_nets_tac safe0_netpair,
oheimb@2630
   578
	FIRST' hyp_subst_tacs,
oheimb@2630
   579
	bimatch_from_nets_tac safep_netpair]);
clasohm@0
   580
clasohm@0
   581
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*)
oheimb@2630
   582
fun safe_tac cs = REPEAT_DETERM_FIRST 
oheimb@2630
   583
	(fn i => COND (has_fewer_prems i) no_tac (safe_step_tac cs i));
lcp@747
   584
paulson@3705
   585
paulson@3705
   586
(*** Clarify_tac: do safe steps without causing branching ***)
paulson@3705
   587
paulson@3705
   588
fun nsubgoalsP n (k,brl) = (subgoals_of_brl brl = n);
paulson@3705
   589
paulson@3705
   590
(*version of bimatch_from_nets_tac that only applies rules that
paulson@3705
   591
  create precisely n subgoals.*)
paulson@3705
   592
fun n_bimatch_from_nets_tac n = 
paulson@3705
   593
    biresolution_from_nets_tac (orderlist o filter (nsubgoalsP n)) true;
paulson@3705
   594
paulson@3705
   595
fun eq_contr_tac i = ematch_tac [not_elim] i  THEN  eq_assume_tac i;
paulson@3705
   596
val eq_assume_contr_tac = eq_assume_tac ORELSE' eq_contr_tac;
paulson@3705
   597
paulson@3705
   598
(*Two-way branching is allowed only if one of the branches immediately closes*)
paulson@3705
   599
fun bimatch2_tac netpair i =
paulson@3705
   600
    n_bimatch_from_nets_tac 2 netpair i THEN
paulson@3705
   601
    (eq_assume_contr_tac i ORELSE eq_assume_contr_tac (i+1));
paulson@3705
   602
paulson@3705
   603
(*Attack subgoals using safe inferences -- matching, not resolution*)
paulson@3705
   604
fun clarify_step_tac (cs as CS{safe0_netpair,safep_netpair,...}) = 
paulson@3705
   605
  getSWrapper cs (FIRST' [
paulson@3705
   606
	eq_assume_contr_tac,
paulson@3705
   607
	bimatch_from_nets_tac safe0_netpair,
paulson@3705
   608
	FIRST' hyp_subst_tacs,
paulson@3705
   609
	n_bimatch_from_nets_tac 1 safep_netpair,
paulson@3705
   610
        bimatch2_tac safep_netpair]);
paulson@3705
   611
paulson@3705
   612
fun clarify_tac cs = SELECT_GOAL (REPEAT_DETERM (clarify_step_tac cs 1));
paulson@3705
   613
paulson@3705
   614
paulson@3705
   615
(*** Unsafe steps instantiate variables or lose information ***)
paulson@3705
   616
paulson@4066
   617
(*Backtracking is allowed among the various these unsafe ways of
paulson@4066
   618
  proving a subgoal.  *)
lcp@747
   619
fun inst0_step_tac (CS{safe0_netpair,safep_netpair,...}) =
lcp@747
   620
  assume_tac 			  APPEND' 
lcp@747
   621
  contr_tac 			  APPEND' 
lcp@747
   622
  biresolve_from_nets_tac safe0_netpair;
lcp@747
   623
paulson@4066
   624
(*These unsafe steps could generate more subgoals.*)
lcp@747
   625
fun instp_step_tac (CS{safep_netpair,...}) =
lcp@747
   626
  biresolve_from_nets_tac safep_netpair;
clasohm@0
   627
clasohm@0
   628
(*These steps could instantiate variables and are therefore unsafe.*)
lcp@747
   629
fun inst_step_tac cs = inst0_step_tac cs APPEND' instp_step_tac cs;
clasohm@0
   630
lcp@982
   631
fun haz_step_tac (CS{haz_netpair,...}) = 
lcp@681
   632
  biresolve_from_nets_tac haz_netpair;
lcp@681
   633
clasohm@0
   634
(*Single step for the prover.  FAILS unless it makes progress. *)
oheimb@2630
   635
fun step_tac cs i = getWrapper cs 
oheimb@2630
   636
	(K (safe_tac cs) ORELSE' (inst_step_tac cs ORELSE' haz_step_tac cs)) i;
clasohm@0
   637
clasohm@0
   638
(*Using a "safe" rule to instantiate variables is unsafe.  This tactic
clasohm@0
   639
  allows backtracking from "safe" rules to "unsafe" rules here.*)
oheimb@2630
   640
fun slow_step_tac cs i = getWrapper cs 
oheimb@2630
   641
	(K (safe_tac cs) ORELSE' (inst_step_tac cs APPEND' haz_step_tac cs)) i;
clasohm@0
   642
paulson@1800
   643
(**** The following tactics all fail unless they solve one goal ****)
clasohm@0
   644
clasohm@0
   645
(*Dumb but fast*)
clasohm@0
   646
fun fast_tac cs = SELECT_GOAL (DEPTH_SOLVE (step_tac cs 1));
clasohm@0
   647
clasohm@0
   648
(*Slower but smarter than fast_tac*)
clasohm@0
   649
fun best_tac cs = 
clasohm@0
   650
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (step_tac cs 1));
clasohm@0
   651
clasohm@0
   652
fun slow_tac cs = SELECT_GOAL (DEPTH_SOLVE (slow_step_tac cs 1));
clasohm@0
   653
clasohm@0
   654
fun slow_best_tac cs = 
clasohm@0
   655
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (slow_step_tac cs 1));
clasohm@0
   656
lcp@681
   657
paulson@1800
   658
(***ASTAR with weight weight_ASTAR, by Norbert Voelker*) 
paulson@1587
   659
val weight_ASTAR = ref 5; 
paulson@1587
   660
paulson@1587
   661
fun astar_tac cs = 
paulson@1587
   662
  SELECT_GOAL ( ASTAR (has_fewer_prems 1
paulson@1587
   663
	      , fn level =>(fn thm =>size_of_thm thm + !weight_ASTAR *level)) 
paulson@1587
   664
	      (step_tac cs 1));
paulson@1587
   665
paulson@1587
   666
fun slow_astar_tac cs = 
paulson@1587
   667
  SELECT_GOAL ( ASTAR (has_fewer_prems 1
paulson@1587
   668
	      , fn level =>(fn thm =>size_of_thm thm + !weight_ASTAR *level)) 
paulson@1587
   669
	      (slow_step_tac cs 1));
paulson@1587
   670
paulson@1800
   671
(**** Complete tactic, loosely based upon LeanTaP.  This tactic is the outcome
lcp@747
   672
  of much experimentation!  Changing APPEND to ORELSE below would prove
lcp@747
   673
  easy theorems faster, but loses completeness -- and many of the harder
paulson@1800
   674
  theorems such as 43. ****)
lcp@681
   675
lcp@747
   676
(*Non-deterministic!  Could always expand the first unsafe connective.
lcp@747
   677
  That's hard to implement and did not perform better in experiments, due to
lcp@747
   678
  greater search depth required.*)
lcp@681
   679
fun dup_step_tac (cs as (CS{dup_netpair,...})) = 
lcp@681
   680
  biresolve_from_nets_tac dup_netpair;
lcp@681
   681
lcp@747
   682
(*Searching to depth m.*)
paulson@3537
   683
fun depth_tac cs m i state = 
lcp@747
   684
  SELECT_GOAL 
oheimb@2630
   685
   (getWrapper cs
oheimb@3204
   686
    (fn i => REPEAT_DETERM1 (COND (has_fewer_prems i) no_tac
oheimb@3204
   687
			     (safe_step_tac cs i)) THEN_ELSE
oheimb@2630
   688
     (DEPTH_SOLVE (depth_tac cs m i),
oheimb@2630
   689
      inst0_step_tac cs i  APPEND
lcp@747
   690
      COND (K(m=0)) no_tac
oheimb@2630
   691
        ((instp_step_tac cs i APPEND dup_step_tac cs i)
oheimb@2630
   692
	 THEN DEPTH_SOLVE (depth_tac cs (m-1) i)))) 1)
paulson@3537
   693
  i state;
lcp@747
   694
paulson@2173
   695
(*Search, with depth bound m.  
paulson@2173
   696
  This is the "entry point", which does safe inferences first.*)
lcp@747
   697
fun safe_depth_tac cs m = 
lcp@681
   698
  SUBGOAL 
lcp@681
   699
    (fn (prem,i) =>
lcp@681
   700
      let val deti =
lcp@681
   701
	  (*No Vars in the goal?  No need to backtrack between goals.*)
lcp@681
   702
	  case term_vars prem of
lcp@681
   703
	      []	=> DETERM 
lcp@681
   704
	    | _::_	=> I
lcp@681
   705
      in  SELECT_GOAL (TRY (safe_tac cs) THEN 
lcp@747
   706
		       DEPTH_SOLVE (deti (depth_tac cs m 1))) i
lcp@747
   707
      end);
lcp@681
   708
paulson@2868
   709
fun deepen_tac cs = DEEPEN (2,10) (safe_depth_tac cs);
lcp@681
   710
wenzelm@4079
   711
berghofe@1724
   712
wenzelm@4079
   713
(** claset theory data **)
wenzelm@4079
   714
wenzelm@4079
   715
(* init data kind claset *)
berghofe@1724
   716
wenzelm@4079
   717
exception CSData of claset ref;
berghofe@1724
   718
wenzelm@4079
   719
local
wenzelm@4079
   720
  val empty = CSData (ref empty_cs);
wenzelm@4079
   721
wenzelm@4079
   722
  (*create new references*)
wenzelm@4079
   723
  fun prep_ext (ClasetData (ref (CSData (ref cs)))) =
wenzelm@4079
   724
    ClasetData (ref (CSData (ref cs)));
berghofe@1724
   725
wenzelm@4079
   726
  fun merge (ClasetData (ref (CSData (ref cs1))), ClasetData (ref (CSData (ref cs2)))) =
wenzelm@4079
   727
    ClasetData (ref (CSData (ref (merge_cs (cs1, cs2)))));
berghofe@1724
   728
wenzelm@4079
   729
  fun print (ClasetData (ref (CSData (ref cs)))) = print_cs cs;
wenzelm@4079
   730
in
wenzelm@4079
   731
  val _ = fix_methods (empty, prep_ext, merge, print);
wenzelm@4079
   732
end;
wenzelm@4079
   733
berghofe@1724
   734
wenzelm@4079
   735
(* access claset *)
berghofe@1724
   736
wenzelm@4079
   737
fun claset_ref_of_sg sg =
wenzelm@4079
   738
  (case Sign.get_data sg clasetK of
wenzelm@4079
   739
    ClasetData (ref (CSData r)) => r
wenzelm@4079
   740
  | _ => sys_error "claset_ref_of_sg");
paulson@1807
   741
wenzelm@4079
   742
val claset_ref_of = claset_ref_of_sg o sign_of;
wenzelm@4079
   743
val claset_of_sg = ! o claset_ref_of_sg;
wenzelm@4079
   744
val claset_of = claset_of_sg o sign_of;
paulson@1800
   745
wenzelm@4079
   746
fun CLASET tacf state = tacf (claset_of_sg (sign_of_thm state)) state;
wenzelm@4079
   747
fun CLASET' tacf i state = tacf (claset_of_sg (sign_of_thm state)) i state;
paulson@3705
   748
wenzelm@4079
   749
val claset = claset_of o Context.get_context;
wenzelm@4079
   750
val claset_ref = claset_ref_of_sg o sign_of o Context.get_context;
wenzelm@4079
   751
paulson@3705
   752
wenzelm@4079
   753
(* change claset *)
paulson@1800
   754
wenzelm@4079
   755
fun change_claset f x = claset_ref () := (f (claset (), x));
berghofe@1724
   756
wenzelm@4079
   757
val AddDs = change_claset (op addDs);
wenzelm@4079
   758
val AddEs = change_claset (op addEs);
wenzelm@4079
   759
val AddIs = change_claset (op addIs);
wenzelm@4079
   760
val AddSDs = change_claset (op addSDs);
wenzelm@4079
   761
val AddSEs = change_claset (op addSEs);
wenzelm@4079
   762
val AddSIs = change_claset (op addSIs);
wenzelm@4079
   763
val Delrules = change_claset (op delrules);
paulson@3727
   764
wenzelm@4079
   765
wenzelm@4079
   766
(* tactics referring to the implicit claset *)
paulson@1800
   767
wenzelm@4079
   768
(*the abstraction over the proof state delays the dereferencing*)
wenzelm@4079
   769
fun Safe_tac st		  = safe_tac (claset()) st;
wenzelm@4079
   770
fun Safe_step_tac i st	  = safe_step_tac (claset()) i st;
wenzelm@4079
   771
fun Clarify_step_tac i st = clarify_step_tac (claset()) i st;
wenzelm@4079
   772
fun Clarify_tac i st	  = clarify_tac (claset()) i st;
wenzelm@4079
   773
fun Step_tac i st	  = step_tac (claset()) i st;
wenzelm@4079
   774
fun Fast_tac i st	  = fast_tac (claset()) i st;
wenzelm@4079
   775
fun Best_tac i st	  = best_tac (claset()) i st;
wenzelm@4079
   776
fun Slow_tac i st	  = slow_tac (claset()) i st;
wenzelm@4079
   777
fun Slow_best_tac i st	  = slow_best_tac (claset()) i st;
wenzelm@4079
   778
fun Deepen_tac m	  = deepen_tac (claset()) m;
paulson@2066
   779
paulson@1800
   780
clasohm@0
   781
end; 
clasohm@0
   782
end;