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