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