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