src/Provers/classical.ML
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (19 months ago)
changeset 67003 49850a679c2c
parent 64556 851ae0e7b09c
child 67649 1e1782c1aedf
permissions -rw-r--r--
more robust sorted_entries;
wenzelm@9938
     1
(*  Title:      Provers/classical.ML
wenzelm@9938
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     3
clasohm@0
     4
Theorem prover for classical reasoning, including predicate calculus, set
clasohm@0
     5
theory, etc.
clasohm@0
     6
wenzelm@60943
     7
Rules must be classified as intro, elim, safe, unsafe.
clasohm@0
     8
clasohm@0
     9
A rule is unsafe unless it can be applied blindly without harmful results.
clasohm@0
    10
For a rule to be safe, its premises and conclusion should be logically
clasohm@0
    11
equivalent.  There should be no variables in the premises that are not in
clasohm@0
    12
the conclusion.
clasohm@0
    13
*)
clasohm@0
    14
wenzelm@4079
    15
(*higher precedence than := facilitates use of references*)
wenzelm@12376
    16
infix 4 addSIs addSEs addSDs addIs addEs addDs delrules
oheimb@4651
    17
  addSWrapper delSWrapper addWrapper delWrapper
oheimb@11181
    18
  addSbefore addSafter addbefore addafter
oheimb@5523
    19
  addD2 addE2 addSD2 addSE2;
wenzelm@4079
    20
clasohm@0
    21
signature CLASSICAL_DATA =
wenzelm@4079
    22
sig
wenzelm@42790
    23
  val imp_elim: thm  (* P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R *)
wenzelm@42790
    24
  val not_elim: thm  (* ~P ==> P ==> R *)
wenzelm@42790
    25
  val swap: thm  (* ~ P ==> (~ R ==> P) ==> R *)
wenzelm@42790
    26
  val classical: thm  (* (~ P ==> P) ==> P *)
wenzelm@50062
    27
  val sizef: thm -> int  (* size function for BEST_FIRST, typically size_of_thm *)
wenzelm@51798
    28
  val hyp_subst_tacs: (Proof.context -> int -> tactic) list (* optional tactics for
wenzelm@51798
    29
    substitution in the hypotheses; assumed to be safe! *)
wenzelm@4079
    30
end;
clasohm@0
    31
wenzelm@5841
    32
signature BASIC_CLASSICAL =
wenzelm@4079
    33
sig
wenzelm@42812
    34
  type wrapper = (int -> tactic) -> int -> tactic
clasohm@0
    35
  type claset
wenzelm@42793
    36
  val print_claset: Proof.context -> unit
wenzelm@42793
    37
  val addDs: Proof.context * thm list -> Proof.context
wenzelm@42793
    38
  val addEs: Proof.context * thm list -> Proof.context
wenzelm@42793
    39
  val addIs: Proof.context * thm list -> Proof.context
wenzelm@42793
    40
  val addSDs: Proof.context * thm list -> Proof.context
wenzelm@42793
    41
  val addSEs: Proof.context * thm list -> Proof.context
wenzelm@42793
    42
  val addSIs: Proof.context * thm list -> Proof.context
wenzelm@42793
    43
  val delrules: Proof.context * thm list -> Proof.context
wenzelm@51703
    44
  val addSWrapper: Proof.context * (string * (Proof.context -> wrapper)) -> Proof.context
wenzelm@51703
    45
  val delSWrapper: Proof.context * string -> Proof.context
wenzelm@51703
    46
  val addWrapper: Proof.context * (string * (Proof.context -> wrapper)) -> Proof.context
wenzelm@51703
    47
  val delWrapper: Proof.context * string -> Proof.context
wenzelm@51717
    48
  val addSbefore: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context
wenzelm@51717
    49
  val addSafter: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context
wenzelm@51717
    50
  val addbefore: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context
wenzelm@51717
    51
  val addafter: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context
wenzelm@51703
    52
  val addD2: Proof.context * (string * thm) -> Proof.context
wenzelm@51703
    53
  val addE2: Proof.context * (string * thm) -> Proof.context
wenzelm@51703
    54
  val addSD2: Proof.context * (string * thm) -> Proof.context
wenzelm@51703
    55
  val addSE2: Proof.context * (string * thm) -> Proof.context
wenzelm@42793
    56
  val appSWrappers: Proof.context -> wrapper
wenzelm@42793
    57
  val appWrappers: Proof.context -> wrapper
lcp@982
    58
wenzelm@42790
    59
  val claset_of: Proof.context -> claset
wenzelm@42793
    60
  val put_claset: claset -> Proof.context -> Proof.context
wenzelm@4079
    61
wenzelm@51703
    62
  val map_theory_claset: (Proof.context -> Proof.context) -> theory -> theory
wenzelm@51703
    63
wenzelm@42793
    64
  val fast_tac: Proof.context -> int -> tactic
wenzelm@42793
    65
  val slow_tac: Proof.context -> int -> tactic
wenzelm@42793
    66
  val astar_tac: Proof.context -> int -> tactic
wenzelm@42793
    67
  val slow_astar_tac: Proof.context -> int -> tactic
wenzelm@42793
    68
  val best_tac: Proof.context -> int -> tactic
wenzelm@42793
    69
  val first_best_tac: Proof.context -> int -> tactic
wenzelm@42793
    70
  val slow_best_tac: Proof.context -> int -> tactic
wenzelm@42793
    71
  val depth_tac: Proof.context -> int -> int -> tactic
wenzelm@42793
    72
  val deepen_tac: Proof.context -> int -> int -> tactic
paulson@1587
    73
wenzelm@58963
    74
  val contr_tac: Proof.context -> int -> tactic
wenzelm@59970
    75
  val dup_elim: Proof.context -> thm -> thm
wenzelm@42790
    76
  val dup_intr: thm -> thm
wenzelm@42793
    77
  val dup_step_tac: Proof.context -> int -> tactic
wenzelm@58957
    78
  val eq_mp_tac: Proof.context -> int -> tactic
wenzelm@60943
    79
  val unsafe_step_tac: Proof.context -> int -> tactic
wenzelm@58963
    80
  val mp_tac: Proof.context -> int -> tactic
wenzelm@42793
    81
  val safe_tac: Proof.context -> tactic
wenzelm@42793
    82
  val safe_steps_tac: Proof.context -> int -> tactic
wenzelm@42793
    83
  val safe_step_tac: Proof.context -> int -> tactic
wenzelm@42793
    84
  val clarify_tac: Proof.context -> int -> tactic
wenzelm@42793
    85
  val clarify_step_tac: Proof.context -> int -> tactic
wenzelm@42793
    86
  val step_tac: Proof.context -> int -> tactic
wenzelm@42793
    87
  val slow_step_tac: Proof.context -> int -> tactic
wenzelm@42790
    88
  val swapify: thm list -> thm list
wenzelm@58963
    89
  val swap_res_tac: Proof.context -> thm list -> int -> tactic
wenzelm@42793
    90
  val inst_step_tac: Proof.context -> int -> tactic
wenzelm@42793
    91
  val inst0_step_tac: Proof.context -> int -> tactic
wenzelm@42793
    92
  val instp_step_tac: Proof.context -> int -> tactic
wenzelm@4079
    93
end;
berghofe@1724
    94
wenzelm@5841
    95
signature CLASSICAL =
wenzelm@5841
    96
sig
wenzelm@5841
    97
  include BASIC_CLASSICAL
wenzelm@59970
    98
  val classical_rule: Proof.context -> thm -> thm
wenzelm@61055
    99
  type rule = thm * (thm * thm list) * (thm * thm list)
wenzelm@42812
   100
  type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net
wenzelm@42812
   101
  val rep_cs: claset ->
wenzelm@60945
   102
   {safeIs: rule Item_Net.T,
wenzelm@60945
   103
    safeEs: rule Item_Net.T,
wenzelm@60945
   104
    unsafeIs: rule Item_Net.T,
wenzelm@60945
   105
    unsafeEs: rule Item_Net.T,
wenzelm@42812
   106
    swrappers: (string * (Proof.context -> wrapper)) list,
wenzelm@42812
   107
    uwrappers: (string * (Proof.context -> wrapper)) list,
wenzelm@42812
   108
    safe0_netpair: netpair,
wenzelm@42812
   109
    safep_netpair: netpair,
wenzelm@60943
   110
    unsafe_netpair: netpair,
wenzelm@42812
   111
    dup_netpair: netpair,
wenzelm@60942
   112
    extra_netpair: Context_Rules.netpair}
wenzelm@24021
   113
  val get_cs: Context.generic -> claset
wenzelm@24021
   114
  val map_cs: (claset -> claset) -> Context.generic -> Context.generic
wenzelm@18728
   115
  val safe_dest: int option -> attribute
wenzelm@18728
   116
  val safe_elim: int option -> attribute
wenzelm@18728
   117
  val safe_intro: int option -> attribute
wenzelm@60943
   118
  val unsafe_dest: int option -> attribute
wenzelm@60943
   119
  val unsafe_elim: int option -> attribute
wenzelm@60943
   120
  val unsafe_intro: int option -> attribute
wenzelm@18728
   121
  val rule_del: attribute
wenzelm@61327
   122
  val rule_tac: Proof.context -> thm list -> thm list -> int -> tactic
wenzelm@61327
   123
  val standard_tac: Proof.context -> thm list -> tactic
wenzelm@30513
   124
  val cla_modifiers: Method.modifier parser list
wenzelm@42793
   125
  val cla_method:
wenzelm@42793
   126
    (Proof.context -> tactic) -> (Proof.context -> Proof.method) context_parser
wenzelm@42793
   127
  val cla_method':
wenzelm@42793
   128
    (Proof.context -> int -> tactic) -> (Proof.context -> Proof.method) context_parser
wenzelm@5841
   129
end;
wenzelm@5841
   130
clasohm@0
   131
wenzelm@42799
   132
functor Classical(Data: CLASSICAL_DATA): CLASSICAL =
clasohm@0
   133
struct
clasohm@0
   134
wenzelm@18534
   135
(** classical elimination rules **)
wenzelm@18534
   136
wenzelm@18534
   137
(*
wenzelm@18534
   138
Classical reasoning requires stronger elimination rules.  For
wenzelm@18534
   139
instance, make_elim of Pure transforms the HOL rule injD into
wenzelm@18534
   140
wenzelm@18534
   141
    [| inj f; f x = f y; x = y ==> PROP W |] ==> PROP W
wenzelm@18534
   142
wenzelm@26938
   143
Such rules can cause fast_tac to fail and blast_tac to report "PROOF
wenzelm@59119
   144
FAILED"; classical_rule will strengthen this to
wenzelm@18534
   145
wenzelm@18534
   146
    [| inj f; ~ W ==> f x = f y; x = y ==> W |] ==> W
wenzelm@18534
   147
*)
wenzelm@18534
   148
wenzelm@59970
   149
fun classical_rule ctxt rule =
wenzelm@59970
   150
  if is_some (Object_Logic.elim_concl ctxt rule) then
wenzelm@18534
   151
    let
wenzelm@60817
   152
      val thy = Proof_Context.theory_of ctxt;
wenzelm@42792
   153
      val rule' = rule RS Data.classical;
wenzelm@18534
   154
      val concl' = Thm.concl_of rule';
wenzelm@18534
   155
      fun redundant_hyp goal =
wenzelm@19257
   156
        concl' aconv Logic.strip_assums_concl goal orelse
wenzelm@18534
   157
          (case Logic.strip_assums_hyp goal of
wenzelm@18534
   158
            hyp :: hyps => exists (fn t => t aconv hyp) hyps
wenzelm@18534
   159
          | _ => false);
wenzelm@18534
   160
      val rule'' =
wenzelm@18534
   161
        rule' |> ALLGOALS (SUBGOAL (fn (goal, i) =>
wenzelm@18534
   162
          if i = 1 orelse redundant_hyp goal
wenzelm@60757
   163
          then eresolve_tac ctxt [thin_rl] i
wenzelm@18534
   164
          else all_tac))
wenzelm@18534
   165
        |> Seq.hd
wenzelm@21963
   166
        |> Drule.zero_var_indexes;
wenzelm@60817
   167
    in if Thm.equiv_thm thy (rule, rule'') then rule else rule'' end
wenzelm@18534
   168
  else rule;
wenzelm@18534
   169
wenzelm@23594
   170
(*flatten nested meta connectives in prems*)
wenzelm@59970
   171
fun flat_rule ctxt =
wenzelm@59970
   172
  Conv.fconv_rule (Conv.prems_conv ~1 (Object_Logic.atomize_prems ctxt));
wenzelm@18534
   173
wenzelm@18534
   174
paulson@1800
   175
(*** Useful tactics for classical reasoning ***)
clasohm@0
   176
wenzelm@10736
   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.*)
wenzelm@58963
   180
fun contr_tac ctxt =
wenzelm@59498
   181
  eresolve_tac ctxt [Data.not_elim] THEN' (eq_assume_tac ORELSE' assume_tac ctxt);
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... *)
wenzelm@59498
   185
fun mp_tac ctxt i =
wenzelm@59498
   186
  eresolve_tac ctxt [Data.not_elim, Data.imp_elim] i THEN assume_tac ctxt i;
clasohm@0
   187
clasohm@0
   188
(*Like mp_tac but instantiates no variables*)
wenzelm@58957
   189
fun eq_mp_tac ctxt i = ematch_tac ctxt [Data.not_elim, Data.imp_elim] i THEN eq_assume_tac i;
clasohm@0
   190
clasohm@0
   191
(*Creates rules to eliminate ~A, from rules to introduce A*)
wenzelm@26412
   192
fun swapify intrs = intrs RLN (2, [Data.swap]);
wenzelm@61853
   193
val swapped = Thm.rule_attribute [] (fn _ => fn th => th RSN (2, Data.swap));
clasohm@0
   194
clasohm@0
   195
(*Uses introduction rules in the normal way, or on negated assumptions,
clasohm@0
   196
  trying rules in order. *)
wenzelm@58963
   197
fun swap_res_tac ctxt rls =
wenzelm@61056
   198
  let
wenzelm@61056
   199
    val transfer = Thm.transfer (Proof_Context.theory_of ctxt);
wenzelm@61056
   200
    fun addrl rl brls = (false, transfer rl) :: (true, transfer rl RSN (2, Data.swap)) :: brls;
wenzelm@61056
   201
  in
wenzelm@58963
   202
    assume_tac ctxt ORELSE'
wenzelm@58963
   203
    contr_tac ctxt ORELSE'
wenzelm@59498
   204
    biresolve_tac ctxt (fold_rev addrl rls [])
wenzelm@42792
   205
  end;
clasohm@0
   206
wenzelm@60943
   207
(*Duplication of unsafe rules, for complete provers*)
wenzelm@42792
   208
fun dup_intr th = zero_var_indexes (th RS Data.classical);
lcp@681
   209
wenzelm@59970
   210
fun dup_elim ctxt th =
wenzelm@59970
   211
  let val rl = (th RSN (2, revcut_rl)) |> Thm.assumption (SOME ctxt) 2 |> Seq.hd;
wenzelm@59498
   212
  in rule_by_tactic ctxt (TRYALL (eresolve_tac ctxt [revcut_rl])) rl end;
wenzelm@36546
   213
lcp@1073
   214
paulson@1800
   215
(**** Classical rule sets ****)
clasohm@0
   216
wenzelm@61055
   217
type rule = thm * (thm * thm list) * (thm * thm list);
wenzelm@61055
   218
  (*external form, internal form (possibly swapped), dup form (possibly swapped)*)
wenzelm@61055
   219
wenzelm@42812
   220
type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net;
wenzelm@42812
   221
type wrapper = (int -> tactic) -> int -> tactic;
wenzelm@42812
   222
clasohm@0
   223
datatype claset =
wenzelm@42793
   224
  CS of
wenzelm@60945
   225
   {safeIs: rule Item_Net.T,  (*safe introduction rules*)
wenzelm@60945
   226
    safeEs: rule Item_Net.T,  (*safe elimination rules*)
wenzelm@60945
   227
    unsafeIs: rule Item_Net.T,  (*unsafe introduction rules*)
wenzelm@60945
   228
    unsafeEs: rule Item_Net.T,  (*unsafe elimination rules*)
wenzelm@60945
   229
    swrappers: (string * (Proof.context -> wrapper)) list,  (*for transforming safe_step_tac*)
wenzelm@60945
   230
    uwrappers: (string * (Proof.context -> wrapper)) list,  (*for transforming step_tac*)
wenzelm@60945
   231
    safe0_netpair: netpair,  (*nets for trivial cases*)
wenzelm@60945
   232
    safep_netpair: netpair,  (*nets for >0 subgoals*)
wenzelm@60945
   233
    unsafe_netpair: netpair,  (*nets for unsafe rules*)
wenzelm@60945
   234
    dup_netpair: netpair,  (*nets for duplication*)
wenzelm@60945
   235
    extra_netpair: Context_Rules.netpair};  (*nets for extra rules*)
wenzelm@60945
   236
wenzelm@60945
   237
val empty_rules: rule Item_Net.T =
wenzelm@60945
   238
  Item_Net.init (Thm.eq_thm_prop o apply2 #1) (single o Thm.full_prop_of o #1);
clasohm@0
   239
wenzelm@6502
   240
val empty_netpair = (Net.empty, Net.empty);
wenzelm@6502
   241
wenzelm@10736
   242
val empty_cs =
wenzelm@42793
   243
  CS
wenzelm@60945
   244
   {safeIs = empty_rules,
wenzelm@60945
   245
    safeEs = empty_rules,
wenzelm@60945
   246
    unsafeIs = empty_rules,
wenzelm@60945
   247
    unsafeEs = empty_rules,
wenzelm@42793
   248
    swrappers = [],
wenzelm@42793
   249
    uwrappers = [],
wenzelm@42793
   250
    safe0_netpair = empty_netpair,
wenzelm@42793
   251
    safep_netpair = empty_netpair,
wenzelm@60943
   252
    unsafe_netpair = empty_netpair,
wenzelm@42793
   253
    dup_netpair = empty_netpair,
wenzelm@60942
   254
    extra_netpair = empty_netpair};
clasohm@0
   255
oheimb@4653
   256
fun rep_cs (CS args) = args;
lcp@1073
   257
wenzelm@4079
   258
paulson@1800
   259
(*** Adding (un)safe introduction or elimination rules.
lcp@1073
   260
lcp@1073
   261
    In case of overlap, new rules are tried BEFORE old ones!!
paulson@1800
   262
***)
clasohm@0
   263
wenzelm@61055
   264
fun joinrules (intrs, elims) = map (pair true) elims @ map (pair false) intrs;
lcp@1073
   265
wenzelm@10736
   266
(*Priority: prefer rules with fewest subgoals,
paulson@1231
   267
  then rules added most recently (preferring the head of the list).*)
lcp@1073
   268
fun tag_brls k [] = []
lcp@1073
   269
  | tag_brls k (brl::brls) =
wenzelm@10736
   270
      (1000000*subgoals_of_brl brl + k, brl) ::
lcp@1073
   271
      tag_brls (k+1) brls;
lcp@1073
   272
wenzelm@12401
   273
fun tag_brls' _ _ [] = []
wenzelm@12401
   274
  | tag_brls' w k (brl::brls) = ((w, k), brl) :: tag_brls' w (k + 1) brls;
wenzelm@10736
   275
wenzelm@23178
   276
fun insert_tagged_list rls = fold_rev Tactic.insert_tagged_brl rls;
lcp@1073
   277
lcp@1073
   278
(*Insert into netpair that already has nI intr rules and nE elim rules.
lcp@1073
   279
  Count the intr rules double (to account for swapify).  Negate to give the
lcp@1073
   280
  new insertions the lowest priority.*)
wenzelm@12376
   281
fun insert (nI, nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules;
wenzelm@61055
   282
fun insert' w (nI, nE) = insert_tagged_list o tag_brls' w (~(nI + nE)) o joinrules;
lcp@1073
   283
wenzelm@23178
   284
fun delete_tagged_list rls = fold_rev Tactic.delete_tagged_brl rls;
wenzelm@12362
   285
fun delete x = delete_tagged_list (joinrules x);
paulson@1800
   286
wenzelm@61268
   287
fun bad_thm ctxt msg th = error (msg ^ "\n" ^ Thm.string_of_thm ctxt th);
wenzelm@42793
   288
wenzelm@60945
   289
fun make_elim ctxt th =
wenzelm@60945
   290
  if has_fewer_prems 1 th then bad_thm ctxt "Ill-formed destruction rule" th
wenzelm@42793
   291
  else Tactic.make_elim th;
wenzelm@42790
   292
wenzelm@60945
   293
fun warn_thm ctxt msg th =
wenzelm@60945
   294
  if Context_Position.is_really_visible ctxt
wenzelm@61268
   295
  then warning (msg ^ Thm.string_of_thm ctxt th) else ();
wenzelm@42793
   296
wenzelm@60945
   297
fun warn_rules ctxt msg rules (r: rule) =
wenzelm@60945
   298
  Item_Net.member rules r andalso (warn_thm ctxt msg (#1 r); true);
wenzelm@42807
   299
wenzelm@60945
   300
fun warn_claset ctxt r (CS {safeIs, safeEs, unsafeIs, unsafeEs, ...}) =
wenzelm@60945
   301
  warn_rules ctxt "Rule already declared as safe introduction (intro!)\n" safeIs r orelse
wenzelm@60945
   302
  warn_rules ctxt "Rule already declared as safe elimination (elim!)\n" safeEs r orelse
wenzelm@60945
   303
  warn_rules ctxt "Rule already declared as introduction (intro)\n" unsafeIs r orelse
wenzelm@60945
   304
  warn_rules ctxt "Rule already declared as elimination (elim)\n" unsafeEs r;
paulson@1927
   305
wenzelm@12376
   306
wenzelm@60946
   307
(*** add rules ***)
lcp@982
   308
wenzelm@60945
   309
fun add_safe_intro w r
wenzelm@60943
   310
    (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   311
      safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60945
   312
  if Item_Net.member safeIs r then cs
paulson@1927
   313
  else
wenzelm@42790
   314
    let
wenzelm@61055
   315
      val (th, rl, _) = r;
wenzelm@23594
   316
      val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
wenzelm@61055
   317
        List.partition (Thm.no_prems o fst) [rl];
wenzelm@42810
   318
      val nI = Item_Net.length safeIs + 1;
wenzelm@42810
   319
      val nE = Item_Net.length safeEs;
wenzelm@42790
   320
    in
wenzelm@42790
   321
      CS
wenzelm@60945
   322
       {safeIs = Item_Net.update r safeIs,
wenzelm@61055
   323
        safe0_netpair = insert (nI, nE) (map fst safe0_rls, maps snd safe0_rls) safe0_netpair,
wenzelm@61055
   324
        safep_netpair = insert (nI, nE) (map fst safep_rls, maps snd safep_rls) safep_netpair,
wenzelm@42790
   325
        safeEs = safeEs,
wenzelm@60943
   326
        unsafeIs = unsafeIs,
wenzelm@60943
   327
        unsafeEs = unsafeEs,
wenzelm@42790
   328
        swrappers = swrappers,
wenzelm@42790
   329
        uwrappers = uwrappers,
wenzelm@60943
   330
        unsafe_netpair = unsafe_netpair,
wenzelm@42790
   331
        dup_netpair = dup_netpair,
wenzelm@60944
   332
        extra_netpair = insert' (the_default 0 w) (nI, nE) ([th], []) extra_netpair}
wenzelm@42790
   333
    end;
lcp@1073
   334
wenzelm@60945
   335
fun add_safe_elim w r
wenzelm@60943
   336
    (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   337
      safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60945
   338
  if Item_Net.member safeEs r then cs
paulson@1927
   339
  else
wenzelm@42790
   340
    let
wenzelm@61055
   341
      val (th, rl, _) = r;
wenzelm@18534
   342
      val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
wenzelm@61055
   343
        List.partition (fn (rl, _) => Thm.nprems_of rl = 1) [rl];
wenzelm@42810
   344
      val nI = Item_Net.length safeIs;
wenzelm@42810
   345
      val nE = Item_Net.length safeEs + 1;
wenzelm@42790
   346
    in
wenzelm@42790
   347
      CS
wenzelm@60945
   348
       {safeEs = Item_Net.update r safeEs,
wenzelm@61055
   349
        safe0_netpair = insert (nI, nE) ([], map fst safe0_rls) safe0_netpair,
wenzelm@61055
   350
        safep_netpair = insert (nI, nE) ([], map fst safep_rls) safep_netpair,
wenzelm@42790
   351
        safeIs = safeIs,
wenzelm@60943
   352
        unsafeIs = unsafeIs,
wenzelm@60943
   353
        unsafeEs = unsafeEs,
wenzelm@42790
   354
        swrappers = swrappers,
wenzelm@42790
   355
        uwrappers = uwrappers,
wenzelm@60943
   356
        unsafe_netpair = unsafe_netpair,
wenzelm@42790
   357
        dup_netpair = dup_netpair,
wenzelm@60944
   358
        extra_netpair = insert' (the_default 0 w) (nI, nE) ([], [th]) extra_netpair}
wenzelm@42790
   359
    end;
clasohm@0
   360
wenzelm@60945
   361
fun add_unsafe_intro w r
wenzelm@60943
   362
    (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   363
      safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60945
   364
  if Item_Net.member unsafeIs r then cs
paulson@1927
   365
  else
wenzelm@42790
   366
    let
wenzelm@61055
   367
      val (th, rl, dup_rl) = r;
wenzelm@60943
   368
      val nI = Item_Net.length unsafeIs + 1;
wenzelm@60943
   369
      val nE = Item_Net.length unsafeEs;
wenzelm@42790
   370
    in
wenzelm@42790
   371
      CS
wenzelm@60945
   372
       {unsafeIs = Item_Net.update r unsafeIs,
wenzelm@61055
   373
        unsafe_netpair = insert (nI, nE) ([fst rl], snd rl) unsafe_netpair,
wenzelm@61055
   374
        dup_netpair = insert (nI, nE) ([fst dup_rl], snd dup_rl) dup_netpair,
wenzelm@42790
   375
        safeIs = safeIs,
wenzelm@42790
   376
        safeEs = safeEs,
wenzelm@60943
   377
        unsafeEs = unsafeEs,
wenzelm@42790
   378
        swrappers = swrappers,
wenzelm@42790
   379
        uwrappers = uwrappers,
wenzelm@9938
   380
        safe0_netpair = safe0_netpair,
wenzelm@9938
   381
        safep_netpair = safep_netpair,
wenzelm@60942
   382
        extra_netpair = insert' (the_default 1 w) (nI, nE) ([th], []) extra_netpair}
wenzelm@60945
   383
    end;
lcp@1073
   384
wenzelm@60945
   385
fun add_unsafe_elim w r
wenzelm@60943
   386
    (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   387
      safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60945
   388
  if Item_Net.member unsafeEs r then cs
paulson@1927
   389
  else
wenzelm@42790
   390
    let
wenzelm@61055
   391
      val (th, rl, dup_rl) = r;
wenzelm@60943
   392
      val nI = Item_Net.length unsafeIs;
wenzelm@60943
   393
      val nE = Item_Net.length unsafeEs + 1;
wenzelm@42790
   394
    in
wenzelm@42790
   395
      CS
wenzelm@60945
   396
       {unsafeEs = Item_Net.update r unsafeEs,
wenzelm@61055
   397
        unsafe_netpair = insert (nI, nE) ([], [fst rl]) unsafe_netpair,
wenzelm@61055
   398
        dup_netpair = insert (nI, nE) ([], [fst dup_rl]) dup_netpair,
wenzelm@42790
   399
        safeIs = safeIs,
wenzelm@42790
   400
        safeEs = safeEs,
wenzelm@60943
   401
        unsafeIs = unsafeIs,
wenzelm@42790
   402
        swrappers = swrappers,
wenzelm@42790
   403
        uwrappers = uwrappers,
wenzelm@9938
   404
        safe0_netpair = safe0_netpair,
wenzelm@9938
   405
        safep_netpair = safep_netpair,
wenzelm@60942
   406
        extra_netpair = insert' (the_default 1 w) (nI, nE) ([], [th]) extra_netpair}
wenzelm@42790
   407
    end;
clasohm@0
   408
wenzelm@61056
   409
fun trim_context (th, (th1, ths1), (th2, ths2)) =
wenzelm@61056
   410
  (Thm.trim_context th,
wenzelm@61056
   411
    (Thm.trim_context th1, map Thm.trim_context ths1),
wenzelm@61056
   412
    (Thm.trim_context th2, map Thm.trim_context ths2));
wenzelm@61056
   413
wenzelm@60946
   414
fun addSI w ctxt th (cs as CS {safeIs, ...}) =
wenzelm@60946
   415
  let
wenzelm@60946
   416
    val th' = flat_rule ctxt th;
wenzelm@61055
   417
    val rl = (th', swapify [th']);
wenzelm@61056
   418
    val r = trim_context (th, rl, rl);
wenzelm@60946
   419
    val _ =
wenzelm@60946
   420
      warn_rules ctxt "Ignoring duplicate safe introduction (intro!)\n" safeIs r orelse
wenzelm@60946
   421
      warn_claset ctxt r cs;
wenzelm@60946
   422
  in add_safe_intro w r cs end;
wenzelm@60946
   423
wenzelm@60946
   424
fun addSE w ctxt th (cs as CS {safeEs, ...}) =
wenzelm@60946
   425
  let
wenzelm@60946
   426
    val _ = has_fewer_prems 1 th andalso bad_thm ctxt "Ill-formed elimination rule" th;
wenzelm@60946
   427
    val th' = classical_rule ctxt (flat_rule ctxt th);
wenzelm@61055
   428
    val rl = (th', []);
wenzelm@61056
   429
    val r = trim_context (th, rl, rl);
wenzelm@60946
   430
    val _ =
wenzelm@60946
   431
      warn_rules ctxt "Ignoring duplicate safe elimination (elim!)\n" safeEs r orelse
wenzelm@60946
   432
      warn_claset ctxt r cs;
wenzelm@60946
   433
  in add_safe_elim w r cs end;
wenzelm@60946
   434
wenzelm@60946
   435
fun addSD w ctxt th = addSE w ctxt (make_elim ctxt th);
wenzelm@60946
   436
wenzelm@60945
   437
fun addI w ctxt th (cs as CS {unsafeIs, ...}) =
wenzelm@60945
   438
  let
wenzelm@60945
   439
    val th' = flat_rule ctxt th;
wenzelm@61055
   440
    val dup_th' = dup_intr th' handle THM _ => bad_thm ctxt "Ill-formed introduction rule" th;
wenzelm@61056
   441
    val r = trim_context (th, (th', swapify [th']), (dup_th', swapify [dup_th']));
wenzelm@60945
   442
    val _ =
wenzelm@60945
   443
      warn_rules ctxt "Ignoring duplicate introduction (intro)\n" unsafeIs r orelse
wenzelm@60945
   444
      warn_claset ctxt r cs;
wenzelm@60945
   445
  in add_unsafe_intro w r cs end;
wenzelm@42793
   446
wenzelm@60945
   447
fun addE w ctxt th (cs as CS {unsafeEs, ...}) =
wenzelm@60945
   448
  let
wenzelm@60945
   449
    val _ = has_fewer_prems 1 th andalso bad_thm ctxt "Ill-formed elimination rule" th;
wenzelm@60945
   450
    val th' = classical_rule ctxt (flat_rule ctxt th);
wenzelm@61055
   451
    val dup_th' = dup_elim ctxt th' handle THM _ => bad_thm ctxt "Ill-formed elimination rule" th;
wenzelm@61056
   452
    val r = trim_context (th, (th', []), (dup_th', []));
wenzelm@60945
   453
    val _ =
wenzelm@60945
   454
      warn_rules ctxt "Ignoring duplicate elimination (elim)\n" unsafeEs r orelse
wenzelm@60945
   455
      warn_claset ctxt r cs;
wenzelm@60945
   456
  in add_unsafe_elim w r cs end;
wenzelm@60945
   457
wenzelm@60945
   458
fun addD w ctxt th = addE w ctxt (make_elim ctxt th);
clasohm@0
   459
lcp@1073
   460
wenzelm@60946
   461
(*** delete rules ***)
wenzelm@60946
   462
wenzelm@60946
   463
local
paulson@1800
   464
wenzelm@60946
   465
fun del_safe_intro (r: rule)
wenzelm@60946
   466
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60946
   467
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60946
   468
  let
wenzelm@61055
   469
    val (th, rl, _) = r;
wenzelm@61055
   470
    val (safe0_rls, safep_rls) = List.partition (Thm.no_prems o fst) [rl];
wenzelm@60946
   471
  in
wenzelm@60946
   472
    CS
wenzelm@61055
   473
     {safe0_netpair = delete (map fst safe0_rls, maps snd safe0_rls) safe0_netpair,
wenzelm@61055
   474
      safep_netpair = delete (map fst safep_rls, maps snd safep_rls) safep_netpair,
wenzelm@60946
   475
      safeIs = Item_Net.remove r safeIs,
wenzelm@60946
   476
      safeEs = safeEs,
wenzelm@60946
   477
      unsafeIs = unsafeIs,
wenzelm@60946
   478
      unsafeEs = unsafeEs,
wenzelm@60946
   479
      swrappers = swrappers,
wenzelm@60946
   480
      uwrappers = uwrappers,
wenzelm@60946
   481
      unsafe_netpair = unsafe_netpair,
wenzelm@60946
   482
      dup_netpair = dup_netpair,
wenzelm@61055
   483
      extra_netpair = delete ([th], []) extra_netpair}
wenzelm@60946
   484
  end;
paulson@1800
   485
wenzelm@60946
   486
fun del_safe_elim (r: rule)
wenzelm@60946
   487
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60946
   488
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60946
   489
  let
wenzelm@61055
   490
    val (th, rl, _) = r;
wenzelm@61055
   491
    val (safe0_rls, safep_rls) = List.partition (fn (rl, _) => Thm.nprems_of rl = 1) [rl];
wenzelm@60946
   492
  in
wenzelm@60946
   493
    CS
wenzelm@61055
   494
     {safe0_netpair = delete ([], map fst safe0_rls) safe0_netpair,
wenzelm@61055
   495
      safep_netpair = delete ([], map fst safep_rls) safep_netpair,
wenzelm@60946
   496
      safeIs = safeIs,
wenzelm@60946
   497
      safeEs = Item_Net.remove r safeEs,
wenzelm@60946
   498
      unsafeIs = unsafeIs,
wenzelm@60946
   499
      unsafeEs = unsafeEs,
wenzelm@60946
   500
      swrappers = swrappers,
wenzelm@60946
   501
      uwrappers = uwrappers,
wenzelm@60946
   502
      unsafe_netpair = unsafe_netpair,
wenzelm@60946
   503
      dup_netpair = dup_netpair,
wenzelm@61055
   504
      extra_netpair = delete ([], [th]) extra_netpair}
wenzelm@60946
   505
  end;
paulson@1800
   506
wenzelm@61055
   507
fun del_unsafe_intro (r as (th, (th', swapped_th'), (dup_th', swapped_dup_th')))
wenzelm@60946
   508
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60946
   509
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60946
   510
  CS
wenzelm@61055
   511
   {unsafe_netpair = delete ([th'], swapped_th') unsafe_netpair,
wenzelm@61055
   512
    dup_netpair = delete ([dup_th'], swapped_dup_th') dup_netpair,
wenzelm@60946
   513
    safeIs = safeIs,
wenzelm@60946
   514
    safeEs = safeEs,
wenzelm@60946
   515
    unsafeIs = Item_Net.remove r unsafeIs,
wenzelm@60946
   516
    unsafeEs = unsafeEs,
wenzelm@60946
   517
    swrappers = swrappers,
wenzelm@60946
   518
    uwrappers = uwrappers,
wenzelm@60946
   519
    safe0_netpair = safe0_netpair,
wenzelm@60946
   520
    safep_netpair = safep_netpair,
wenzelm@61055
   521
    extra_netpair = delete ([th], []) extra_netpair};
paulson@1800
   522
wenzelm@61055
   523
fun del_unsafe_elim (r as (th, (th', _), (dup_th', _)))
wenzelm@60946
   524
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60946
   525
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60946
   526
  CS
wenzelm@60946
   527
   {unsafe_netpair = delete ([], [th']) unsafe_netpair,
wenzelm@61055
   528
    dup_netpair = delete ([], [dup_th']) dup_netpair,
wenzelm@60946
   529
    safeIs = safeIs,
wenzelm@60946
   530
    safeEs = safeEs,
wenzelm@60946
   531
    unsafeIs = unsafeIs,
wenzelm@60946
   532
    unsafeEs = Item_Net.remove r unsafeEs,
wenzelm@60946
   533
    swrappers = swrappers,
wenzelm@60946
   534
    uwrappers = uwrappers,
wenzelm@60946
   535
    safe0_netpair = safe0_netpair,
wenzelm@60946
   536
    safep_netpair = safep_netpair,
wenzelm@61055
   537
    extra_netpair = delete ([], [th]) extra_netpair};
paulson@1800
   538
wenzelm@60946
   539
fun del f rules th cs =
wenzelm@61055
   540
  fold f (Item_Net.lookup rules (th, (th, []), (th, []))) cs;
wenzelm@60946
   541
wenzelm@60946
   542
in
wenzelm@60946
   543
wenzelm@60945
   544
fun delrule ctxt th (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, ...}) =
wenzelm@60945
   545
  let
wenzelm@60945
   546
    val th' = Tactic.make_elim th;
wenzelm@61055
   547
    val r = (th, (th, []), (th, []));
wenzelm@61055
   548
    val r' = (th', (th', []), (th', []));
wenzelm@60945
   549
  in
wenzelm@60945
   550
    if Item_Net.member safeIs r orelse Item_Net.member safeEs r orelse
wenzelm@60945
   551
      Item_Net.member unsafeIs r orelse Item_Net.member unsafeEs r orelse
wenzelm@60945
   552
      Item_Net.member safeEs r' orelse Item_Net.member unsafeEs r'
wenzelm@54742
   553
    then
wenzelm@60942
   554
      cs
wenzelm@60946
   555
      |> del del_safe_intro safeIs th
wenzelm@60946
   556
      |> del del_safe_elim safeEs th
wenzelm@60946
   557
      |> del del_safe_elim safeEs th'
wenzelm@60946
   558
      |> del del_unsafe_intro unsafeIs th
wenzelm@60946
   559
      |> del del_unsafe_elim unsafeEs th
wenzelm@60946
   560
      |> del del_unsafe_elim unsafeEs th'
wenzelm@60945
   561
    else (warn_thm ctxt "Undeclared classical rule\n" th; cs)
wenzelm@9938
   562
  end;
paulson@1800
   563
wenzelm@60946
   564
end;
wenzelm@60946
   565
paulson@1800
   566
wenzelm@42793
   567
wenzelm@42793
   568
(** claset data **)
wenzelm@42790
   569
wenzelm@42793
   570
(* wrappers *)
wenzelm@42790
   571
haftmann@22674
   572
fun map_swrappers f
wenzelm@60943
   573
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   574
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60943
   575
  CS {safeIs = safeIs, safeEs = safeEs, unsafeIs = unsafeIs, unsafeEs = unsafeEs,
oheimb@4767
   576
    swrappers = f swrappers, uwrappers = uwrappers,
oheimb@4767
   577
    safe0_netpair = safe0_netpair, safep_netpair = safep_netpair,
wenzelm@60943
   578
    unsafe_netpair = unsafe_netpair, dup_netpair = dup_netpair, extra_netpair = extra_netpair};
oheimb@4767
   579
haftmann@22674
   580
fun map_uwrappers f
wenzelm@60943
   581
  (CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers,
wenzelm@60943
   582
    safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) =
wenzelm@60943
   583
  CS {safeIs = safeIs, safeEs = safeEs, unsafeIs = unsafeIs, unsafeEs = unsafeEs,
oheimb@4767
   584
    swrappers = swrappers, uwrappers = f uwrappers,
oheimb@4767
   585
    safe0_netpair = safe0_netpair, safep_netpair = safep_netpair,
wenzelm@60943
   586
    unsafe_netpair = unsafe_netpair, dup_netpair = dup_netpair, extra_netpair = extra_netpair};
oheimb@4767
   587
haftmann@22674
   588
wenzelm@42793
   589
(* merge_cs *)
lcp@982
   590
wenzelm@42810
   591
(*Merge works by adding all new rules of the 2nd claset into the 1st claset,
wenzelm@42810
   592
  in order to preserve priorities reliably.*)
wenzelm@42810
   593
wenzelm@42810
   594
fun merge_thms add thms1 thms2 =
wenzelm@42810
   595
  fold_rev (fn thm => if Item_Net.member thms1 thm then I else add thm) (Item_Net.content thms2);
wenzelm@42810
   596
wenzelm@60943
   597
fun merge_cs (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, ...},
wenzelm@60943
   598
    cs' as CS {safeIs = safeIs2, safeEs = safeEs2, unsafeIs = unsafeIs2, unsafeEs = unsafeEs2,
haftmann@22674
   599
      swrappers, uwrappers, ...}) =
wenzelm@24358
   600
  if pointer_eq (cs, cs') then cs
wenzelm@24358
   601
  else
wenzelm@42810
   602
    cs
wenzelm@60945
   603
    |> merge_thms (add_safe_intro NONE) safeIs safeIs2
wenzelm@60945
   604
    |> merge_thms (add_safe_elim NONE) safeEs safeEs2
wenzelm@60945
   605
    |> merge_thms (add_unsafe_intro NONE) unsafeIs unsafeIs2
wenzelm@60945
   606
    |> merge_thms (add_unsafe_elim NONE) unsafeEs unsafeEs2
wenzelm@42810
   607
    |> map_swrappers (fn ws => AList.merge (op =) (K true) (ws, swrappers))
wenzelm@42810
   608
    |> map_uwrappers (fn ws => AList.merge (op =) (K true) (ws, uwrappers));
wenzelm@42793
   609
wenzelm@42793
   610
wenzelm@42793
   611
(* data *)
wenzelm@42793
   612
wenzelm@42793
   613
structure Claset = Generic_Data
wenzelm@42793
   614
(
wenzelm@42793
   615
  type T = claset;
wenzelm@42793
   616
  val empty = empty_cs;
wenzelm@42793
   617
  val extend = I;
wenzelm@42793
   618
  val merge = merge_cs;
wenzelm@42793
   619
);
wenzelm@42793
   620
wenzelm@42793
   621
val claset_of = Claset.get o Context.Proof;
wenzelm@42793
   622
val rep_claset_of = rep_cs o claset_of;
wenzelm@42793
   623
wenzelm@42793
   624
val get_cs = Claset.get;
wenzelm@42793
   625
val map_cs = Claset.map;
wenzelm@42793
   626
wenzelm@51703
   627
fun map_theory_claset f thy =
wenzelm@51703
   628
  let
wenzelm@51703
   629
    val ctxt' = f (Proof_Context.init_global thy);
wenzelm@51703
   630
    val thy' = Proof_Context.theory_of ctxt';
wenzelm@51703
   631
  in Context.theory_map (Claset.map (K (claset_of ctxt'))) thy' end;
wenzelm@51703
   632
wenzelm@42793
   633
fun map_claset f = Context.proof_map (map_cs f);
wenzelm@42793
   634
fun put_claset cs = map_claset (K cs);
wenzelm@42793
   635
wenzelm@42793
   636
fun print_claset ctxt =
wenzelm@42793
   637
  let
wenzelm@60943
   638
    val {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, ...} = rep_claset_of ctxt;
wenzelm@61268
   639
    val pretty_thms = map (Thm.pretty_thm_item ctxt o #1) o Item_Net.content;
wenzelm@42793
   640
  in
wenzelm@42793
   641
    [Pretty.big_list "safe introduction rules (intro!):" (pretty_thms safeIs),
wenzelm@60943
   642
      Pretty.big_list "introduction rules (intro):" (pretty_thms unsafeIs),
wenzelm@42793
   643
      Pretty.big_list "safe elimination rules (elim!):" (pretty_thms safeEs),
wenzelm@60943
   644
      Pretty.big_list "elimination rules (elim):" (pretty_thms unsafeEs),
wenzelm@42793
   645
      Pretty.strs ("safe wrappers:" :: map #1 swrappers),
wenzelm@42793
   646
      Pretty.strs ("unsafe wrappers:" :: map #1 uwrappers)]
wenzelm@56334
   647
    |> Pretty.writeln_chunks
wenzelm@42793
   648
  end;
wenzelm@42793
   649
wenzelm@42793
   650
wenzelm@42793
   651
(* old-style declarations *)
wenzelm@42793
   652
wenzelm@60945
   653
fun decl f (ctxt, ths) = map_claset (fold_rev (f ctxt) ths) ctxt;
wenzelm@42793
   654
wenzelm@42793
   655
val op addSIs = decl (addSI NONE);
wenzelm@42793
   656
val op addSEs = decl (addSE NONE);
wenzelm@42793
   657
val op addSDs = decl (addSD NONE);
wenzelm@42793
   658
val op addIs = decl (addI NONE);
wenzelm@42793
   659
val op addEs = decl (addE NONE);
wenzelm@42793
   660
val op addDs = decl (addD NONE);
wenzelm@42793
   661
val op delrules = decl delrule;
wenzelm@42793
   662
wenzelm@42793
   663
wenzelm@42793
   664
wenzelm@42793
   665
(*** Modifying the wrapper tacticals ***)
wenzelm@42793
   666
wenzelm@42793
   667
fun appSWrappers ctxt = fold (fn (_, w) => w ctxt) (#swrappers (rep_claset_of ctxt));
wenzelm@42793
   668
fun appWrappers ctxt = fold (fn (_, w) => w ctxt) (#uwrappers (rep_claset_of ctxt));
wenzelm@42793
   669
wenzelm@42793
   670
fun update_warn msg (p as (key : string, _)) xs =
wenzelm@42793
   671
  (if AList.defined (op =) xs key then warning msg else (); AList.update (op =) p xs);
wenzelm@42793
   672
wenzelm@42793
   673
fun delete_warn msg (key : string) xs =
wenzelm@42793
   674
  if AList.defined (op =) xs key then AList.delete (op =) key xs
wenzelm@42793
   675
  else (warning msg; xs);
wenzelm@42793
   676
wenzelm@42793
   677
(*Add/replace a safe wrapper*)
wenzelm@51703
   678
fun ctxt addSWrapper new_swrapper = ctxt |> map_claset
wenzelm@51703
   679
  (map_swrappers (update_warn ("Overwriting safe wrapper " ^ fst new_swrapper) new_swrapper));
wenzelm@42793
   680
wenzelm@42793
   681
(*Add/replace an unsafe wrapper*)
wenzelm@51703
   682
fun ctxt addWrapper new_uwrapper = ctxt |> map_claset
wenzelm@51703
   683
  (map_uwrappers (update_warn ("Overwriting unsafe wrapper " ^ fst new_uwrapper) new_uwrapper));
wenzelm@42793
   684
wenzelm@42793
   685
(*Remove a safe wrapper*)
wenzelm@51703
   686
fun ctxt delSWrapper name = ctxt |> map_claset
wenzelm@51703
   687
  (map_swrappers (delete_warn ("No such safe wrapper in claset: " ^ name) name));
wenzelm@42793
   688
wenzelm@42793
   689
(*Remove an unsafe wrapper*)
wenzelm@51703
   690
fun ctxt delWrapper name = ctxt |> map_claset
wenzelm@51703
   691
  (map_uwrappers (delete_warn ("No such unsafe wrapper in claset: " ^ name) name));
wenzelm@42793
   692
wenzelm@42793
   693
(* compose a safe tactic alternatively before/after safe_step_tac *)
wenzelm@51717
   694
fun ctxt addSbefore (name, tac1) =
wenzelm@51717
   695
  ctxt addSWrapper (name, fn ctxt => fn tac2 => tac1 ctxt ORELSE' tac2);
wenzelm@51717
   696
fun ctxt addSafter (name, tac2) =
wenzelm@51717
   697
  ctxt addSWrapper (name, fn ctxt => fn tac1 => tac1 ORELSE' tac2 ctxt);
wenzelm@42793
   698
wenzelm@42793
   699
(*compose a tactic alternatively before/after the step tactic *)
wenzelm@51717
   700
fun ctxt addbefore (name, tac1) =
wenzelm@51717
   701
  ctxt addWrapper (name, fn ctxt => fn tac2 => tac1 ctxt APPEND' tac2);
wenzelm@51717
   702
fun ctxt addafter (name, tac2) =
wenzelm@51717
   703
  ctxt addWrapper (name, fn ctxt => fn tac1 => tac1 APPEND' tac2 ctxt);
wenzelm@42793
   704
wenzelm@58957
   705
fun ctxt addD2 (name, thm) =
wenzelm@59498
   706
  ctxt addafter (name, fn ctxt' => dresolve_tac ctxt' [thm] THEN' assume_tac ctxt');
wenzelm@58957
   707
fun ctxt addE2 (name, thm) =
wenzelm@59498
   708
  ctxt addafter (name, fn ctxt' => eresolve_tac ctxt' [thm] THEN' assume_tac ctxt');
wenzelm@58957
   709
fun ctxt addSD2 (name, thm) =
wenzelm@58957
   710
  ctxt addSafter (name, fn ctxt' => dmatch_tac ctxt' [thm] THEN' eq_assume_tac);
wenzelm@58957
   711
fun ctxt addSE2 (name, thm) =
wenzelm@58957
   712
  ctxt addSafter (name, fn ctxt' => ematch_tac ctxt' [thm] THEN' eq_assume_tac);
wenzelm@42793
   713
paulson@1711
   714
lcp@982
   715
paulson@1800
   716
(**** Simple tactics for theorem proving ****)
clasohm@0
   717
clasohm@0
   718
(*Attack subgoals using safe inferences -- matching, not resolution*)
wenzelm@42793
   719
fun safe_step_tac ctxt =
wenzelm@42793
   720
  let val {safe0_netpair, safep_netpair, ...} = rep_claset_of ctxt in
wenzelm@42793
   721
    appSWrappers ctxt
wenzelm@42793
   722
      (FIRST'
wenzelm@42793
   723
       [eq_assume_tac,
wenzelm@58957
   724
        eq_mp_tac ctxt,
wenzelm@59164
   725
        bimatch_from_nets_tac ctxt safe0_netpair,
wenzelm@51798
   726
        FIRST' (map (fn tac => tac ctxt) Data.hyp_subst_tacs),
wenzelm@59164
   727
        bimatch_from_nets_tac ctxt safep_netpair])
wenzelm@42793
   728
  end;
clasohm@0
   729
oheimb@5757
   730
(*Repeatedly attack a subgoal using safe inferences -- it's deterministic!*)
wenzelm@42793
   731
fun safe_steps_tac ctxt =
wenzelm@42793
   732
  REPEAT_DETERM1 o (fn i => COND (has_fewer_prems i) no_tac (safe_step_tac ctxt i));
oheimb@5757
   733
clasohm@0
   734
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*)
wenzelm@42793
   735
fun safe_tac ctxt = REPEAT_DETERM1 (FIRSTGOAL (safe_steps_tac ctxt));
lcp@747
   736
paulson@3705
   737
paulson@3705
   738
(*** Clarify_tac: do safe steps without causing branching ***)
paulson@3705
   739
wenzelm@42790
   740
fun nsubgoalsP n (k, brl) = (subgoals_of_brl brl = n);
paulson@3705
   741
paulson@3705
   742
(*version of bimatch_from_nets_tac that only applies rules that
paulson@3705
   743
  create precisely n subgoals.*)
wenzelm@59164
   744
fun n_bimatch_from_nets_tac ctxt n =
wenzelm@59164
   745
  biresolution_from_nets_tac ctxt (order_list o filter (nsubgoalsP n)) true;
paulson@3705
   746
wenzelm@58957
   747
fun eq_contr_tac ctxt i = ematch_tac ctxt [Data.not_elim] i THEN eq_assume_tac i;
wenzelm@58957
   748
fun eq_assume_contr_tac ctxt = eq_assume_tac ORELSE' eq_contr_tac ctxt;
paulson@3705
   749
paulson@3705
   750
(*Two-way branching is allowed only if one of the branches immediately closes*)
wenzelm@58957
   751
fun bimatch2_tac ctxt netpair i =
wenzelm@59164
   752
  n_bimatch_from_nets_tac ctxt 2 netpair i THEN
wenzelm@58957
   753
  (eq_assume_contr_tac ctxt i ORELSE eq_assume_contr_tac ctxt (i + 1));
paulson@3705
   754
paulson@3705
   755
(*Attack subgoals using safe inferences -- matching, not resolution*)
wenzelm@42793
   756
fun clarify_step_tac ctxt =
wenzelm@42793
   757
  let val {safe0_netpair, safep_netpair, ...} = rep_claset_of ctxt in
wenzelm@42793
   758
    appSWrappers ctxt
wenzelm@42793
   759
     (FIRST'
wenzelm@58957
   760
       [eq_assume_contr_tac ctxt,
wenzelm@59164
   761
        bimatch_from_nets_tac ctxt safe0_netpair,
wenzelm@51798
   762
        FIRST' (map (fn tac => tac ctxt) Data.hyp_subst_tacs),
wenzelm@59164
   763
        n_bimatch_from_nets_tac ctxt 1 safep_netpair,
wenzelm@58957
   764
        bimatch2_tac ctxt safep_netpair])
wenzelm@42793
   765
  end;
paulson@3705
   766
wenzelm@42793
   767
fun clarify_tac ctxt = SELECT_GOAL (REPEAT_DETERM (clarify_step_tac ctxt 1));
paulson@3705
   768
paulson@3705
   769
paulson@3705
   770
(*** Unsafe steps instantiate variables or lose information ***)
paulson@3705
   771
paulson@4066
   772
(*Backtracking is allowed among the various these unsafe ways of
paulson@4066
   773
  proving a subgoal.  *)
wenzelm@42793
   774
fun inst0_step_tac ctxt =
wenzelm@58963
   775
  assume_tac ctxt APPEND'
wenzelm@58963
   776
  contr_tac ctxt APPEND'
wenzelm@59164
   777
  biresolve_from_nets_tac ctxt (#safe0_netpair (rep_claset_of ctxt));
lcp@747
   778
paulson@4066
   779
(*These unsafe steps could generate more subgoals.*)
wenzelm@42793
   780
fun instp_step_tac ctxt =
wenzelm@59164
   781
  biresolve_from_nets_tac ctxt (#safep_netpair (rep_claset_of ctxt));
clasohm@0
   782
clasohm@0
   783
(*These steps could instantiate variables and are therefore unsafe.*)
wenzelm@42793
   784
fun inst_step_tac ctxt = inst0_step_tac ctxt APPEND' instp_step_tac ctxt;
clasohm@0
   785
wenzelm@60943
   786
fun unsafe_step_tac ctxt =
wenzelm@60943
   787
  biresolve_from_nets_tac ctxt (#unsafe_netpair (rep_claset_of ctxt));
lcp@681
   788
clasohm@0
   789
(*Single step for the prover.  FAILS unless it makes progress. *)
wenzelm@42793
   790
fun step_tac ctxt i =
wenzelm@60943
   791
  safe_tac ctxt ORELSE appWrappers ctxt (inst_step_tac ctxt ORELSE' unsafe_step_tac ctxt) i;
clasohm@0
   792
clasohm@0
   793
(*Using a "safe" rule to instantiate variables is unsafe.  This tactic
clasohm@0
   794
  allows backtracking from "safe" rules to "unsafe" rules here.*)
wenzelm@42793
   795
fun slow_step_tac ctxt i =
wenzelm@60943
   796
  safe_tac ctxt ORELSE appWrappers ctxt (inst_step_tac ctxt APPEND' unsafe_step_tac ctxt) i;
clasohm@0
   797
wenzelm@42791
   798
paulson@1800
   799
(**** The following tactics all fail unless they solve one goal ****)
clasohm@0
   800
clasohm@0
   801
(*Dumb but fast*)
wenzelm@42793
   802
fun fast_tac ctxt =
wenzelm@54742
   803
  Object_Logic.atomize_prems_tac ctxt THEN' SELECT_GOAL (DEPTH_SOLVE (step_tac ctxt 1));
clasohm@0
   804
clasohm@0
   805
(*Slower but smarter than fast_tac*)
wenzelm@42793
   806
fun best_tac ctxt =
wenzelm@54742
   807
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@42793
   808
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (step_tac ctxt 1));
clasohm@0
   809
oheimb@9402
   810
(*even a bit smarter than best_tac*)
wenzelm@42793
   811
fun first_best_tac ctxt =
wenzelm@54742
   812
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@42793
   813
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (FIRSTGOAL (step_tac ctxt)));
oheimb@9402
   814
wenzelm@42793
   815
fun slow_tac ctxt =
wenzelm@54742
   816
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@42793
   817
  SELECT_GOAL (DEPTH_SOLVE (slow_step_tac ctxt 1));
clasohm@0
   818
wenzelm@42793
   819
fun slow_best_tac ctxt =
wenzelm@54742
   820
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@42793
   821
  SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (slow_step_tac ctxt 1));
clasohm@0
   822
lcp@681
   823
wenzelm@10736
   824
(***ASTAR with weight weight_ASTAR, by Norbert Voelker*)
wenzelm@42791
   825
wenzelm@42791
   826
val weight_ASTAR = 5;
paulson@1587
   827
wenzelm@42793
   828
fun astar_tac ctxt =
wenzelm@54742
   829
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@10382
   830
  SELECT_GOAL
wenzelm@52462
   831
    (ASTAR (has_fewer_prems 1, fn lev => fn thm => Data.sizef thm + weight_ASTAR * lev)
wenzelm@42793
   832
      (step_tac ctxt 1));
paulson@1587
   833
wenzelm@42793
   834
fun slow_astar_tac ctxt =
wenzelm@54742
   835
  Object_Logic.atomize_prems_tac ctxt THEN'
wenzelm@10382
   836
  SELECT_GOAL
wenzelm@52462
   837
    (ASTAR (has_fewer_prems 1, fn lev => fn thm => Data.sizef thm + weight_ASTAR * lev)
wenzelm@42793
   838
      (slow_step_tac ctxt 1));
paulson@1587
   839
wenzelm@42790
   840
paulson@1800
   841
(**** Complete tactic, loosely based upon LeanTaP.  This tactic is the outcome
lcp@747
   842
  of much experimentation!  Changing APPEND to ORELSE below would prove
lcp@747
   843
  easy theorems faster, but loses completeness -- and many of the harder
paulson@1800
   844
  theorems such as 43. ****)
lcp@681
   845
lcp@747
   846
(*Non-deterministic!  Could always expand the first unsafe connective.
lcp@747
   847
  That's hard to implement and did not perform better in experiments, due to
lcp@747
   848
  greater search depth required.*)
wenzelm@42793
   849
fun dup_step_tac ctxt =
wenzelm@59164
   850
  biresolve_from_nets_tac ctxt (#dup_netpair (rep_claset_of ctxt));
lcp@681
   851
oheimb@5523
   852
(*Searching to depth m. A variant called nodup_depth_tac appears in clasimp.ML*)
oheimb@5757
   853
local
wenzelm@42793
   854
  fun slow_step_tac' ctxt = appWrappers ctxt (instp_step_tac ctxt APPEND' dup_step_tac ctxt);
wenzelm@42790
   855
in
wenzelm@42793
   856
  fun depth_tac ctxt m i state = SELECT_GOAL
wenzelm@42793
   857
    (safe_steps_tac ctxt 1 THEN_ELSE
wenzelm@42793
   858
      (DEPTH_SOLVE (depth_tac ctxt m 1),
wenzelm@42793
   859
        inst0_step_tac ctxt 1 APPEND COND (K (m = 0)) no_tac
wenzelm@42793
   860
          (slow_step_tac' ctxt 1 THEN DEPTH_SOLVE (depth_tac ctxt (m - 1) 1)))) i state;
oheimb@5757
   861
end;
lcp@747
   862
wenzelm@10736
   863
(*Search, with depth bound m.
paulson@2173
   864
  This is the "entry point", which does safe inferences first.*)
wenzelm@42793
   865
fun safe_depth_tac ctxt m = SUBGOAL (fn (prem, i) =>
wenzelm@42793
   866
  let
wenzelm@42793
   867
    val deti = (*No Vars in the goal?  No need to backtrack between goals.*)
wenzelm@42793
   868
      if exists_subterm (fn Var _ => true | _ => false) prem then DETERM else I;
wenzelm@42790
   869
  in
wenzelm@42793
   870
    SELECT_GOAL (TRY (safe_tac ctxt) THEN DEPTH_SOLVE (deti (depth_tac ctxt m 1))) i
wenzelm@42790
   871
  end);
lcp@681
   872
wenzelm@42793
   873
fun deepen_tac ctxt = DEEPEN (2, 10) (safe_depth_tac ctxt);
wenzelm@24021
   874
wenzelm@24021
   875
wenzelm@5885
   876
(* attributes *)
wenzelm@5885
   877
wenzelm@42793
   878
fun attrib f =
wenzelm@60945
   879
  Thm.declaration_attribute (fn th => fn context =>
wenzelm@60945
   880
    map_cs (f (Context.proof_of context) th) context);
wenzelm@5885
   881
wenzelm@18691
   882
val safe_elim = attrib o addSE;
wenzelm@18691
   883
val safe_intro = attrib o addSI;
wenzelm@42793
   884
val safe_dest = attrib o addSD;
wenzelm@60943
   885
val unsafe_elim = attrib o addE;
wenzelm@60943
   886
val unsafe_intro = attrib o addI;
wenzelm@60943
   887
val unsafe_dest = attrib o addD;
wenzelm@45375
   888
wenzelm@45375
   889
val rule_del =
wenzelm@60945
   890
  Thm.declaration_attribute (fn th => fn context =>
wenzelm@60945
   891
    context
wenzelm@60945
   892
    |> map_cs (delrule (Context.proof_of context) th)
wenzelm@60945
   893
    |> Thm.attribute_declaration Context_Rules.rule_del th);
wenzelm@5885
   894
wenzelm@5885
   895
wenzelm@5841
   896
wenzelm@5885
   897
(** concrete syntax of attributes **)
wenzelm@5841
   898
wenzelm@5841
   899
val introN = "intro";
wenzelm@5841
   900
val elimN = "elim";
wenzelm@5841
   901
val destN = "dest";
wenzelm@5841
   902
wenzelm@58826
   903
val _ =
wenzelm@58826
   904
  Theory.setup
wenzelm@58826
   905
   (Attrib.setup @{binding swapped} (Scan.succeed swapped)
wenzelm@58826
   906
      "classical swap of introduction rule" #>
wenzelm@60943
   907
    Attrib.setup @{binding dest} (Context_Rules.add safe_dest unsafe_dest Context_Rules.dest_query)
wenzelm@58826
   908
      "declaration of Classical destruction rule" #>
wenzelm@60943
   909
    Attrib.setup @{binding elim} (Context_Rules.add safe_elim unsafe_elim Context_Rules.elim_query)
wenzelm@58826
   910
      "declaration of Classical elimination rule" #>
wenzelm@60943
   911
    Attrib.setup @{binding intro} (Context_Rules.add safe_intro unsafe_intro Context_Rules.intro_query)
wenzelm@58826
   912
      "declaration of Classical introduction rule" #>
wenzelm@58826
   913
    Attrib.setup @{binding rule} (Scan.lift Args.del >> K rule_del)
wenzelm@58826
   914
      "remove declaration of intro/elim/dest rule");
wenzelm@5841
   915
wenzelm@5841
   916
wenzelm@5841
   917
wenzelm@7230
   918
(** proof methods **)
wenzelm@7230
   919
wenzelm@7230
   920
local
wenzelm@7230
   921
wenzelm@30609
   922
fun some_rule_tac ctxt facts = SUBGOAL (fn (goal, i) =>
wenzelm@5841
   923
  let
wenzelm@61049
   924
    val [rules1, rules2, rules4] = Context_Rules.find_rules ctxt false facts goal;
wenzelm@60942
   925
    val {extra_netpair, ...} = rep_claset_of ctxt;
wenzelm@61049
   926
    val rules3 = Context_Rules.find_rules_netpair ctxt true facts goal extra_netpair;
wenzelm@12376
   927
    val rules = rules1 @ rules2 @ rules3 @ rules4;
wenzelm@58950
   928
    val ruleq = Drule.multi_resolves (SOME ctxt) facts rules;
wenzelm@52732
   929
    val _ = Method.trace ctxt rules;
wenzelm@12376
   930
  in
wenzelm@59498
   931
    fn st => Seq.maps (fn rule => resolve_tac ctxt [rule] i st) ruleq
wenzelm@18834
   932
  end)
wenzelm@54742
   933
  THEN_ALL_NEW Goal.norm_hhf_tac ctxt;
wenzelm@5841
   934
wenzelm@30609
   935
in
wenzelm@7281
   936
wenzelm@30609
   937
fun rule_tac ctxt [] facts = some_rule_tac ctxt facts
wenzelm@54742
   938
  | rule_tac ctxt rules facts = Method.rule_tac ctxt rules facts;
wenzelm@30609
   939
wenzelm@60619
   940
fun standard_tac ctxt facts =
wenzelm@60619
   941
  HEADGOAL (some_rule_tac ctxt facts) ORELSE
wenzelm@60618
   942
  Class.standard_intro_classes_tac ctxt facts;
wenzelm@60618
   943
wenzelm@7230
   944
end;
wenzelm@5841
   945
wenzelm@5841
   946
wenzelm@6502
   947
(* automatic methods *)
wenzelm@5841
   948
wenzelm@5927
   949
val cla_modifiers =
wenzelm@64556
   950
 [Args.$$$ destN -- Args.bang_colon >> K (Method.modifier (safe_dest NONE) \<^here>),
wenzelm@64556
   951
  Args.$$$ destN -- Args.colon >> K (Method.modifier (unsafe_dest NONE) \<^here>),
wenzelm@64556
   952
  Args.$$$ elimN -- Args.bang_colon >> K (Method.modifier (safe_elim NONE) \<^here>),
wenzelm@64556
   953
  Args.$$$ elimN -- Args.colon >> K (Method.modifier (unsafe_elim NONE) \<^here>),
wenzelm@64556
   954
  Args.$$$ introN -- Args.bang_colon >> K (Method.modifier (safe_intro NONE) \<^here>),
wenzelm@64556
   955
  Args.$$$ introN -- Args.colon >> K (Method.modifier (unsafe_intro NONE) \<^here>),
wenzelm@64556
   956
  Args.del -- Args.colon >> K (Method.modifier rule_del \<^here>)];
wenzelm@5927
   957
wenzelm@42793
   958
fun cla_method tac = Method.sections cla_modifiers >> K (SIMPLE_METHOD o tac);
wenzelm@42793
   959
fun cla_method' tac = Method.sections cla_modifiers >> K (SIMPLE_METHOD' o tac);
wenzelm@5841
   960
wenzelm@5841
   961
wenzelm@5841
   962
wenzelm@58826
   963
(** method setup **)
wenzelm@5841
   964
wenzelm@58826
   965
val _ =
wenzelm@58826
   966
  Theory.setup
wenzelm@60619
   967
   (Method.setup @{binding standard} (Scan.succeed (METHOD o standard_tac))
wenzelm@60618
   968
      "standard proof step: classical intro/elim rule or class introduction" #>
wenzelm@58826
   969
    Method.setup @{binding rule}
wenzelm@58826
   970
      (Attrib.thms >> (fn rules => fn ctxt => METHOD (HEADGOAL o rule_tac ctxt rules)))
wenzelm@58826
   971
      "apply some intro/elim rule (potentially classical)" #>
wenzelm@58826
   972
    Method.setup @{binding contradiction}
wenzelm@58826
   973
      (Scan.succeed (fn ctxt => Method.rule ctxt [Data.not_elim, Drule.rotate_prems 1 Data.not_elim]))
wenzelm@58826
   974
      "proof by contradiction" #>
wenzelm@58826
   975
    Method.setup @{binding clarify} (cla_method' (CHANGED_PROP oo clarify_tac))
wenzelm@58826
   976
      "repeatedly apply safe steps" #>
wenzelm@58826
   977
    Method.setup @{binding fast} (cla_method' fast_tac) "classical prover (depth-first)" #>
wenzelm@58826
   978
    Method.setup @{binding slow} (cla_method' slow_tac) "classical prover (slow depth-first)" #>
wenzelm@58826
   979
    Method.setup @{binding best} (cla_method' best_tac) "classical prover (best-first)" #>
wenzelm@58826
   980
    Method.setup @{binding deepen}
wenzelm@58826
   981
      (Scan.lift (Scan.optional Parse.nat 4) --| Method.sections cla_modifiers
wenzelm@58826
   982
        >> (fn n => fn ctxt => SIMPLE_METHOD' (deepen_tac ctxt n)))
wenzelm@58826
   983
      "classical prover (iterative deepening)" #>
wenzelm@58826
   984
    Method.setup @{binding safe} (cla_method (CHANGED_PROP o safe_tac))
wenzelm@58826
   985
      "classical prover (apply safe rules)" #>
wenzelm@58826
   986
    Method.setup @{binding safe_step} (cla_method' safe_step_tac)
wenzelm@58826
   987
      "single classical step (safe rules)" #>
wenzelm@58826
   988
    Method.setup @{binding inst_step} (cla_method' inst_step_tac)
wenzelm@58826
   989
      "single classical step (safe rules, allow instantiations)" #>
wenzelm@58826
   990
    Method.setup @{binding step} (cla_method' step_tac)
wenzelm@58826
   991
      "single classical step (safe and unsafe rules)" #>
wenzelm@58826
   992
    Method.setup @{binding slow_step} (cla_method' slow_step_tac)
wenzelm@58826
   993
      "single classical step (safe and unsafe rules, allow backtracking)" #>
wenzelm@58826
   994
    Method.setup @{binding clarify_step} (cla_method' clarify_step_tac)
wenzelm@58826
   995
      "single classical step (safe rules, without splitting)");
wenzelm@5841
   996
wenzelm@8667
   997
wenzelm@8667
   998
(** outer syntax **)
wenzelm@8667
   999
wenzelm@24867
  1000
val _ =
wenzelm@59936
  1001
  Outer_Syntax.command @{command_keyword print_claset} "print context of Classical Reasoner"
wenzelm@60097
  1002
    (Scan.succeed (Toplevel.keep (print_claset o Toplevel.context_of)));
wenzelm@8667
  1003
wenzelm@5841
  1004
end;