src/Pure/Isar/method.ML
author wenzelm
Mon, 23 Jul 2007 14:06:12 +0200
changeset 23922 707639e9497d
parent 23655 d2d1138e0ddc
child 23937 66e1f24d655d
permissions -rw-r--r--
marked some CRITICAL sections (for multithreading);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/method.ML
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     4
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
     5
Isar proof methods.
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     6
*)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     7
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     8
signature BASIC_METHOD =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     9
sig
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    10
  val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    11
  val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    12
  type method
11731
1a0c1ef86518 added trace_rules, trace;
wenzelm
parents: 10907
diff changeset
    13
  val trace_rules: bool ref
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    14
  val print_methods: theory -> unit
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    15
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    16
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    17
signature METHOD =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    18
sig
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    19
  include BASIC_METHOD
18227
d4cfa0fee007 moved multi_resolve(s) to drule.ML;
wenzelm
parents: 18145
diff changeset
    20
  val apply: method -> thm list -> cases_tactic
d4cfa0fee007 moved multi_resolve(s) to drule.ML;
wenzelm
parents: 18145
diff changeset
    21
  val RAW_METHOD_CASES: (thm list -> cases_tactic) -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    22
  val RAW_METHOD: (thm list -> tactic) -> method
18227
d4cfa0fee007 moved multi_resolve(s) to drule.ML;
wenzelm
parents: 18145
diff changeset
    23
  val METHOD_CASES: (thm list -> cases_tactic) -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    24
  val METHOD: (thm list -> tactic) -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    25
  val fail: method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    26
  val succeed: method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    27
  val insert_tac: thm list -> int -> tactic
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    28
  val insert: thm list -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    29
  val insert_facts: method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    30
  val SIMPLE_METHOD: tactic -> method
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
    31
  val SIMPLE_METHOD': (int -> tactic) -> method
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
    32
  val SIMPLE_METHOD'': ((int -> tactic) -> tactic) -> (int -> tactic) -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    33
  val defer: int option -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    34
  val prefer: int -> method
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    35
  val cheating: bool -> Proof.context -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    36
  val intro: thm list -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    37
  val elim: thm list -> method
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    38
  val unfold: thm list -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    39
  val fold: thm list -> Proof.context -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    40
  val atomize: bool -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    41
  val this: method
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    42
  val fact: thm list -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    43
  val assumption: Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    44
  val close: bool -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    45
  val trace: Proof.context -> thm list -> unit
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5921
diff changeset
    46
  val rule_tac: thm list -> thm list -> int -> tactic
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    47
  val some_rule_tac: thm list -> Proof.context -> thm list -> int -> tactic
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    48
  val rule: thm list -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    49
  val erule: int -> thm list -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    50
  val drule: int -> thm list -> method
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    51
  val frule: int -> thm list -> method
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    52
  val iprover_tac: Proof.context -> int option -> int -> tactic
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    53
  val set_tactic: (Proof.context -> thm list -> tactic) -> unit
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    54
  val tactic: string -> Proof.context -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    55
  type src
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    56
  datatype text =
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
    57
    Basic of (Proof.context -> method) * Position.T |
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    58
    Source of src |
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
    59
    Source_i of src |
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    60
    Then of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    61
    Orelse of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    62
    Try of text |
19186
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
    63
    Repeat1 of text |
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
    64
    SelectGoals of int * text
17857
810a67ecbc64 added primitive_text, succeed_text;
wenzelm
parents: 17756
diff changeset
    65
  val primitive_text: (thm -> thm) -> text
810a67ecbc64 added primitive_text, succeed_text;
wenzelm
parents: 17756
diff changeset
    66
  val succeed_text: text
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    67
  val default_text: text
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    68
  val this_text: text
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    69
  val done_text: text
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
    70
  val sorry_text: bool -> text
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
    71
  val finish_text: text option * bool -> Position.T -> text
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    72
  exception METHOD_FAIL of (string * Position.T) * exn
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    73
  val method: theory -> src -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    74
  val method_i: theory -> src -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    75
  val add_methods: (bstring * (src -> Proof.context -> method) * string) list
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    76
    -> theory -> theory
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    77
  val add_method: bstring * (src -> Proof.context -> method) * string
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    78
    -> theory -> theory
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
    79
  val method_setup: bstring * string * string -> theory -> theory
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
    80
  val syntax: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list))
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
    81
    -> src -> Proof.context -> 'a * Proof.context
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    82
  val simple_args: (Args.T list -> 'a * Args.T list)
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    83
    -> ('a -> Proof.context -> method) -> src -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    84
  val ctxt_args: (Proof.context -> method) -> src -> Proof.context -> method
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    85
  val no_args: method -> src -> Proof.context -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    86
  type modifier
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
    87
  val sectioned_args: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    88
    (Args.T list -> modifier * Args.T list) list ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    89
    ('a -> Proof.context -> 'b) -> src -> Proof.context -> 'b
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    90
  val bang_sectioned_args:
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    91
    (Args.T list -> modifier * Args.T list) list ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    92
    (thm list -> Proof.context -> 'a) -> src -> Proof.context -> 'a
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    93
  val bang_sectioned_args':
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    94
    (Args.T list -> modifier * Args.T list) list ->
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
    95
    (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    96
    ('a -> thm list -> Proof.context -> 'b) -> src -> Proof.context -> 'b
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    97
  val only_sectioned_args:
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
    98
    (Args.T list -> modifier * Args.T list) list ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
    99
    (Proof.context -> 'a) -> src -> Proof.context -> 'a
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   100
  val thms_ctxt_args: (thm list -> Proof.context -> 'a) -> src ->
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   101
    Proof.context -> 'a
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   102
  val thms_args: (thm list -> 'a) -> src -> Proof.context -> 'a
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   103
  val thm_args: (thm -> 'a) -> src -> Proof.context -> 'a
9539
7ff8f3516d54 added goal_args(');
wenzelm
parents: 9485
diff changeset
   104
  val goal_args: (Args.T list -> 'a * Args.T list) -> ('a -> int -> tactic)
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   105
    -> src -> Proof.context -> method
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
   106
  val goal_args': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list))
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   107
    -> ('a -> int -> tactic) -> src -> Proof.context -> method
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   108
  val goal_args_ctxt: (Args.T list -> 'a * Args.T list) ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   109
    (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
   110
  val goal_args_ctxt': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   111
    (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
22118
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   112
  val parse: OuterLex.token list -> text * OuterLex.token list
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   113
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   114
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   115
structure Method: METHOD =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   116
struct
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   117
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   118
(** generic tools **)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   119
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   120
(* goal addressing *)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   121
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   122
fun FINDGOAL tac st =
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   123
  let fun find i n = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1) n)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   124
  in find 1 (Thm.nprems_of st) st end;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   125
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   126
fun HEADGOAL tac = tac 1;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   127
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   128
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   129
12324
5db4b4596d1a rule context and attributes moved to rule_context.ML;
wenzelm
parents: 12311
diff changeset
   130
(** proof methods **)
5db4b4596d1a rule context and attributes moved to rule_context.ML;
wenzelm
parents: 12311
diff changeset
   131
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   132
(* datatype method *)
11731
1a0c1ef86518 added trace_rules, trace;
wenzelm
parents: 10907
diff changeset
   133
18227
d4cfa0fee007 moved multi_resolve(s) to drule.ML;
wenzelm
parents: 18145
diff changeset
   134
datatype method = Meth of thm list -> cases_tactic;
11731
1a0c1ef86518 added trace_rules, trace;
wenzelm
parents: 10907
diff changeset
   135
17756
d4a35f82fbb4 minor tweaks for Poplog/ML;
wenzelm
parents: 17587
diff changeset
   136
fun apply (Meth m) = m;
11731
1a0c1ef86518 added trace_rules, trace;
wenzelm
parents: 10907
diff changeset
   137
17756
d4a35f82fbb4 minor tweaks for Poplog/ML;
wenzelm
parents: 17587
diff changeset
   138
val RAW_METHOD_CASES = Meth;
11731
1a0c1ef86518 added trace_rules, trace;
wenzelm
parents: 10907
diff changeset
   139
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   140
fun RAW_METHOD tac = RAW_METHOD_CASES (NO_CASES o tac);
12144
f84eb7334d04 added RAW_METHOD, RAW_METHOD_CASES;
wenzelm
parents: 12119
diff changeset
   141
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   142
fun METHOD_CASES tac = RAW_METHOD_CASES (fn facts =>
21687
f689f729afab reorganized structure Goal vs. Tactic;
wenzelm
parents: 21592
diff changeset
   143
  Seq.THEN (ALLGOALS Goal.conjunction_tac, tac facts));
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   144
21687
f689f729afab reorganized structure Goal vs. Tactic;
wenzelm
parents: 21592
diff changeset
   145
fun METHOD tac = RAW_METHOD (fn facts => ALLGOALS Goal.conjunction_tac THEN tac facts);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   146
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   147
val fail = METHOD (K no_tac);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   148
val succeed = METHOD (K all_tac);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   149
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   150
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   151
(* insert facts *)
7419
wenzelm
parents: 7367
diff changeset
   152
wenzelm
parents: 7367
diff changeset
   153
local
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   154
21579
abd2b4386a63 COMP_INCR;
wenzelm
parents: 20335
diff changeset
   155
fun cut_rule_tac rule =
abd2b4386a63 COMP_INCR;
wenzelm
parents: 20335
diff changeset
   156
  Tactic.rtac (Drule.forall_intr_vars rule COMP_INCR revcut_rl);
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   157
7419
wenzelm
parents: 7367
diff changeset
   158
in
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   159
7419
wenzelm
parents: 7367
diff changeset
   160
fun insert_tac [] i = all_tac
wenzelm
parents: 7367
diff changeset
   161
  | insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts);
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   162
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   163
val insert_facts = METHOD (ALLGOALS o insert_tac);
7664
c151ac595551 insert: ignore facts;
wenzelm
parents: 7611
diff changeset
   164
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms));
7419
wenzelm
parents: 7367
diff changeset
   165
9706
8e48a19fc81e removed METHOD0;
wenzelm
parents: 9653
diff changeset
   166
fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac);
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   167
fun SIMPLE_METHOD'' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac));
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   168
val SIMPLE_METHOD' = SIMPLE_METHOD'' HEADGOAL;
9706
8e48a19fc81e removed METHOD0;
wenzelm
parents: 9653
diff changeset
   169
12324
5db4b4596d1a rule context and attributes moved to rule_context.ML;
wenzelm
parents: 12311
diff changeset
   170
end;
5db4b4596d1a rule context and attributes moved to rule_context.ML;
wenzelm
parents: 12311
diff changeset
   171
9706
8e48a19fc81e removed METHOD0;
wenzelm
parents: 9653
diff changeset
   172
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   173
(* shuffle subgoals *)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   174
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   175
fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1)));
18939
wenzelm
parents: 18921
diff changeset
   176
fun defer opt_i = METHOD (K (Tactic.defer_tac (the_default 1 opt_i)));
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   177
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   178
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   179
(* cheating *)
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   180
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   181
fun cheating int ctxt = METHOD (K (setmp quick_and_dirty (int orelse ! quick_and_dirty)
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   182
    (SkipProof.cheat_tac (ProofContext.theory_of ctxt))));
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   183
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   184
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   185
(* unfold intro/elim rules *)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   186
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   187
fun intro ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.match_tac ths));
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   188
fun elim ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.ematch_tac ths));
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   189
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   190
12384
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   191
(* unfold/fold definitions *)
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   192
18877
2ee8333a2ba1 (un)fold: removed '(raw)' option;
wenzelm
parents: 18841
diff changeset
   193
fun unfold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.unfold_tac ctxt ths));
2ee8333a2ba1 (un)fold: removed '(raw)' option;
wenzelm
parents: 18841
diff changeset
   194
fun fold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.fold_tac ctxt ths));
6532
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   195
12384
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   196
12829
c92128238f85 full_atomize;
wenzelm
parents: 12399
diff changeset
   197
(* atomize rule statements *)
c92128238f85 full_atomize;
wenzelm
parents: 12399
diff changeset
   198
23590
ad95084a5c63 renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents: 23577
diff changeset
   199
fun atomize false = SIMPLE_METHOD' (CHANGED_PROP o ObjectLogic.atomize_prems_tac)
12829
c92128238f85 full_atomize;
wenzelm
parents: 12399
diff changeset
   200
  | atomize true = RAW_METHOD (K (HEADGOAL (CHANGED_PROP o ObjectLogic.full_atomize_tac)));
c92128238f85 full_atomize;
wenzelm
parents: 12399
diff changeset
   201
c92128238f85 full_atomize;
wenzelm
parents: 12399
diff changeset
   202
18039
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   203
(* this -- resolve facts directly *)
12384
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   204
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   205
val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac));
9484
3bda55143260 (un)fold: CHANGED;
wenzelm
parents: 9418
diff changeset
   206
3bda55143260 (un)fold: CHANGED;
wenzelm
parents: 9418
diff changeset
   207
18039
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   208
(* fact -- composition by facts from context *)
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   209
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   210
fun fact [] ctxt = SIMPLE_METHOD' (ProofContext.some_fact_tac ctxt)
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   211
  | fact rules _ = SIMPLE_METHOD' (ProofContext.fact_tac rules);
18039
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   212
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   213
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   214
(* assumption *)
7419
wenzelm
parents: 7367
diff changeset
   215
wenzelm
parents: 7367
diff changeset
   216
local
wenzelm
parents: 7367
diff changeset
   217
19778
f0a318495ca4 assm_tac: try rule termI;
wenzelm
parents: 19482
diff changeset
   218
fun cond_rtac cond rule = SUBGOAL (fn (prop, i) =>
f0a318495ca4 assm_tac: try rule termI;
wenzelm
parents: 19482
diff changeset
   219
  if cond (Logic.strip_assums_concl prop)
f0a318495ca4 assm_tac: try rule termI;
wenzelm
parents: 19482
diff changeset
   220
  then Tactic.rtac rule i else no_tac);
7419
wenzelm
parents: 7367
diff changeset
   221
23395
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   222
fun legacy_tac ctxt st =
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   223
  (legacy_feature ("implicit use of prems in assumption proof" ^ ContextPosition.str_of ctxt);
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   224
    all_tac st);
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   225
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   226
fun assm_tac ctxt =
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   227
  assume_tac APPEND'
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   228
  Goal.assume_rule_tac ctxt APPEND'
23395
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   229
  (CHANGED o solve_tac (Assumption.prems_of ctxt) THEN' K (legacy_tac ctxt)) APPEND'
19778
f0a318495ca4 assm_tac: try rule termI;
wenzelm
parents: 19482
diff changeset
   230
  cond_rtac (can Logic.dest_equals) Drule.reflexive_thm APPEND'
f0a318495ca4 assm_tac: try rule termI;
wenzelm
parents: 19482
diff changeset
   231
  cond_rtac (can Logic.dest_term) Drule.termI;
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   232
7419
wenzelm
parents: 7367
diff changeset
   233
in
wenzelm
parents: 7367
diff changeset
   234
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   235
fun assumption ctxt = METHOD (HEADGOAL o
23395
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   236
  (fn [] => assm_tac ctxt
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   237
    | [fact] => solve_tac [fact]
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   238
    | _ => K no_tac));
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   239
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   240
fun close immed ctxt = METHOD (K
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   241
  (FILTER Thm.no_prems
23395
15fb6637690e method assumption: uniform treatment of prems as legacy feature;
wenzelm
parents: 23349
diff changeset
   242
    ((if immed then ALLGOALS (assm_tac ctxt) else all_tac) THEN flexflex_tac)));
7419
wenzelm
parents: 7367
diff changeset
   243
wenzelm
parents: 7367
diff changeset
   244
end;
wenzelm
parents: 7367
diff changeset
   245
wenzelm
parents: 7367
diff changeset
   246
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   247
(* rule etc. -- single-step refinements *)
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   248
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   249
val trace_rules = ref false;
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   250
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   251
fun trace ctxt rules =
21962
279b129498b6 removed conditional combinator;
wenzelm
parents: 21879
diff changeset
   252
  if ! trace_rules andalso not (null rules) then
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   253
    Pretty.big_list "rules:" (map (ProofContext.pretty_thm ctxt) rules)
21962
279b129498b6 removed conditional combinator;
wenzelm
parents: 21879
diff changeset
   254
    |> Pretty.string_of |> tracing
279b129498b6 removed conditional combinator;
wenzelm
parents: 21879
diff changeset
   255
  else ();
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   256
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   257
local
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   258
18841
edecd40194c1 method (un)folded: option '(raw)';
wenzelm
parents: 18824
diff changeset
   259
fun gen_rule_tac tac rules facts =
edecd40194c1 method (un)folded: option '(raw)';
wenzelm
parents: 18824
diff changeset
   260
  (fn i => fn st =>
edecd40194c1 method (un)folded: option '(raw)';
wenzelm
parents: 18824
diff changeset
   261
    if null facts then tac rules i st
edecd40194c1 method (un)folded: option '(raw)';
wenzelm
parents: 18824
diff changeset
   262
    else Seq.maps (fn rule => (tac o single) rule i st) (Drule.multi_resolves facts rules))
21687
f689f729afab reorganized structure Goal vs. Tactic;
wenzelm
parents: 21592
diff changeset
   263
  THEN_ALL_NEW Goal.norm_hhf_tac;
7130
a17f7b5ac40f added erule;
wenzelm
parents: 6981
diff changeset
   264
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   265
fun gen_arule_tac tac j rules facts =
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   266
  EVERY' (gen_rule_tac tac rules facts :: replicate j Tactic.assume_tac);
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   267
11785
3087d6f19adc intro! and elim! rules;
wenzelm
parents: 11765
diff changeset
   268
fun gen_some_rule_tac tac arg_rules ctxt facts = SUBGOAL (fn (goal, i) =>
3087d6f19adc intro! and elim! rules;
wenzelm
parents: 11765
diff changeset
   269
  let
3087d6f19adc intro! and elim! rules;
wenzelm
parents: 11765
diff changeset
   270
    val rules =
3087d6f19adc intro! and elim! rules;
wenzelm
parents: 11765
diff changeset
   271
      if not (null arg_rules) then arg_rules
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19307
diff changeset
   272
      else flat (ContextRules.find_rules false facts goal ctxt)
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12007
diff changeset
   273
  in trace ctxt rules; tac rules facts i end);
10309
a7f961fb62c6 intro_classes by default;
wenzelm
parents: 10034
diff changeset
   274
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   275
fun meth tac x = METHOD (HEADGOAL o tac x);
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   276
fun meth' tac x y = METHOD (HEADGOAL o tac x y);
8220
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   277
7419
wenzelm
parents: 7367
diff changeset
   278
in
wenzelm
parents: 7367
diff changeset
   279
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   280
val rule_tac = gen_rule_tac Tactic.resolve_tac;
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   281
val rule = meth rule_tac;
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   282
val some_rule_tac = gen_some_rule_tac rule_tac;
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   283
val some_rule = meth' some_rule_tac;
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   284
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   285
val erule = meth' (gen_arule_tac Tactic.eresolve_tac);
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   286
val drule = meth' (gen_arule_tac Tactic.dresolve_tac);
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   287
val frule = meth' (gen_arule_tac Tactic.forward_tac);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   288
7419
wenzelm
parents: 7367
diff changeset
   289
end;
wenzelm
parents: 7367
diff changeset
   290
wenzelm
parents: 7367
diff changeset
   291
17587
760c6ade4ab6 renamed "rules" to "iprover"
nipkow
parents: 17496
diff changeset
   292
(* iprover -- intuitionistic proof search *)
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   293
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   294
local
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   295
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   296
val remdups_tac = SUBGOAL (fn (g, i) =>
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   297
  let val prems = Logic.strip_assums_hyp g in
19046
bc5c6c9b114e removed distinct, renamed gen_distinct to distinct;
wenzelm
parents: 18999
diff changeset
   298
    REPEAT_DETERM_N (length prems - length (distinct op aconv prems))
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   299
    (Tactic.ematch_tac [Drule.remdups_rl] i THEN Tactic.eq_assume_tac i)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   300
  end);
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   301
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   302
fun REMDUPS tac = tac THEN_ALL_NEW remdups_tac;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   303
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   304
val bires_tac = Tactic.biresolution_from_nets_tac ContextRules.orderlist;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   305
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   306
fun safe_step_tac ctxt =
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   307
  ContextRules.Swrap ctxt
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   308
   (eq_assume_tac ORELSE'
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   309
    bires_tac true (ContextRules.netpair_bang ctxt));
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   310
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   311
fun unsafe_step_tac ctxt =
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   312
  ContextRules.wrap ctxt
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   313
   (assume_tac APPEND'
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   314
    bires_tac false (ContextRules.netpair_bang ctxt) APPEND'
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   315
    bires_tac false (ContextRules.netpair ctxt));
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   316
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   317
fun step_tac ctxt i =
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   318
  REPEAT_DETERM1 (REMDUPS (safe_step_tac ctxt) i) ORELSE
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   319
  REMDUPS (unsafe_step_tac ctxt) i;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   320
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   321
fun intprover_tac ctxt gs d lim = SUBGOAL (fn (g, i) => if d > lim then no_tac else
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   322
  let
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   323
    val ps = Logic.strip_assums_hyp g;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   324
    val c = Logic.strip_assums_concl g;
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   325
  in
18921
f47c46d7d654 canonical member/insert/merge;
wenzelm
parents: 18877
diff changeset
   326
    if member (fn ((ps1, c1), (ps2, c2)) =>
19307
2beb7153e657 moved gen_eq_set to library.ML;
wenzelm
parents: 19186
diff changeset
   327
        c1 aconv c2 andalso
2beb7153e657 moved gen_eq_set to library.ML;
wenzelm
parents: 19186
diff changeset
   328
        length ps1 = length ps2 andalso
2beb7153e657 moved gen_eq_set to library.ML;
wenzelm
parents: 19186
diff changeset
   329
        gen_eq_set (op aconv) (ps1, ps2)) gs (ps, c) then no_tac
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   330
    else (step_tac ctxt THEN_ALL_NEW intprover_tac ctxt ((ps, c) :: gs) (d + 1) lim) i
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   331
  end);
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   332
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   333
in
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   334
17587
760c6ade4ab6 renamed "rules" to "iprover"
nipkow
parents: 17496
diff changeset
   335
fun iprover_tac ctxt opt_lim =
18939
wenzelm
parents: 18921
diff changeset
   336
  SELECT_GOAL (DEEPEN (2, the_default 20 opt_lim) (intprover_tac ctxt [] 0) 4 1);
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   337
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   338
end;
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   339
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   340
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   341
(* ML tactics *)
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   342
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   343
val tactic_ref = ref ((fn _ => raise Match): Proof.context -> thm list -> tactic);
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   344
fun set_tactic f = tactic_ref := f;
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   345
23922
707639e9497d marked some CRITICAL sections (for multithreading);
wenzelm
parents: 23655
diff changeset
   346
fun ml_tactic txt ctxt = CRITICAL (fn () =>
23425
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   347
  (ML_Context.use_mltext
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   348
    ("let fun tactic (ctxt: Proof.context) (facts: thm list) : tactic =\n"
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   349
      ^ txt ^ "\nin Method.set_tactic tactic end") false (SOME (Context.Proof ctxt));
23922
707639e9497d marked some CRITICAL sections (for multithreading);
wenzelm
parents: 23655
diff changeset
   350
    ML_Context.setmp (SOME (Context.Proof ctxt)) (! tactic_ref ctxt)));
23425
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   351
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   352
fun tactic txt ctxt = METHOD (ml_tactic txt ctxt);
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   353
fun raw_tactic txt ctxt = RAW_METHOD (ml_tactic txt ctxt);
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   354
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   355
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   356
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   357
(** method syntax **)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   358
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   359
(* method text *)
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   360
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   361
type src = Args.src;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   362
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   363
datatype text =
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   364
  Basic of (Proof.context -> method) * Position.T |
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   365
  Source of src |
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   366
  Source_i of src |
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   367
  Then of text list |
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   368
  Orelse of text list |
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   369
  Try of text |
19186
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
   370
  Repeat1 of text |
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
   371
  SelectGoals of int * text;
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   372
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   373
fun primitive_text r = Basic (K (SIMPLE_METHOD (PRIMITIVE r)), Position.none);
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   374
val succeed_text = Basic (K succeed, Position.none);
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   375
val default_text = Source (Args.src (("default", []), Position.none));
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   376
val this_text = Basic (K this, Position.none);
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   377
val done_text = Basic (K (SIMPLE_METHOD all_tac), Position.none);
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   378
fun sorry_text int = Basic (cheating int, Position.none);
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   379
23349
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   380
fun finish_text (NONE, immed) pos = Basic (close immed, pos)
23a8345f89f5 Basic text: include position;
wenzelm
parents: 23178
diff changeset
   381
  | finish_text (SOME txt, immed) pos = Then [txt, Basic (close immed, pos)];
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   382
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   383
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   384
(* method definitions *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   385
16448
6c45c5416b79 (RAW_)METHOD_CASES: RuleCases.tactic;
wenzelm
parents: 16347
diff changeset
   386
structure MethodsData = TheoryDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   387
(
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   388
  type T = (((src -> Proof.context -> method) * string) * stamp) NameSpace.table;
16347
9b3265182607 meths: NameSpace.table;
wenzelm
parents: 16145
diff changeset
   389
  val empty = NameSpace.empty_table;
6546
995a66249a9b theory data: copy;
wenzelm
parents: 6532
diff changeset
   390
  val copy = I;
16448
6c45c5416b79 (RAW_)METHOD_CASES: RuleCases.tactic;
wenzelm
parents: 16347
diff changeset
   391
  val extend = I;
23655
d2d1138e0ddc replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents: 23590
diff changeset
   392
  fun merge _ tables : T = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUP dup =>
d2d1138e0ddc replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents: 23590
diff changeset
   393
    error ("Attempt to merge different versions of method " ^ quote dup);
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   394
);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   395
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   396
fun print_methods thy =
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   397
  let
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   398
    val meths = MethodsData.get thy;
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   399
    fun prt_meth (name, ((_, comment), _)) = Pretty.block
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   400
      [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   401
  in
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   402
    [Pretty.big_list "methods:" (map prt_meth (NameSpace.extern_table meths))]
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   403
    |> Pretty.chunks |> Pretty.writeln
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22586
diff changeset
   404
  end;
7611
5b5aba10c8f6 help: unkown theory context;
wenzelm
parents: 7601
diff changeset
   405
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   406
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   407
(* get methods *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   408
5916
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
   409
exception METHOD_FAIL of (string * Position.T) * exn;
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
   410
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   411
fun method_i thy =
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   412
  let
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   413
    val meths = #2 (MethodsData.get thy);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   414
    fun meth src =
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   415
      let val ((name, _), pos) = Args.dest_src src in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17356
diff changeset
   416
        (case Symtab.lookup meths name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   417
          NONE => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   418
        | SOME ((mth, _), _) => transform_failure (curry METHOD_FAIL (name, pos)) (mth src))
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   419
      end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   420
  in meth end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   421
20030
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   422
fun method thy = method_i thy o Args.map_name (NameSpace.intern (#1 (MethodsData.get thy)));
e62913ef9d24 added method_i and Source_i;
wenzelm
parents: 19778
diff changeset
   423
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   424
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   425
(* add method *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   426
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   427
fun add_methods raw_meths thy =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   428
  let
16145
1bb17485602f renamed cond_extern to extern;
wenzelm
parents: 15973
diff changeset
   429
    val new_meths = raw_meths |> map (fn (name, f, comment) =>
16347
9b3265182607 meths: NameSpace.table;
wenzelm
parents: 16145
diff changeset
   430
      (name, ((f, comment), stamp ())));
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   431
23086
12320f6e2523 tuned Pure/General/name_space.ML
haftmann
parents: 22846
diff changeset
   432
    fun add meths = NameSpace.extend_table (Sign.naming_of thy) new_meths meths
23655
d2d1138e0ddc replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents: 23590
diff changeset
   433
      handle Symtab.DUP dup => error ("Duplicate declaration of method " ^ quote dup);
16347
9b3265182607 meths: NameSpace.table;
wenzelm
parents: 16145
diff changeset
   434
  in MethodsData.map add thy end;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   435
9194
a57987e0250b added add_method;
wenzelm
parents: 8966
diff changeset
   436
val add_method = add_methods o Library.single;
a57987e0250b added add_method;
wenzelm
parents: 8966
diff changeset
   437
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   438
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   439
(* method_setup *)
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   440
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   441
fun method_setup (name, txt, cmt) =
22118
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   442
  ML_Context.use_let
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   443
    "val method: bstring * (Method.src -> Proof.context -> Proof.method) * string"
22086
cf6019fece63 adapted ML context operations;
wenzelm
parents: 21962
diff changeset
   444
    "Context.map_theory (Method.add_method method)"
cf6019fece63 adapted ML context operations;
wenzelm
parents: 21962
diff changeset
   445
    ("(" ^ quote name ^ ", " ^ txt ^ ", " ^ quote cmt ^ ")")
cf6019fece63 adapted ML context operations;
wenzelm
parents: 21962
diff changeset
   446
  |> Context.theory_map;
17356
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   447
09afdf37cdb3 added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents: 17314
diff changeset
   448
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   449
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   450
(** concrete syntax **)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   451
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   452
(* basic *)
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   453
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
   454
fun syntax scan = Args.context_syntax "method" scan;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   455
17110
4c5622d7bdbe moved before proof.ML;
wenzelm
parents: 16876
diff changeset
   456
fun simple_args scan f src ctxt : method =
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   457
  fst (syntax (Scan.lift (scan >> (fn x => f x ctxt))) src ctxt);
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   458
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   459
fun ctxt_args (f: Proof.context -> method) src ctxt =
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   460
  fst (syntax (Scan.succeed (f ctxt)) src ctxt);
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   461
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   462
fun no_args m = ctxt_args (K m);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   463
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   464
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   465
(* sections *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   466
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   467
type modifier = (Proof.context -> Proof.context) * attribute;
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   468
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   469
local
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   470
8381
4fc7e63781f6 sect: exlude ":" from parser;
wenzelm
parents: 8372
diff changeset
   471
fun sect ss = Scan.first (map Scan.lift ss);
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19307
diff changeset
   472
fun thms ss = Scan.repeat (Scan.unless (sect ss) Attrib.multi_thm) >> flat;
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   473
19186
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
   474
fun app (f, att) (context, ths) = foldl_map att (Context.map_proof f context, ths);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   475
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
   476
fun section ss = (sect ss -- thms ss) :-- (fn (m, ths) => Scan.depend (fn context =>
19186
1bf4b5c4a794 text: added SelectGoals;
wenzelm
parents: 19046
diff changeset
   477
  Scan.succeed (app m (context, ths)))) >> #2;
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   478
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   479
fun sectioned args ss = args -- Scan.repeat (section ss);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   480
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   481
in
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   482
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   483
fun sectioned_args args ss f src ctxt =
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   484
  let val ((x, _), ctxt') = syntax (sectioned args ss) src ctxt
5921
50005d6ba609 removed trace;
wenzelm
parents: 5916
diff changeset
   485
  in f x ctxt' end;
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   486
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   487
fun bang_sectioned_args ss f = sectioned_args Args.bang_facts ss f;
9777
232fb8886765 added bang_sectioned_args';
wenzelm
parents: 9706
diff changeset
   488
fun bang_sectioned_args' ss scan f =
232fb8886765 added bang_sectioned_args';
wenzelm
parents: 9706
diff changeset
   489
  sectioned_args (Args.bang_facts -- scan >> swap) ss (uncurry f);
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   490
fun only_sectioned_args ss f = sectioned_args (Scan.succeed ()) ss (fn () => f);
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   491
18999
e0eb9cb97db0 syntax: Context.generic;
wenzelm
parents: 18939
diff changeset
   492
fun thms_ctxt_args f = sectioned_args (thms []) [] f;
8093
d5eb246c94ec added thms_ctxt_args;
wenzelm
parents: 7664
diff changeset
   493
fun thms_args f = thms_ctxt_args (K o f);
9706
8e48a19fc81e removed METHOD0;
wenzelm
parents: 9653
diff changeset
   494
fun thm_args f = thms_args (fn [thm] => f thm | _ => error "Single theorem expected");
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   495
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   496
end;
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   497
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   498
17587
760c6ade4ab6 renamed "rules" to "iprover"
nipkow
parents: 17496
diff changeset
   499
(* iprover syntax *)
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   500
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   501
local
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   502
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   503
val introN = "intro";
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   504
val elimN = "elim";
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   505
val destN = "dest";
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   506
val ruleN = "rule";
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   507
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   508
fun modifier name kind kind' att =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   509
  Args.$$$ name |-- (kind >> K NONE || kind' |-- Args.nat --| Args.colon >> SOME)
20289
ba7a7c56bed5 normalized Proof.context/method type aliases;
wenzelm
parents: 20224
diff changeset
   510
    >> (pair (I: Proof.context -> Proof.context) o att);
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   511
17587
760c6ade4ab6 renamed "rules" to "iprover"
nipkow
parents: 17496
diff changeset
   512
val iprover_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   513
 [modifier destN Args.bang_colon Args.bang ContextRules.dest_bang,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   514
  modifier destN Args.colon (Scan.succeed ()) ContextRules.dest,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   515
  modifier elimN Args.bang_colon Args.bang ContextRules.elim_bang,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   516
  modifier elimN Args.colon (Scan.succeed ()) ContextRules.elim,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   517
  modifier introN Args.bang_colon Args.bang ContextRules.intro_bang,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   518
  modifier introN Args.colon (Scan.succeed ()) ContextRules.intro,
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   519
  Args.del -- Args.colon >> K (I, ContextRules.rule_del)];
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   520
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   521
in
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   522
18640
61627ae3ddc3 generic attributes;
wenzelm
parents: 18474
diff changeset
   523
val iprover_meth =
61627ae3ddc3 generic attributes;
wenzelm
parents: 18474
diff changeset
   524
  bang_sectioned_args' iprover_modifiers (Scan.lift (Scan.option Args.nat))
61627ae3ddc3 generic attributes;
wenzelm
parents: 18474
diff changeset
   525
    (fn n => fn prems => fn ctxt => METHOD (fn facts =>
61627ae3ddc3 generic attributes;
wenzelm
parents: 18474
diff changeset
   526
      HEADGOAL (insert_tac (prems @ facts) THEN'
23590
ad95084a5c63 renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents: 23577
diff changeset
   527
      ObjectLogic.atomize_prems_tac THEN' iprover_tac ctxt n)));
12347
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   528
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   529
end;
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   530
6ee66b76d813 added "rules" method;
wenzelm
parents: 12324
diff changeset
   531
9539
7ff8f3516d54 added goal_args(');
wenzelm
parents: 9485
diff changeset
   532
(* tactic syntax *)
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   533
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   534
fun nat_thms_args f = uncurry f oo
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   535
  (fst oo syntax (Scan.lift (Scan.optional (Args.parens Args.nat) 0) -- Attrib.thms));
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   536
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   537
fun goal_args' args tac src ctxt = fst (syntax (Args.goal_spec HEADGOAL -- args >>
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   538
  (fn (quant, s) => SIMPLE_METHOD'' quant (tac s))) src ctxt);
8537
8abfc72109f2 use Args.goal_spec;
wenzelm
parents: 8519
diff changeset
   539
9539
7ff8f3516d54 added goal_args(');
wenzelm
parents: 9485
diff changeset
   540
fun goal_args args tac = goal_args' (Scan.lift args) tac;
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   541
14174
f3cafd2929d5 Methods rule_tac etc support static (Isar) contexts.
ballarin
parents: 13650
diff changeset
   542
fun goal_args_ctxt' args tac src ctxt =
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   543
  fst (syntax (Args.goal_spec HEADGOAL -- args >>
21592
8831206d7f41 renamed SIMPLE_METHOD' to SIMPLE_METHOD'';
wenzelm
parents: 21579
diff changeset
   544
  (fn (quant, s) => SIMPLE_METHOD'' quant (tac ctxt s))) src ctxt);
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   545
14174
f3cafd2929d5 Methods rule_tac etc support static (Isar) contexts.
ballarin
parents: 13650
diff changeset
   546
fun goal_args_ctxt args tac = goal_args_ctxt' (Scan.lift args) tac;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   547
14718
wenzelm
parents: 14508
diff changeset
   548
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18640
diff changeset
   549
(* theory setup *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   550
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18640
diff changeset
   551
val _ = Context.add_setup (add_methods
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   552
 [("fail", no_args fail, "force failure"),
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   553
  ("succeed", no_args succeed, "succeed"),
9587
1368ce019457 tuned msg;
wenzelm
parents: 9565
diff changeset
   554
  ("-", no_args insert_facts, "do nothing (insert current facts only)"),
9539
7ff8f3516d54 added goal_args(');
wenzelm
parents: 9485
diff changeset
   555
  ("insert", thms_args insert, "insert theorems, ignoring facts (improper)"),
12384
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   556
  ("intro", thms_args intro, "repeatedly apply introduction rules"),
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   557
  ("elim", thms_args elim, "repeatedly apply elimination rules"),
18877
2ee8333a2ba1 (un)fold: removed '(raw)' option;
wenzelm
parents: 18841
diff changeset
   558
  ("unfold", thms_ctxt_args unfold_meth, "unfold definitions"),
2ee8333a2ba1 (un)fold: removed '(raw)' option;
wenzelm
parents: 18841
diff changeset
   559
  ("fold", thms_ctxt_args fold_meth, "fold definitions"),
21879
a3efbae45735 switched argument order in *.syntax lifters
haftmann
parents: 21687
diff changeset
   560
  ("atomize", (atomize o fst) oo syntax (Args.mode "full"),
11962
4c6585866fb2 added "atomize" method;
wenzelm
parents: 11905
diff changeset
   561
    "present local premises as object-level statements"),
18640
61627ae3ddc3 generic attributes;
wenzelm
parents: 18474
diff changeset
   562
  ("iprover", iprover_meth, "intuitionistic proof search"),
12384
86e383f6bfea simple version of 'intro' and 'elim' method;
wenzelm
parents: 12359
diff changeset
   563
  ("rule", thms_ctxt_args some_rule, "apply some intro/elim rule"),
10744
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   564
  ("erule", nat_thms_args erule, "apply rule in elimination manner (improper)"),
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   565
  ("drule", nat_thms_args drule, "apply rule in destruct manner (improper)"),
5d142ca01b8e 'erule' etc.: assm arg;
wenzelm
parents: 10541
diff changeset
   566
  ("frule", nat_thms_args frule, "apply rule in forward manner (improper)"),
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   567
  ("this", no_args this, "apply current facts as rules"),
18039
500b7ed7b2bd added fact method;
wenzelm
parents: 17857
diff changeset
   568
  ("fact", thms_ctxt_args fact, "composition by facts from context"),
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   569
  ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
20335
b5eca86ef9cc moved bires_inst_tac etc. to rule_insts.ML;
wenzelm
parents: 20289
diff changeset
   570
  ("rename_tac", goal_args (Scan.repeat1 Args.name) Tactic.rename_params_tac,
22586
d2008c5f8d99 tuned comment;
wenzelm
parents: 22134
diff changeset
   571
    "rename parameters of goal"),
20335
b5eca86ef9cc moved bires_inst_tac etc. to rule_insts.ML;
wenzelm
parents: 20289
diff changeset
   572
  ("rotate_tac", goal_args (Scan.optional Args.int 1) Tactic.rotate_tac,
b5eca86ef9cc moved bires_inst_tac etc. to rule_insts.ML;
wenzelm
parents: 20289
diff changeset
   573
    "rotate assumptions of goal"),
23425
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   574
  ("tactic", simple_args Args.name tactic, "ML tactic as proof method"),
b74315510f85 added raw_tactic;
wenzelm
parents: 23395
diff changeset
   575
  ("raw_tactic", simple_args Args.name raw_tactic, "ML tactic as raw proof method")]);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   576
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   577
22118
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   578
(* outer parser *)
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   579
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   580
local
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   581
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   582
structure T = OuterLex;
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   583
structure P = OuterParse;
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   584
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   585
fun is_symid_meth s =
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   586
  s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s;
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   587
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   588
fun meth4 x =
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   589
 (P.position (P.xname >> rpair []) >> (Source o Args.src) ||
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   590
  P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   591
and meth3 x =
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   592
 (meth4 --| P.$$$ "?" >> Try ||
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   593
  meth4 --| P.$$$ "+" >> Repeat1 ||
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   594
  meth4 -- (P.$$$ "[" |-- Scan.optional P.nat 1 --| P.$$$ "]") >> (SelectGoals o swap) ||
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   595
  meth4) x
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   596
and meth2 x =
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   597
 (P.position (P.xname -- P.args1 is_symid_meth false) >> (Source o Args.src) ||
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   598
  meth3) x
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   599
and meth1 x = (P.enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   600
and meth0 x = (P.enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x;
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   601
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   602
in val parse = meth3 end;
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   603
16639b216295 removed obsolete Method;
wenzelm
parents: 22086
diff changeset
   604
16145
1bb17485602f renamed cond_extern to extern;
wenzelm
parents: 15973
diff changeset
   605
(*final declarations of this structure!*)
1bb17485602f renamed cond_extern to extern;
wenzelm
parents: 15973
diff changeset
   606
val unfold = unfold_meth;
1bb17485602f renamed cond_extern to extern;
wenzelm
parents: 15973
diff changeset
   607
val fold = fold_meth;
1bb17485602f renamed cond_extern to extern;
wenzelm
parents: 15973
diff changeset
   608
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   609
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   610
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   611
structure BasicMethod: BASIC_METHOD = Method;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   612
open BasicMethod;