src/Pure/Isar/method.ML
author wenzelm
Sat Oct 15 00:08:06 2005 +0200 (2005-10-15)
changeset 17857 810a67ecbc64
parent 17756 d4a35f82fbb4
child 18039 500b7ed7b2bd
permissions -rw-r--r--
added primitive_text, succeed_text;
wenzelm@5824
     1
(*  Title:      Pure/Isar/method.ML
wenzelm@5824
     2
    ID:         $Id$
wenzelm@5824
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5824
     4
wenzelm@17110
     5
Isar proof methods.
wenzelm@5824
     6
*)
wenzelm@5824
     7
wenzelm@5824
     8
signature BASIC_METHOD =
wenzelm@5824
     9
sig
wenzelm@17110
    10
  val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
wenzelm@17110
    11
  val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
wenzelm@17110
    12
  type method
wenzelm@11731
    13
  val trace_rules: bool ref
wenzelm@5824
    14
  val print_methods: theory -> unit
wenzelm@17110
    15
  val Method: bstring -> (Args.src -> ProofContext.context -> method) -> string -> unit
wenzelm@5824
    16
end;
wenzelm@5824
    17
wenzelm@5824
    18
signature METHOD =
wenzelm@5824
    19
sig
wenzelm@5824
    20
  include BASIC_METHOD
wenzelm@7419
    21
  val multi_resolve: thm list -> thm -> thm Seq.seq
wenzelm@7419
    22
  val multi_resolves: thm list -> thm list -> thm Seq.seq
wenzelm@17110
    23
  val apply: method -> thm list -> RuleCases.tactic;
wenzelm@17110
    24
  val RAW_METHOD_CASES: (thm list -> RuleCases.tactic) -> method
wenzelm@17110
    25
  val RAW_METHOD: (thm list -> tactic) -> method
wenzelm@17110
    26
  val METHOD_CASES: (thm list -> RuleCases.tactic) -> method
wenzelm@17110
    27
  val METHOD: (thm list -> tactic) -> method
wenzelm@17110
    28
  val fail: method
wenzelm@17110
    29
  val succeed: method
wenzelm@17110
    30
  val insert_tac: thm list -> int -> tactic
wenzelm@17110
    31
  val insert: thm list -> method
wenzelm@17110
    32
  val insert_facts: method
wenzelm@17110
    33
  val SIMPLE_METHOD: tactic -> method
wenzelm@17110
    34
  val SIMPLE_METHOD': ((int -> tactic) -> tactic) -> (int -> tactic) -> method
wenzelm@17110
    35
  val defer: int option -> method
wenzelm@17110
    36
  val prefer: int -> method
wenzelm@17356
    37
  val cheating: bool -> ProofContext.context -> method
wenzelm@17110
    38
  val intro: thm list -> method
wenzelm@17110
    39
  val elim: thm list -> method
wenzelm@17110
    40
  val unfold: thm list -> method
wenzelm@17110
    41
  val fold: thm list -> method
wenzelm@17110
    42
  val atomize: bool -> method
wenzelm@17110
    43
  val this: method
wenzelm@17110
    44
  val assumption: ProofContext.context -> method
wenzelm@17110
    45
  val close: bool -> ProofContext.context -> method
wenzelm@17110
    46
  val trace: ProofContext.context -> thm list -> unit
wenzelm@6091
    47
  val rule_tac: thm list -> thm list -> int -> tactic
wenzelm@17110
    48
  val some_rule_tac: thm list -> ProofContext.context -> thm list -> int -> tactic
wenzelm@17110
    49
  val rule: thm list -> method
wenzelm@17110
    50
  val erule: int -> thm list -> method
wenzelm@17110
    51
  val drule: int -> thm list -> method
wenzelm@17110
    52
  val frule: int -> thm list -> method
nipkow@17587
    53
  val iprover_tac: ProofContext.context -> int option -> int -> tactic
wenzelm@17110
    54
  val bires_inst_tac: bool -> ProofContext.context -> (indexname * string) list ->
wenzelm@17110
    55
    thm -> int -> tactic
wenzelm@17110
    56
  val set_tactic: (ProofContext.context -> thm list -> tactic) -> unit
wenzelm@17110
    57
  val tactic: string -> ProofContext.context -> method
wenzelm@17110
    58
  type src
wenzelm@5824
    59
  datatype text =
wenzelm@17110
    60
    Basic of (ProofContext.context -> method) |
wenzelm@15703
    61
    Source of src |
wenzelm@5824
    62
    Then of text list |
wenzelm@5824
    63
    Orelse of text list |
wenzelm@5824
    64
    Try of text |
wenzelm@5824
    65
    Repeat1 of text
wenzelm@17857
    66
  val primitive_text: (thm -> thm) -> text
wenzelm@17857
    67
  val succeed_text: text
wenzelm@17110
    68
  val default_text: text
wenzelm@17110
    69
  val this_text: text
wenzelm@17110
    70
  val done_text: text
wenzelm@17356
    71
  val sorry_text: bool -> text
wenzelm@17356
    72
  val finish_text: text option * bool -> text
wenzelm@17110
    73
  exception METHOD_FAIL of (string * Position.T) * exn
wenzelm@17110
    74
  val method: theory -> src -> ProofContext.context -> method
wenzelm@17110
    75
  val add_methods: (bstring * (src -> ProofContext.context -> method) * string) list
wenzelm@17110
    76
    -> theory -> theory
wenzelm@17110
    77
  val add_method: bstring * (src -> ProofContext.context -> method) * string
wenzelm@17110
    78
    -> theory -> theory
wenzelm@17356
    79
  val method_setup: bstring * string * string -> theory -> theory
wenzelm@17110
    80
  val syntax: (ProofContext.context * Args.T list -> 'a * (ProofContext.context * Args.T list))
wenzelm@17110
    81
    -> src -> ProofContext.context -> ProofContext.context * 'a
wenzelm@17110
    82
  val simple_args: (Args.T list -> 'a * Args.T list)
wenzelm@17110
    83
    -> ('a -> ProofContext.context -> method) -> src -> ProofContext.context -> method
wenzelm@17110
    84
  val ctxt_args: (ProofContext.context -> method) -> src -> ProofContext.context -> method
wenzelm@17110
    85
  val no_args: method -> src -> ProofContext.context -> method
wenzelm@17110
    86
  type modifier
wenzelm@17110
    87
  val sectioned_args: (ProofContext.context * Args.T list ->
wenzelm@17110
    88
      'a * (ProofContext.context * Args.T list)) ->
wenzelm@17110
    89
    (Args.T list -> modifier * Args.T list) list ->
wenzelm@17110
    90
    ('a -> ProofContext.context -> 'b) -> src -> ProofContext.context -> 'b
wenzelm@17110
    91
  val bang_sectioned_args:
wenzelm@17110
    92
    (Args.T list -> modifier * Args.T list) list ->
wenzelm@17110
    93
    (thm list -> ProofContext.context -> 'a) -> src -> ProofContext.context -> 'a
wenzelm@17110
    94
  val bang_sectioned_args':
wenzelm@17110
    95
    (Args.T list -> modifier * Args.T list) list ->
wenzelm@17110
    96
    (ProofContext.context * Args.T list -> 'a * (ProofContext.context * Args.T list)) ->
wenzelm@17110
    97
    ('a -> thm list -> ProofContext.context -> 'b) -> src -> ProofContext.context -> 'b
wenzelm@17110
    98
  val only_sectioned_args:
wenzelm@17110
    99
    (Args.T list -> modifier * Args.T list) list ->
wenzelm@17110
   100
    (ProofContext.context -> 'a) -> src -> ProofContext.context -> 'a
wenzelm@17110
   101
  val thms_ctxt_args: (thm list -> ProofContext.context -> 'a) -> src ->
wenzelm@17110
   102
    ProofContext.context -> 'a
wenzelm@17110
   103
  val thms_args: (thm list -> 'a) -> src -> ProofContext.context -> 'a
wenzelm@17110
   104
  val thm_args: (thm -> 'a) -> src -> ProofContext.context -> 'a
wenzelm@9539
   105
  val goal_args: (Args.T list -> 'a * Args.T list) -> ('a -> int -> tactic)
wenzelm@17110
   106
    -> src -> ProofContext.context -> method
wenzelm@17110
   107
  val goal_args': (ProofContext.context * Args.T list ->
wenzelm@17110
   108
      'a * (ProofContext.context * Args.T list))
wenzelm@17110
   109
    -> ('a -> int -> tactic) -> src -> ProofContext.context -> method
wenzelm@17110
   110
  val goal_args_ctxt: (Args.T list -> 'a * Args.T list) ->
wenzelm@17110
   111
    (ProofContext.context -> 'a -> int -> tactic) -> src -> ProofContext.context -> method
wenzelm@17110
   112
  val goal_args_ctxt': (ProofContext.context * Args.T list ->
wenzelm@17110
   113
    'a * (ProofContext.context * Args.T list)) ->
wenzelm@17110
   114
    (ProofContext.context -> 'a -> int -> tactic) -> src -> ProofContext.context -> method
wenzelm@5824
   115
end;
wenzelm@5824
   116
wenzelm@5824
   117
structure Method: METHOD =
wenzelm@5824
   118
struct
wenzelm@5824
   119
wenzelm@17110
   120
(** generic tools **)
wenzelm@17110
   121
wenzelm@17110
   122
(* goal addressing *)
wenzelm@17110
   123
wenzelm@17110
   124
fun FINDGOAL tac st =
wenzelm@17110
   125
  let fun find i n = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1) n)
wenzelm@17110
   126
  in find 1 (Thm.nprems_of st) st end;
wenzelm@17110
   127
wenzelm@17110
   128
fun HEADGOAL tac = tac 1;
wenzelm@17110
   129
wenzelm@17110
   130
wenzelm@17110
   131
(* multi_resolve *)
wenzelm@17110
   132
wenzelm@17110
   133
local
wenzelm@17110
   134
wenzelm@17110
   135
fun res th i rule =
wenzelm@17110
   136
  Thm.biresolution false [(false, th)] i rule handle THM _ => Seq.empty;
wenzelm@17110
   137
wenzelm@17110
   138
fun multi_res _ [] rule = Seq.single rule
wenzelm@17356
   139
  | multi_res i (th :: ths) rule = Seq.maps (res th i) (multi_res (i + 1) ths rule);
wenzelm@17110
   140
wenzelm@17110
   141
in
wenzelm@17110
   142
wenzelm@17110
   143
val multi_resolve = multi_res 1;
wenzelm@17356
   144
fun multi_resolves facts rules = Seq.maps (multi_resolve facts) (Seq.of_list rules);
wenzelm@17110
   145
wenzelm@17110
   146
end;
wenzelm@17110
   147
wenzelm@15703
   148
wenzelm@5824
   149
wenzelm@12324
   150
(** proof methods **)
wenzelm@12324
   151
wenzelm@17110
   152
(* datatype method *)
wenzelm@11731
   153
wenzelm@17756
   154
datatype method = Meth of thm list -> RuleCases.tactic;
wenzelm@11731
   155
wenzelm@17756
   156
fun apply (Meth m) = m;
wenzelm@11731
   157
wenzelm@17756
   158
val RAW_METHOD_CASES = Meth;
wenzelm@11731
   159
wenzelm@17110
   160
fun RAW_METHOD tac = RAW_METHOD_CASES (NO_CASES o tac);
wenzelm@12144
   161
wenzelm@17110
   162
fun METHOD_CASES tac = RAW_METHOD_CASES (fn facts =>
wenzelm@17110
   163
  Seq.THEN (TRY Tactic.conjunction_tac, tac facts));
wenzelm@8372
   164
wenzelm@17110
   165
fun METHOD tac = RAW_METHOD (fn facts =>
wenzelm@17110
   166
  TRY Tactic.conjunction_tac THEN tac facts);
wenzelm@5824
   167
wenzelm@5824
   168
val fail = METHOD (K no_tac);
wenzelm@5824
   169
val succeed = METHOD (K all_tac);
wenzelm@5824
   170
wenzelm@5824
   171
wenzelm@17110
   172
(* insert facts *)
wenzelm@7419
   173
wenzelm@7419
   174
local
wenzelm@5824
   175
wenzelm@6981
   176
fun cut_rule_tac raw_rule =
wenzelm@6981
   177
  let
wenzelm@6981
   178
    val rule = Drule.forall_intr_vars raw_rule;
wenzelm@6981
   179
    val revcut_rl = Drule.incr_indexes_wrt [] [] [] [rule] Drule.revcut_rl;
wenzelm@7555
   180
  in Tactic.rtac (rule COMP revcut_rl) end;
wenzelm@6981
   181
wenzelm@7419
   182
in
wenzelm@5824
   183
wenzelm@7419
   184
fun insert_tac [] i = all_tac
wenzelm@7419
   185
  | insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts);
wenzelm@6981
   186
wenzelm@7555
   187
val insert_facts = METHOD (ALLGOALS o insert_tac);
wenzelm@7664
   188
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms));
wenzelm@7419
   189
wenzelm@9706
   190
fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac);
wenzelm@9706
   191
fun SIMPLE_METHOD' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac));
wenzelm@9706
   192
wenzelm@12324
   193
end;
wenzelm@12324
   194
wenzelm@9706
   195
wenzelm@17110
   196
(* shuffle subgoals *)
wenzelm@17110
   197
wenzelm@17110
   198
fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1)));
wenzelm@17110
   199
fun defer opt_i = METHOD (K (Tactic.defer_tac (if_none opt_i 1)));
wenzelm@17110
   200
wenzelm@17110
   201
wenzelm@17356
   202
(* cheating *)
wenzelm@17356
   203
wenzelm@17356
   204
fun cheating int ctxt = METHOD (K (setmp quick_and_dirty (int orelse ! quick_and_dirty)
wenzelm@17356
   205
    (SkipProof.cheat_tac (ProofContext.theory_of ctxt))));
wenzelm@17356
   206
wenzelm@17356
   207
wenzelm@17110
   208
(* unfold intro/elim rules *)
wenzelm@17110
   209
wenzelm@17110
   210
fun intro ths = SIMPLE_METHOD' HEADGOAL (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.match_tac ths));
wenzelm@17110
   211
fun elim ths = SIMPLE_METHOD' HEADGOAL (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.ematch_tac ths));
wenzelm@17110
   212
wenzelm@17110
   213
wenzelm@12384
   214
(* unfold/fold definitions *)
wenzelm@12384
   215
wenzelm@16145
   216
fun unfold_meth ths = SIMPLE_METHOD (CHANGED_PROP (rewrite_goals_tac ths));
wenzelm@16145
   217
fun fold_meth ths = SIMPLE_METHOD (CHANGED_PROP (fold_goals_tac ths));
wenzelm@6532
   218
wenzelm@12384
   219
wenzelm@12829
   220
(* atomize rule statements *)
wenzelm@12829
   221
wenzelm@12829
   222
fun atomize false = SIMPLE_METHOD' HEADGOAL (CHANGED_PROP o ObjectLogic.atomize_tac)
wenzelm@12829
   223
  | atomize true = RAW_METHOD (K (HEADGOAL (CHANGED_PROP o ObjectLogic.full_atomize_tac)));
wenzelm@12829
   224
wenzelm@12829
   225
wenzelm@17110
   226
(* this -- apply facts directly *)
wenzelm@12384
   227
wenzelm@17110
   228
val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac));
wenzelm@9484
   229
wenzelm@9484
   230
wenzelm@17110
   231
(* assumption *)
wenzelm@7419
   232
wenzelm@7419
   233
local
wenzelm@7419
   234
wenzelm@17110
   235
fun asm_tac ths =
wenzelm@17110
   236
  foldr (op APPEND') (K no_tac) (map (fn th => Tactic.rtac th THEN_ALL_NEW assume_tac) ths);
wenzelm@17110
   237
wenzelm@17110
   238
val refl_tac = SUBGOAL (fn (prop, i) =>
wenzelm@17110
   239
  if can Logic.dest_equals (Logic.strip_assums_concl prop)
wenzelm@17110
   240
  then Tactic.rtac Drule.reflexive_thm i else no_tac);
wenzelm@7419
   241
wenzelm@17110
   242
fun assm_tac ctxt =
wenzelm@17110
   243
  assume_tac APPEND'
wenzelm@17110
   244
  asm_tac (ProofContext.prems_of ctxt) APPEND'
wenzelm@17110
   245
  refl_tac;
wenzelm@17110
   246
wenzelm@17110
   247
fun assumption_tac ctxt [] = assm_tac ctxt
wenzelm@17110
   248
  | assumption_tac _ [fact] = asm_tac [fact]
wenzelm@17110
   249
  | assumption_tac _ _ = K no_tac;
wenzelm@7419
   250
wenzelm@7419
   251
in
wenzelm@7419
   252
wenzelm@17110
   253
fun assumption ctxt = METHOD (HEADGOAL o assumption_tac ctxt);
wenzelm@17356
   254
fun close immed ctxt = METHOD (K
wenzelm@17356
   255
  (FILTER Thm.no_prems ((if immed then ALLGOALS (assm_tac ctxt) else all_tac) THEN flexflex_tac)));
wenzelm@7419
   256
wenzelm@7419
   257
end;
wenzelm@7419
   258
wenzelm@7419
   259
wenzelm@17110
   260
(* rule etc. -- single-step refinements *)
wenzelm@12347
   261
wenzelm@17110
   262
val trace_rules = ref false;
wenzelm@12347
   263
wenzelm@17110
   264
fun trace ctxt rules =
wenzelm@17110
   265
  conditional (! trace_rules andalso not (null rules)) (fn () =>
wenzelm@17110
   266
    Pretty.big_list "rules:" (map (ProofContext.pretty_thm ctxt) rules)
wenzelm@17110
   267
    |> Pretty.string_of |> tracing);
wenzelm@12347
   268
wenzelm@12347
   269
local
wenzelm@12347
   270
wenzelm@10541
   271
fun gen_rule_tac tac rules [] i st = tac rules i st
wenzelm@12324
   272
  | gen_rule_tac tac rules facts i st =
wenzelm@17356
   273
      Seq.maps (fn rule => (tac o single) rule i st) (multi_resolves facts rules);
wenzelm@7130
   274
wenzelm@10744
   275
fun gen_arule_tac tac j rules facts =
wenzelm@10744
   276
  EVERY' (gen_rule_tac tac rules facts :: replicate j Tactic.assume_tac);
wenzelm@10744
   277
wenzelm@11785
   278
fun gen_some_rule_tac tac arg_rules ctxt facts = SUBGOAL (fn (goal, i) =>
wenzelm@11785
   279
  let
wenzelm@11785
   280
    val rules =
wenzelm@11785
   281
      if not (null arg_rules) then arg_rules
skalberg@15570
   282
      else List.concat (ContextRules.find_rules false facts goal ctxt)
wenzelm@12055
   283
  in trace ctxt rules; tac rules facts i end);
wenzelm@10309
   284
wenzelm@10744
   285
fun meth tac x = METHOD (HEADGOAL o tac x);
wenzelm@10744
   286
fun meth' tac x y = METHOD (HEADGOAL o tac x y);
wenzelm@8220
   287
wenzelm@7419
   288
in
wenzelm@7419
   289
wenzelm@10744
   290
val rule_tac = gen_rule_tac Tactic.resolve_tac;
wenzelm@10744
   291
val rule = meth rule_tac;
wenzelm@10744
   292
val some_rule_tac = gen_some_rule_tac rule_tac;
wenzelm@10744
   293
val some_rule = meth' some_rule_tac;
wenzelm@10744
   294
wenzelm@10744
   295
val erule = meth' (gen_arule_tac Tactic.eresolve_tac);
wenzelm@10744
   296
val drule = meth' (gen_arule_tac Tactic.dresolve_tac);
wenzelm@10744
   297
val frule = meth' (gen_arule_tac Tactic.forward_tac);
wenzelm@5824
   298
wenzelm@7419
   299
end;
wenzelm@7419
   300
wenzelm@7419
   301
nipkow@17587
   302
(* iprover -- intuitionistic proof search *)
wenzelm@17110
   303
wenzelm@17110
   304
local
wenzelm@17110
   305
wenzelm@17110
   306
val remdups_tac = SUBGOAL (fn (g, i) =>
wenzelm@17110
   307
  let val prems = Logic.strip_assums_hyp g in
wenzelm@17110
   308
    REPEAT_DETERM_N (length prems - length (gen_distinct op aconv prems))
wenzelm@17110
   309
    (Tactic.ematch_tac [Drule.remdups_rl] i THEN Tactic.eq_assume_tac i)
wenzelm@17110
   310
  end);
wenzelm@17110
   311
wenzelm@17110
   312
fun REMDUPS tac = tac THEN_ALL_NEW remdups_tac;
wenzelm@17110
   313
wenzelm@17110
   314
fun gen_eq_set e s1 s2 =
wenzelm@17110
   315
  length s1 = length s2 andalso
wenzelm@17110
   316
  gen_subset e (s1, s2) andalso gen_subset e (s2, s1);
wenzelm@17110
   317
wenzelm@17110
   318
val bires_tac = Tactic.biresolution_from_nets_tac ContextRules.orderlist;
wenzelm@17110
   319
wenzelm@17110
   320
fun safe_step_tac ctxt =
wenzelm@17110
   321
  ContextRules.Swrap ctxt
wenzelm@17110
   322
   (eq_assume_tac ORELSE'
wenzelm@17110
   323
    bires_tac true (ContextRules.netpair_bang ctxt));
wenzelm@8195
   324
wenzelm@17110
   325
fun unsafe_step_tac ctxt =
wenzelm@17110
   326
  ContextRules.wrap ctxt
wenzelm@17110
   327
   (assume_tac APPEND'
wenzelm@17110
   328
    bires_tac false (ContextRules.netpair_bang ctxt) APPEND'
wenzelm@17110
   329
    bires_tac false (ContextRules.netpair ctxt));
wenzelm@17110
   330
wenzelm@17110
   331
fun step_tac ctxt i =
wenzelm@17110
   332
  REPEAT_DETERM1 (REMDUPS (safe_step_tac ctxt) i) ORELSE
wenzelm@17110
   333
  REMDUPS (unsafe_step_tac ctxt) i;
wenzelm@17110
   334
wenzelm@17110
   335
fun intprover_tac ctxt gs d lim = SUBGOAL (fn (g, i) => if d > lim then no_tac else
wenzelm@17110
   336
  let
wenzelm@17110
   337
    val ps = Logic.strip_assums_hyp g;
wenzelm@17110
   338
    val c = Logic.strip_assums_concl g;
wenzelm@17110
   339
  in
wenzelm@17110
   340
    if gen_mem (fn ((ps1, c1), (ps2, c2)) =>
wenzelm@17110
   341
      c1 aconv c2 andalso gen_eq_set op aconv ps1 ps2) ((ps, c), gs) then no_tac
wenzelm@17110
   342
    else (step_tac ctxt THEN_ALL_NEW intprover_tac ctxt ((ps, c) :: gs) (d + 1) lim) i
wenzelm@17110
   343
  end);
wenzelm@17110
   344
wenzelm@17110
   345
in
wenzelm@17110
   346
nipkow@17587
   347
fun iprover_tac ctxt opt_lim =
wenzelm@17110
   348
  SELECT_GOAL (DEEPEN (2, if_none opt_lim 20) (intprover_tac ctxt [] 0) 4 1);
wenzelm@17110
   349
wenzelm@17110
   350
end;
wenzelm@8195
   351
wenzelm@8195
   352
wenzelm@17110
   353
(* rule_tac etc. -- refer to dynamic goal state!! *)
wenzelm@12119
   354
ballarin@14174
   355
fun bires_inst_tac bires_flag ctxt insts thm =
ballarin@14174
   356
  let
wenzelm@17110
   357
    val thy = ProofContext.theory_of ctxt;
ballarin@14174
   358
    (* Separate type and term insts *)
ballarin@14174
   359
    fun has_type_var ((x, _), _) = (case Symbol.explode x of
ballarin@14174
   360
          "'"::cs => true | cs => false);
skalberg@15570
   361
    val Tinsts = List.filter has_type_var insts;
ballarin@14174
   362
    val tinsts = filter_out has_type_var insts;
ballarin@14174
   363
    (* Tactic *)
ballarin@14174
   364
    fun tac i st =
ballarin@14174
   365
      let
ballarin@14174
   366
        (* Preprocess state: extract environment information:
ballarin@14174
   367
           - variables and their types
ballarin@14174
   368
           - type variables and their sorts
ballarin@14174
   369
           - parameters and their types *)
ballarin@14174
   370
        val (types, sorts) = types_sorts st;
ballarin@14174
   371
    (* Process type insts: Tinsts_env *)
ballarin@14174
   372
    fun absent xi = error
wenzelm@14718
   373
          ("No such variable in theorem: " ^ Syntax.string_of_vname xi);
ballarin@14174
   374
    val (rtypes, rsorts) = types_sorts thm;
ballarin@14174
   375
    fun readT (xi, s) =
skalberg@15531
   376
        let val S = case rsorts xi of SOME S => S | NONE => absent xi;
wenzelm@17110
   377
            val T = Sign.read_typ (thy, sorts) s;
berghofe@15798
   378
            val U = TVar (xi, S);
wenzelm@17110
   379
        in if Sign.typ_instance thy (T, U) then (U, T)
ballarin@14174
   380
           else error
ballarin@14174
   381
             ("Instantiation of " ^ Syntax.string_of_vname xi ^ " fails")
ballarin@14174
   382
        end;
ballarin@14174
   383
    val Tinsts_env = map readT Tinsts;
ballarin@14174
   384
    (* Preprocess rule: extract vars and their types, apply Tinsts *)
ballarin@14174
   385
    fun get_typ xi =
ballarin@14174
   386
      (case rtypes xi of
berghofe@15798
   387
           SOME T => typ_subst_atomic Tinsts_env T
skalberg@15531
   388
         | NONE => absent xi);
ballarin@14174
   389
    val (xis, ss) = Library.split_list tinsts;
ballarin@14174
   390
    val Ts = map get_typ xis;
wenzelm@14718
   391
        val (_, _, Bi, _) = dest_state(st,i)
wenzelm@14718
   392
        val params = Logic.strip_params Bi
wenzelm@14718
   393
                             (* params of subgoal i as string typ pairs *)
wenzelm@14718
   394
        val params = rev(Term.rename_wrt_term Bi params)
wenzelm@14718
   395
                           (* as they are printed: bound variables with *)
ballarin@14508
   396
                           (* the same name are renamed during printing *)
haftmann@17314
   397
        fun types' (a, ~1) = (case AList.lookup (op =) params a of
skalberg@15531
   398
                NONE => types (a, ~1)
ballarin@14174
   399
              | some => some)
ballarin@14174
   400
          | types' xi = types xi;
wenzelm@15973
   401
        fun internal x = is_some (types' (x, ~1));
wenzelm@15703
   402
        val used = Drule.add_used thm (Drule.add_used st []);
wenzelm@14718
   403
        val (ts, envT) =
wenzelm@14718
   404
          ProofContext.read_termTs_schematic ctxt internal types' sorts used (ss ~~ Ts);
berghofe@15798
   405
        val envT' = map (fn (ixn, T) =>
wenzelm@15973
   406
          (TVar (ixn, the (rsorts ixn)), T)) envT @ Tinsts_env;
wenzelm@14718
   407
        val cenv =
wenzelm@14718
   408
          map
wenzelm@14718
   409
            (fn (xi, t) =>
wenzelm@17110
   410
              pairself (Thm.cterm_of thy) (Var (xi, fastype_of t), t))
wenzelm@14718
   411
            (gen_distinct
wenzelm@14718
   412
              (fn ((x1, t1), (x2, t2)) => x1 = x2 andalso t1 aconv t2)
wenzelm@14718
   413
              (xis ~~ ts));
wenzelm@14718
   414
        (* Lift and instantiate rule *)
wenzelm@14718
   415
        val {maxidx, ...} = rep_thm st;
wenzelm@14718
   416
        val paramTs = map #2 params
wenzelm@14718
   417
        and inc = maxidx+1
wenzelm@14718
   418
        fun liftvar (Var ((a,j), T)) =
wenzelm@16876
   419
              Var((a, j+inc), paramTs ---> Logic.incr_tvar inc T)
wenzelm@14718
   420
          | liftvar t = raise TERM("Variable expected", [t]);
wenzelm@14718
   421
        fun liftterm t = list_abs_free
wenzelm@14718
   422
              (params, Logic.incr_indexes(paramTs,inc) t)
wenzelm@14718
   423
        fun liftpair (cv,ct) =
wenzelm@14718
   424
              (cterm_fun liftvar cv, cterm_fun liftterm ct)
wenzelm@17110
   425
        val lifttvar = pairself (ctyp_of thy o Logic.incr_tvar inc);
wenzelm@14718
   426
        val rule = Drule.instantiate
berghofe@15798
   427
              (map lifttvar envT', map liftpair cenv)
wenzelm@14718
   428
              (lift_rule (st, i) thm)
ballarin@14174
   429
      in
wenzelm@14718
   430
        if i > nprems_of st then no_tac st
wenzelm@14718
   431
        else st |>
wenzelm@14718
   432
          compose_tac (bires_flag, rule, nprems_of thm) i
ballarin@14174
   433
      end
wenzelm@14718
   434
           handle TERM (msg,_)   => (warning msg; no_tac st)
wenzelm@14718
   435
                | THM  (msg,_,_) => (warning msg; no_tac st);
ballarin@14174
   436
  in
ballarin@14174
   437
    tac
ballarin@14174
   438
  end;
wenzelm@8238
   439
wenzelm@17110
   440
local
wenzelm@17110
   441
ballarin@14174
   442
fun gen_inst _ tac _ (quant, ([], thms)) =
ballarin@14174
   443
      METHOD (fn facts => quant (insert_tac facts THEN' tac thms))
ballarin@14174
   444
  | gen_inst inst_tac _ ctxt (quant, (insts, [thm])) =
ballarin@14174
   445
      METHOD (fn facts =>
ballarin@14174
   446
        quant (insert_tac facts THEN' inst_tac ctxt insts thm))
ballarin@14174
   447
  | gen_inst _ _ _ _ = error "Cannot have instantiations with multiple rules";
wenzelm@14718
   448
ballarin@14174
   449
(* Preserve Var indexes of rl; increment revcut_rl instead.
ballarin@14174
   450
   Copied from tactic.ML *)
ballarin@14174
   451
fun make_elim_preserve rl =
ballarin@14174
   452
  let val {maxidx,...} = rep_thm rl
wenzelm@17110
   453
      fun cvar xi = cterm_of ProtoPure.thy (Var(xi,propT));
ballarin@14174
   454
      val revcut_rl' =
ballarin@14174
   455
          instantiate ([],  [(cvar("V",0), cvar("V",maxidx+1)),
ballarin@14174
   456
                             (cvar("W",0), cvar("W",maxidx+1))]) revcut_rl
ballarin@14174
   457
      val arg = (false, rl, nprems_of rl)
ballarin@14174
   458
      val [th] = Seq.list_of (bicompose false arg 1 revcut_rl')
ballarin@14174
   459
  in  th  end
ballarin@14174
   460
  handle Bind => raise THM("make_elim_preserve", 1, [rl]);
wenzelm@8238
   461
wenzelm@17110
   462
in
wenzelm@17110
   463
wenzelm@17110
   464
val res_inst_meth = gen_inst (bires_inst_tac false) Tactic.resolve_tac;
wenzelm@17110
   465
wenzelm@17110
   466
val eres_inst_meth = gen_inst (bires_inst_tac true) Tactic.eresolve_tac;
wenzelm@17110
   467
ballarin@14174
   468
val cut_inst_meth =
ballarin@14174
   469
  gen_inst
wenzelm@17110
   470
    (fn ctxt => fn insts => bires_inst_tac false ctxt insts o make_elim_preserve)
ballarin@14174
   471
    Tactic.cut_rules_tac;
ballarin@14174
   472
ballarin@14174
   473
val dres_inst_meth =
ballarin@14174
   474
  gen_inst
wenzelm@17110
   475
    (fn ctxt => fn insts => bires_inst_tac true ctxt insts o make_elim_preserve)
ballarin@14174
   476
    Tactic.dresolve_tac;
ballarin@14174
   477
ballarin@14174
   478
val forw_inst_meth =
ballarin@14174
   479
  gen_inst
ballarin@14174
   480
    (fn ctxt => fn insts => fn rule =>
ballarin@14174
   481
       bires_inst_tac false ctxt insts (make_elim_preserve rule) THEN'
ballarin@14174
   482
       assume_tac)
ballarin@14174
   483
    Tactic.forward_tac;
ballarin@14174
   484
ballarin@14174
   485
fun subgoal_tac ctxt sprop =
wenzelm@17110
   486
  DETERM o bires_inst_tac false ctxt [(("psi", 0), sprop)] cut_rl;
ballarin@14174
   487
ballarin@14174
   488
fun subgoals_tac ctxt sprops = EVERY' (map (subgoal_tac ctxt) sprops);
ballarin@14174
   489
ballarin@14174
   490
fun thin_tac ctxt s =
ballarin@14174
   491
  bires_inst_tac true ctxt [(("V", 0), s)] thin_rl;
wenzelm@8238
   492
wenzelm@17110
   493
end;
wenzelm@8329
   494
wenzelm@8329
   495
wenzelm@8351
   496
(* ML tactics *)
wenzelm@8351
   497
wenzelm@17110
   498
val tactic_ref = ref ((fn _ => raise Match): ProofContext.context -> thm list -> tactic);
wenzelm@8351
   499
fun set_tactic f = tactic_ref := f;
wenzelm@8351
   500
wenzelm@8351
   501
fun tactic txt ctxt = METHOD (fn facts =>
wenzelm@9631
   502
  (Context.use_mltext
wenzelm@17110
   503
    ("let fun tactic (ctxt: ProofContext.context) (facts: thm list) : tactic = \
wenzelm@16500
   504
       \let val thm = ProofContext.get_thm_closure ctxt o PureThy.Name\n\
wenzelm@16500
   505
       \  and thms = ProofContext.get_thms_closure ctxt o PureThy.Name in\n"
wenzelm@16500
   506
       ^ txt ^
wenzelm@16500
   507
       "\nend in Method.set_tactic tactic end")
skalberg@15531
   508
    false NONE;
skalberg@15531
   509
    Context.setmp (SOME (ProofContext.theory_of ctxt)) (! tactic_ref ctxt) facts));
wenzelm@8351
   510
wenzelm@8351
   511
wenzelm@5824
   512
wenzelm@17110
   513
(** method syntax **)
wenzelm@17110
   514
wenzelm@17110
   515
(* method text *)
wenzelm@17110
   516
wenzelm@17110
   517
type src = Args.src;
wenzelm@5824
   518
wenzelm@17110
   519
datatype text =
wenzelm@17110
   520
  Basic of (ProofContext.context -> method) |
wenzelm@17110
   521
  Source of src |
wenzelm@17110
   522
  Then of text list |
wenzelm@17110
   523
  Orelse of text list |
wenzelm@17110
   524
  Try of text |
wenzelm@17110
   525
  Repeat1 of text;
wenzelm@17110
   526
wenzelm@17857
   527
val primitive_text = Basic o K o SIMPLE_METHOD o PRIMITIVE;
wenzelm@17857
   528
val succeed_text = Basic (K succeed);
wenzelm@17110
   529
val default_text = Source (Args.src (("default", []), Position.none));
wenzelm@17110
   530
val this_text = Basic (K this);
wenzelm@17110
   531
val done_text = Basic (K (SIMPLE_METHOD all_tac));
wenzelm@17356
   532
val sorry_text = Basic o cheating;
wenzelm@17110
   533
wenzelm@17356
   534
fun finish_text (NONE, immed) = Basic (close immed)
wenzelm@17356
   535
  | finish_text (SOME txt, immed) = Then [txt, Basic (close immed)];
wenzelm@17110
   536
wenzelm@17110
   537
wenzelm@17110
   538
(* method definitions *)
wenzelm@5824
   539
wenzelm@16448
   540
structure MethodsData = TheoryDataFun
wenzelm@16448
   541
(struct
wenzelm@5824
   542
  val name = "Isar/methods";
wenzelm@17110
   543
  type T = (((src -> ProofContext.context -> method) * string) * stamp) NameSpace.table;
wenzelm@5824
   544
wenzelm@16347
   545
  val empty = NameSpace.empty_table;
wenzelm@6546
   546
  val copy = I;
wenzelm@16448
   547
  val extend = I;
haftmann@17496
   548
  fun merge _ tables = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUPS dups =>
wenzelm@16347
   549
    error ("Attempt to merge different versions of method(s) " ^ commas_quote dups);
wenzelm@5824
   550
wenzelm@16347
   551
  fun print _ meths =
wenzelm@5824
   552
    let
wenzelm@5824
   553
      fun prt_meth (name, ((_, comment), _)) = Pretty.block
wenzelm@6849
   554
        [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
wenzelm@5824
   555
    in
wenzelm@16347
   556
      [Pretty.big_list "methods:" (map prt_meth (NameSpace.extern_table meths))]
wenzelm@9222
   557
      |> Pretty.chunks |> Pretty.writeln
wenzelm@5824
   558
    end;
wenzelm@16448
   559
end);
wenzelm@5824
   560
wenzelm@15801
   561
val _ = Context.add_setup [MethodsData.init];
wenzelm@5824
   562
val print_methods = MethodsData.print;
wenzelm@7611
   563
wenzelm@5824
   564
wenzelm@5824
   565
(* get methods *)
wenzelm@5824
   566
wenzelm@5916
   567
exception METHOD_FAIL of (string * Position.T) * exn;
wenzelm@5916
   568
wenzelm@5824
   569
fun method thy =
wenzelm@5824
   570
  let
wenzelm@16347
   571
    val (space, meths) = MethodsData.get thy;
wenzelm@5884
   572
    fun meth src =
wenzelm@5884
   573
      let
wenzelm@5884
   574
        val ((raw_name, _), pos) = Args.dest_src src;
wenzelm@5884
   575
        val name = NameSpace.intern space raw_name;
wenzelm@5884
   576
      in
wenzelm@17412
   577
        (case Symtab.lookup meths name of
skalberg@15531
   578
          NONE => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
skalberg@15531
   579
        | SOME ((mth, _), _) => transform_failure (curry METHOD_FAIL (name, pos)) (mth src))
wenzelm@5824
   580
      end;
wenzelm@5824
   581
  in meth end;
wenzelm@5824
   582
wenzelm@5824
   583
wenzelm@17110
   584
(* add method *)
wenzelm@5824
   585
wenzelm@5824
   586
fun add_methods raw_meths thy =
wenzelm@5824
   587
  let
wenzelm@16145
   588
    val new_meths = raw_meths |> map (fn (name, f, comment) =>
wenzelm@16347
   589
      (name, ((f, comment), stamp ())));
wenzelm@5824
   590
wenzelm@17110
   591
    fun add meths = NameSpace.extend_table (Sign.naming_of thy) (meths, new_meths)
wenzelm@16347
   592
      handle Symtab.DUPS dups =>
wenzelm@16347
   593
        error ("Duplicate declaration of method(s) " ^ commas_quote dups);
wenzelm@16347
   594
  in MethodsData.map add thy end;
wenzelm@5824
   595
wenzelm@9194
   596
val add_method = add_methods o Library.single;
wenzelm@9194
   597
wenzelm@5824
   598
fun Method name meth cmt = Context.>> (add_methods [(name, meth, cmt)]);
wenzelm@5824
   599
wenzelm@5824
   600
wenzelm@17356
   601
(* method_setup *)
wenzelm@17356
   602
wenzelm@17356
   603
fun method_setup (name, txt, cmt) =
wenzelm@17356
   604
  Context.use_let
wenzelm@17356
   605
    "val thm = PureThy.get_thm_closure (Context.the_context ()) o PureThy.Name;\n\
wenzelm@17356
   606
    \val thms = PureThy.get_thms_closure (Context.the_context ()) o PureThy.Name;\n\
wenzelm@17356
   607
    \val method: bstring * (Method.src -> ProofContext.context -> Proof.method) * string"
wenzelm@17356
   608
    "Method.add_method method"
wenzelm@17356
   609
    ("(" ^ Library.quote name ^ ", " ^ txt ^ ", " ^ Library.quote cmt ^ ")");
wenzelm@17356
   610
wenzelm@17356
   611
wenzelm@5884
   612
wenzelm@17110
   613
(** concrete syntax **)
wenzelm@5824
   614
wenzelm@5884
   615
(* basic *)
wenzelm@5884
   616
wenzelm@17110
   617
fun syntax (scan:
wenzelm@17110
   618
    (ProofContext.context * Args.T list -> 'a * (ProofContext.context * Args.T list))) =
wenzelm@5884
   619
  Args.syntax "method" scan;
wenzelm@5824
   620
wenzelm@17110
   621
fun simple_args scan f src ctxt : method =
wenzelm@8351
   622
  #2 (syntax (Scan.lift (scan >> (fn x => f x ctxt))) src ctxt);
wenzelm@8351
   623
wenzelm@17110
   624
fun ctxt_args (f: ProofContext.context -> method) src ctxt =
wenzelm@8282
   625
  #2 (syntax (Scan.succeed (f ctxt)) src ctxt);
wenzelm@7555
   626
wenzelm@7555
   627
fun no_args m = ctxt_args (K m);
wenzelm@5884
   628
wenzelm@5884
   629
wenzelm@5884
   630
(* sections *)
wenzelm@5824
   631
wenzelm@17110
   632
type modifier = (ProofContext.context -> ProofContext.context) * ProofContext.context attribute;
wenzelm@7268
   633
wenzelm@7268
   634
local
wenzelm@7268
   635
wenzelm@8381
   636
fun sect ss = Scan.first (map Scan.lift ss);
wenzelm@5884
   637
fun thms ss = Scan.unless (sect ss) Attrib.local_thms;
skalberg@15570
   638
fun thmss ss = Scan.repeat (thms ss) >> List.concat;
wenzelm@5884
   639
wenzelm@7268
   640
fun apply (f, att) (ctxt, ths) = Thm.applys_attributes ((f ctxt, ths), [att]);
wenzelm@5824
   641
wenzelm@7268
   642
fun section ss = (sect ss -- thmss ss) :-- (fn (m, ths) => Scan.depend (fn ctxt =>
wenzelm@7268
   643
  Scan.succeed (apply m (ctxt, ths)))) >> #2;
wenzelm@5884
   644
wenzelm@7601
   645
fun sectioned args ss = args -- Scan.repeat (section ss);
wenzelm@5884
   646
wenzelm@7268
   647
in
wenzelm@5824
   648
wenzelm@5884
   649
fun sectioned_args args ss f src ctxt =
wenzelm@8282
   650
  let val (ctxt', (x, _)) = syntax (sectioned args ss) src ctxt
wenzelm@5921
   651
  in f x ctxt' end;
wenzelm@5884
   652
wenzelm@7601
   653
fun bang_sectioned_args ss f = sectioned_args Args.bang_facts ss f;
wenzelm@9777
   654
fun bang_sectioned_args' ss scan f =
wenzelm@9777
   655
  sectioned_args (Args.bang_facts -- scan >> swap) ss (uncurry f);
wenzelm@7601
   656
fun only_sectioned_args ss f = sectioned_args (Scan.succeed ()) ss (fn () => f);
wenzelm@7268
   657
wenzelm@8093
   658
fun thms_ctxt_args f = sectioned_args (thmss []) [] f;
wenzelm@8093
   659
fun thms_args f = thms_ctxt_args (K o f);
wenzelm@9706
   660
fun thm_args f = thms_args (fn [thm] => f thm | _ => error "Single theorem expected");
wenzelm@5824
   661
wenzelm@7268
   662
end;
wenzelm@7268
   663
wenzelm@5824
   664
nipkow@17587
   665
(* iprover syntax *)
wenzelm@12347
   666
wenzelm@12347
   667
local
wenzelm@12347
   668
wenzelm@12347
   669
val introN = "intro";
wenzelm@12347
   670
val elimN = "elim";
wenzelm@12347
   671
val destN = "dest";
wenzelm@12347
   672
val ruleN = "rule";
wenzelm@12347
   673
wenzelm@12347
   674
fun modifier name kind kind' att =
skalberg@15531
   675
  Args.$$$ name |-- (kind >> K NONE || kind' |-- Args.nat --| Args.colon >> SOME)
wenzelm@17110
   676
    >> (pair (I: ProofContext.context -> ProofContext.context) o att);
wenzelm@12347
   677
nipkow@17587
   678
val iprover_modifiers =
wenzelm@12384
   679
 [modifier destN Args.bang_colon Args.bang ContextRules.dest_bang_local,
wenzelm@12350
   680
  modifier destN Args.colon (Scan.succeed ()) ContextRules.dest_local,
wenzelm@12350
   681
  modifier elimN Args.bang_colon Args.bang ContextRules.elim_bang_local,
wenzelm@12350
   682
  modifier elimN Args.colon (Scan.succeed ()) ContextRules.elim_local,
wenzelm@12350
   683
  modifier introN Args.bang_colon Args.bang ContextRules.intro_bang_local,
wenzelm@12350
   684
  modifier introN Args.colon (Scan.succeed ()) ContextRules.intro_local,
wenzelm@12350
   685
  Args.del -- Args.colon >> K (I, ContextRules.rule_del_local)];
wenzelm@12347
   686
wenzelm@12347
   687
in
wenzelm@12347
   688
nipkow@17587
   689
fun iprover_args m = bang_sectioned_args' iprover_modifiers (Scan.lift (Scan.option Args.nat)) m;
wenzelm@12347
   690
nipkow@17587
   691
fun iprover_meth n prems ctxt = METHOD (fn facts =>
nipkow@17587
   692
  HEADGOAL (insert_tac (prems @ facts) THEN' ObjectLogic.atomize_tac THEN' iprover_tac ctxt n));
wenzelm@12347
   693
wenzelm@12347
   694
end;
wenzelm@12347
   695
wenzelm@12347
   696
wenzelm@9539
   697
(* tactic syntax *)
wenzelm@8238
   698
wenzelm@10744
   699
fun nat_thms_args f = uncurry f oo
wenzelm@10744
   700
  (#2 oo syntax (Scan.lift (Scan.optional (Args.parens Args.nat) 0) -- Attrib.local_thmss));
wenzelm@10744
   701
wenzelm@8238
   702
val insts =
wenzelm@9539
   703
  Scan.optional
wenzelm@9565
   704
    (Args.enum1 "and" (Scan.lift (Args.name -- (Args.$$$ "=" |-- Args.!!! Args.name))) --|
wenzelm@9565
   705
      Scan.lift (Args.$$$ "in")) [] -- Attrib.local_thmss;
wenzelm@8238
   706
wenzelm@12119
   707
fun inst_args f src ctxt = f ctxt (#2 (syntax (Args.goal_spec HEADGOAL -- insts) src ctxt));
wenzelm@8537
   708
ballarin@14174
   709
val insts_var =
ballarin@14174
   710
  Scan.optional
ballarin@14174
   711
    (Args.enum1 "and" (Scan.lift (Args.var -- (Args.$$$ "=" |-- Args.!!! Args.name))) --|
ballarin@14174
   712
      Scan.lift (Args.$$$ "in")) [] -- Attrib.local_thmss;
ballarin@14174
   713
wenzelm@17110
   714
fun inst_args_var f src ctxt =
wenzelm@17110
   715
  f ctxt (#2 (syntax (Args.goal_spec HEADGOAL -- insts_var) src ctxt));
wenzelm@8537
   716
wenzelm@12119
   717
fun goal_args' args tac src ctxt = #2 (syntax (Args.goal_spec HEADGOAL -- args >>
ballarin@14215
   718
  (fn (quant, s) => SIMPLE_METHOD' quant (tac s))) src ctxt);
wenzelm@8537
   719
wenzelm@9539
   720
fun goal_args args tac = goal_args' (Scan.lift args) tac;
wenzelm@8238
   721
ballarin@14174
   722
fun goal_args_ctxt' args tac src ctxt =
ballarin@14174
   723
  #2 (syntax (Args.goal_spec HEADGOAL -- args >>
ballarin@14174
   724
  (fn (quant, s) => SIMPLE_METHOD' quant (tac ctxt s))) src ctxt);
wenzelm@8238
   725
ballarin@14174
   726
fun goal_args_ctxt args tac = goal_args_ctxt' (Scan.lift args) tac;
wenzelm@5824
   727
wenzelm@14718
   728
wenzelm@9539
   729
(* misc tactic emulations *)
wenzelm@9539
   730
ballarin@14174
   731
val subgoal_meth = goal_args_ctxt (Scan.repeat1 Args.name) subgoals_tac;
ballarin@14174
   732
val thin_meth = goal_args_ctxt Args.name thin_tac;
wenzelm@9539
   733
val rename_meth = goal_args (Scan.repeat1 Args.name) Tactic.rename_params_tac;
wenzelm@9631
   734
val rotate_meth = goal_args (Scan.optional Args.int 1) Tactic.rotate_tac;
wenzelm@9539
   735
wenzelm@9539
   736
wenzelm@5824
   737
(* pure_methods *)
wenzelm@5824
   738
wenzelm@5824
   739
val pure_methods =
wenzelm@5824
   740
 [("fail", no_args fail, "force failure"),
wenzelm@5824
   741
  ("succeed", no_args succeed, "succeed"),
wenzelm@9587
   742
  ("-", no_args insert_facts, "do nothing (insert current facts only)"),
wenzelm@9539
   743
  ("insert", thms_args insert, "insert theorems, ignoring facts (improper)"),
wenzelm@16145
   744
  ("unfold", thms_args unfold_meth, "unfold definitions"),
wenzelm@12384
   745
  ("intro", thms_args intro, "repeatedly apply introduction rules"),
wenzelm@12384
   746
  ("elim", thms_args elim, "repeatedly apply elimination rules"),
wenzelm@16145
   747
  ("fold", thms_args fold_meth, "fold definitions"),
wenzelm@12829
   748
  ("atomize", (atomize o #2) oo syntax (Args.mode "full"),
wenzelm@11962
   749
    "present local premises as object-level statements"),
nipkow@17587
   750
  ("iprover", iprover_args iprover_meth, "intuitionistic proof search"),
wenzelm@12384
   751
  ("rule", thms_ctxt_args some_rule, "apply some intro/elim rule"),
wenzelm@10744
   752
  ("erule", nat_thms_args erule, "apply rule in elimination manner (improper)"),
wenzelm@10744
   753
  ("drule", nat_thms_args drule, "apply rule in destruct manner (improper)"),
wenzelm@10744
   754
  ("frule", nat_thms_args frule, "apply rule in forward manner (improper)"),
wenzelm@8195
   755
  ("this", no_args this, "apply current facts as rules"),
wenzelm@8238
   756
  ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
ballarin@14174
   757
  ("rule_tac", inst_args_var res_inst_meth, "apply rule (dynamic instantiation)"),
ballarin@14174
   758
  ("erule_tac", inst_args_var eres_inst_meth, "apply rule in elimination manner (dynamic instantiation)"),
ballarin@14174
   759
  ("drule_tac", inst_args_var dres_inst_meth, "apply rule in destruct manner (dynamic instantiation)"),
ballarin@14174
   760
  ("frule_tac", inst_args_var forw_inst_meth, "apply rule in forward manner (dynamic instantiation)"),
ballarin@14174
   761
  ("cut_tac", inst_args_var cut_inst_meth, "cut rule (dynamic instantiation)"),
ballarin@14174
   762
  ("subgoal_tac", subgoal_meth, "insert subgoal (dynamic instantiation)"),
ballarin@14174
   763
  ("thin_tac", thin_meth, "remove premise (dynamic instantiation)"),
ballarin@14174
   764
  ("rename_tac", rename_meth, "rename parameters of goal (dynamic instantiation)"),
wenzelm@9631
   765
  ("rotate_tac", rotate_meth, "rotate assumptions of goal"),
wenzelm@8351
   766
  ("tactic", simple_args Args.name tactic, "ML tactic as proof method")];
wenzelm@5824
   767
wenzelm@15801
   768
val _ = Context.add_setup [add_methods pure_methods];
wenzelm@5824
   769
wenzelm@5824
   770
wenzelm@16145
   771
(*final declarations of this structure!*)
wenzelm@16145
   772
val unfold = unfold_meth;
wenzelm@16145
   773
val fold = fold_meth;
wenzelm@16145
   774
wenzelm@5824
   775
end;
wenzelm@5824
   776
wenzelm@5824
   777
structure BasicMethod: BASIC_METHOD = Method;
wenzelm@5824
   778
open BasicMethod;