src/Pure/Isar/method.ML
author wenzelm
Wed, 08 Mar 2000 23:46:59 +0100
changeset 8381 4fc7e63781f6
parent 8372 7b2cec1e789c
child 8519 981f52707e5d
permissions -rw-r--r--
sect: exlude ":" from parser;
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
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
     5
Proof methods.
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
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    10
  val print_methods: theory -> unit
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    11
  val Method: bstring -> (Args.src -> Proof.context -> Proof.method) -> string -> unit
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    12
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    13
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    14
signature METHOD =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    15
sig
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    16
  include BASIC_METHOD
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    17
  val print_global_rules: theory -> unit
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    18
  val print_local_rules: Proof.context -> unit
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    19
  val dest_global: theory attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    20
  val elim_global: theory attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    21
  val intro_global: theory attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    22
  val delrule_global: theory attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    23
  val dest_local: Proof.context attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    24
  val elim_local: Proof.context attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    25
  val intro_local: Proof.context attribute
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
    26
  val delrule_local: Proof.context attribute
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5921
diff changeset
    27
  val METHOD: (thm list -> tactic) -> Proof.method
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
    28
  val METHOD_CASES:
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
    29
    (thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq) -> Proof.method
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    30
  val METHOD0: tactic -> Proof.method
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    31
  val fail: Proof.method
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    32
  val succeed: Proof.method
8167
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
    33
  val defer: int option -> Proof.method
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
    34
  val prefer: int -> Proof.method
7419
wenzelm
parents: 7367
diff changeset
    35
  val insert_tac: thm list -> int -> tactic
7574
5bcb7fc31caa added 'insert' method (again);
wenzelm
parents: 7555
diff changeset
    36
  val insert: thm list -> Proof.method
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
    37
  val insert_facts: Proof.method
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    38
  val unfold: thm list -> Proof.method
7419
wenzelm
parents: 7367
diff changeset
    39
  val fold: thm list -> Proof.method
wenzelm
parents: 7367
diff changeset
    40
  val multi_resolve: thm list -> thm -> thm Seq.seq
wenzelm
parents: 7367
diff changeset
    41
  val multi_resolves: thm list -> thm list -> thm Seq.seq
8335
4c117393e4e6 added multi_resolveq, resolveq_tac;
wenzelm
parents: 8329
diff changeset
    42
  val resolveq_tac: thm Seq.seq -> int -> tactic
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
    43
  val resolveq_cases_tac: (thm * string list) Seq.seq
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
    44
    -> int -> thm -> (thm * (string * RuleCases.T) list) Seq.seq
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5921
diff changeset
    45
  val rule_tac: thm list -> thm list -> int -> tactic
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5921
diff changeset
    46
  val rule: thm list -> Proof.method
7130
a17f7b5ac40f added erule;
wenzelm
parents: 6981
diff changeset
    47
  val erule: thm list -> Proof.method
8220
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
    48
  val drule: thm list -> Proof.method
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
    49
  val frule: thm list -> Proof.method
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
    50
  val this: Proof.method
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
    51
  val assumption: Proof.context -> Proof.method
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
    52
  val set_tactic: (Proof.context -> thm list -> tactic) -> unit
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
    53
  val tactic: string -> Proof.context -> Proof.method
5916
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
    54
  exception METHOD_FAIL of (string * Position.T) * exn
7611
5b5aba10c8f6 help: unkown theory context;
wenzelm
parents: 7601
diff changeset
    55
  val help_methods: theory option -> unit
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    56
  val method: theory -> Args.src -> Proof.context -> Proof.method
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    57
  val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    58
    -> theory -> theory
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
    59
  val syntax: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8242
diff changeset
    60
    Args.src -> Proof.context -> Proof.context * 'a
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
    61
  val simple_args: (Args.T list -> 'a * Args.T list)
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
    62
    -> ('a -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
    63
  val ctxt_args: (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
    64
  val no_args: Proof.method -> Args.src -> Proof.context -> Proof.method
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
    65
  type modifier
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    66
  val sectioned_args: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
    67
    (Args.T list -> modifier * Args.T list) list ->
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
    68
    ('a -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    69
  val bang_sectioned_args:
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    70
    (Args.T list -> modifier * Args.T list) list ->
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
    71
    (thm list -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    72
  val only_sectioned_args:
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
    73
    (Args.T list -> modifier * Args.T list) list ->
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
    74
    (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
8093
d5eb246c94ec added thms_ctxt_args;
wenzelm
parents: 7664
diff changeset
    75
  val thms_ctxt_args: (thm list -> Proof.context -> Proof.method)
d5eb246c94ec added thms_ctxt_args;
wenzelm
parents: 7664
diff changeset
    76
    -> Args.src -> Proof.context -> Proof.method
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5921
diff changeset
    77
  val thms_args: (thm list -> Proof.method) -> Args.src -> Proof.context -> Proof.method
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    78
  datatype text =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    79
    Basic of (Proof.context -> Proof.method) |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    80
    Source of Args.src |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    81
    Then of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    82
    Orelse of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    83
    Try of text |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    84
    Repeat1 of text
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    85
  val refine: text -> Proof.state -> Proof.state Seq.seq
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
    86
  val refine_end: text -> Proof.state -> Proof.state Seq.seq
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
    87
  val proof: text option -> Proof.state -> Proof.state Seq.seq
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    88
  val local_qed: text option
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    89
    -> ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
6736
a0b2cfa12d0d local_qed: print_result;
wenzelm
parents: 6683
diff changeset
    90
    -> Proof.state -> Proof.state Seq.seq
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    91
  val local_terminal_proof: text * text option
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    92
    -> ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
6736
a0b2cfa12d0d local_qed: print_result;
wenzelm
parents: 6683
diff changeset
    93
    -> Proof.state -> Proof.state Seq.seq
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    94
  val local_immediate_proof: ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    95
    -> Proof.state -> Proof.state Seq.seq
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
    96
  val local_default_proof: ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
6736
a0b2cfa12d0d local_qed: print_result;
wenzelm
parents: 6683
diff changeset
    97
    -> Proof.state -> Proof.state Seq.seq
6951
13399b560e4e global_qed: removed alt_name, alt_att;
wenzelm
parents: 6934
diff changeset
    98
  val global_qed: text option -> Proof.state -> theory * {kind: string, name: string, thm: thm}
6934
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
    99
  val global_terminal_proof: text * text option
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
   100
    -> Proof.state -> theory * {kind: string, name: string, thm: thm}
6532
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   101
  val global_immediate_proof: Proof.state -> theory * {kind: string, name: string, thm: thm}
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   102
  val global_default_proof: Proof.state -> theory * {kind: string, name: string, thm: thm}
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   103
  val setup: (theory -> theory) list
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   104
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   105
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   106
structure Method: METHOD =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   107
struct
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   108
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   109
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   110
(** global and local rule data **)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   111
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   112
fun prt_rules kind ths =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   113
  Pretty.writeln (Pretty.big_list ("standard " ^ kind ^ " rules:") (map Display.pretty_thm ths));
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   114
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   115
fun print_rules (intro, elim) =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   116
  (prt_rules "introduction" intro; prt_rules "elimination" elim);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   117
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   118
fun merge_rules (ths1, ths2) = Library.generic_merge Thm.eq_thm I I ths1 ths2;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   119
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   120
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   121
(* theory data kind 'Isar/rules' *)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   122
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   123
structure GlobalRulesArgs =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   124
struct
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   125
  val name = "Isar/rules";
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   126
  type T = thm list * thm list;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   127
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   128
  val empty = ([], []);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   129
  val copy = I;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   130
  val prep_ext = I;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   131
  fun merge ((intro1, elim1), (intro2, elim2)) =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   132
    (merge_rules (intro1, intro2), merge_rules (elim1, elim2));
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   133
  fun print _ = print_rules;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   134
end;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   135
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   136
structure GlobalRules = TheoryDataFun(GlobalRulesArgs);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   137
val print_global_rules = GlobalRules.print;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   138
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   139
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   140
(* proof data kind 'Isar/rules' *)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   141
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   142
structure LocalRulesArgs =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   143
struct
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   144
  val name = "Isar/rules";
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   145
  type T = thm list * thm list;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   146
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   147
  val init = GlobalRules.get;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   148
  fun print _ = print_rules;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   149
end;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   150
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   151
structure LocalRules = ProofDataFun(LocalRulesArgs);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   152
val print_local_rules = LocalRules.print;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   154
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   155
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   156
(** attributes **)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   157
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   158
(* add rules *)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   159
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   160
local
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   161
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   162
fun add_rule thm rules = Library.gen_ins Thm.eq_thm (thm, rules);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   163
fun del_rule thm rules = Library.gen_rem Thm.eq_thm (rules, thm);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   164
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   165
fun add_dest thm (intro, elim) = (intro, add_rule (Tactic.make_elim thm) elim);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   166
fun add_elim thm (intro, elim) = (intro, add_rule thm elim);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   167
fun add_intro thm (intro, elim) = (add_rule thm intro, elim);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   168
fun delrule thm (intro, elim) = (del_rule thm intro, del_rule thm elim);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   169
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   170
fun mk_att f g (x, thm) = (f (g thm) x, thm);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   171
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   172
in
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   173
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   174
val dest_global = mk_att GlobalRules.map add_dest;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   175
val elim_global = mk_att GlobalRules.map add_elim;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   176
val intro_global = mk_att GlobalRules.map add_intro;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   177
val delrule_global = mk_att GlobalRules.map delrule;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   178
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   179
val dest_local = mk_att LocalRules.map add_dest;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   180
val elim_local = mk_att LocalRules.map add_elim;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   181
val intro_local = mk_att LocalRules.map add_intro;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   182
val delrule_local = mk_att LocalRules.map delrule;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   183
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   184
end;
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   185
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   186
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   187
(* concrete syntax *)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   188
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   189
val rule_atts =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   190
 [("dest", (Attrib.no_args dest_global, Attrib.no_args dest_local), "destruction rule"),
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   191
  ("elim", (Attrib.no_args elim_global, Attrib.no_args elim_local), "elimination rule"),
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   192
  ("intro", (Attrib.no_args intro_global, Attrib.no_args intro_local), "introduction rule"),
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   193
  ("delrule", (Attrib.no_args delrule_global, Attrib.no_args delrule_local), "delete rule")];
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   194
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   195
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   196
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   197
(** proof methods **)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   198
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   199
(* make methods *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   200
6849
0b660860c0ad cond_extern_table;
wenzelm
parents: 6775
diff changeset
   201
val METHOD = Proof.method;
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   202
val METHOD_CASES = Proof.method_cases;
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   203
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   204
fun METHOD0 tac = METHOD (fn [] => tac | _ => error "Method may not be used with facts");
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   205
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   206
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   207
(* primitive *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   208
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   209
val fail = METHOD (K no_tac);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   210
val succeed = METHOD (K all_tac);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   211
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   212
8167
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
   213
(* shuffle *)
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
   214
8240
87e08624e209 fixed prefer;
wenzelm
parents: 8238
diff changeset
   215
fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1)));
8167
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
   216
fun defer opt_i = METHOD (K (Tactic.defer_tac (if_none opt_i 1)));
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
   217
7574835ed01e added prefer, defer;
wenzelm
parents: 8153
diff changeset
   218
7419
wenzelm
parents: 7367
diff changeset
   219
(* insert *)
wenzelm
parents: 7367
diff changeset
   220
wenzelm
parents: 7367
diff changeset
   221
local
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   222
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   223
fun cut_rule_tac raw_rule =
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   224
  let
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   225
    val rule = Drule.forall_intr_vars raw_rule;
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   226
    val revcut_rl = Drule.incr_indexes_wrt [] [] [] [rule] Drule.revcut_rl;
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   227
  in Tactic.rtac (rule COMP revcut_rl) end;
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   228
7419
wenzelm
parents: 7367
diff changeset
   229
in
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   230
7419
wenzelm
parents: 7367
diff changeset
   231
fun insert_tac [] i = all_tac
wenzelm
parents: 7367
diff changeset
   232
  | insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts);
6981
eaade7e398a7 export assumption_tac;
wenzelm
parents: 6951
diff changeset
   233
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   234
val insert_facts = METHOD (ALLGOALS o insert_tac);
7664
c151ac595551 insert: ignore facts;
wenzelm
parents: 7611
diff changeset
   235
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms));
7419
wenzelm
parents: 7367
diff changeset
   236
wenzelm
parents: 7367
diff changeset
   237
end;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   238
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   239
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   240
(* unfold / fold definitions *)
6532
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   241
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   242
fun unfold thms = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN rewrite_goals_tac thms);
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   243
fun fold thms = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN fold_goals_tac thms);
6532
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   244
9d79a304aecc fold / unfold methods;
wenzelm
parents: 6500
diff changeset
   245
7419
wenzelm
parents: 7367
diff changeset
   246
(* multi_resolve *)
wenzelm
parents: 7367
diff changeset
   247
wenzelm
parents: 7367
diff changeset
   248
local
wenzelm
parents: 7367
diff changeset
   249
wenzelm
parents: 7367
diff changeset
   250
fun res th i rule =
wenzelm
parents: 7367
diff changeset
   251
  Thm.biresolution false [(false, th)] i rule handle THM _ => Seq.empty;
wenzelm
parents: 7367
diff changeset
   252
wenzelm
parents: 7367
diff changeset
   253
fun multi_res _ [] rule = Seq.single rule
wenzelm
parents: 7367
diff changeset
   254
  | multi_res i (th :: ths) rule = Seq.flat (Seq.map (res th i) (multi_res (i + 1) ths rule));
wenzelm
parents: 7367
diff changeset
   255
wenzelm
parents: 7367
diff changeset
   256
in
wenzelm
parents: 7367
diff changeset
   257
wenzelm
parents: 7367
diff changeset
   258
val multi_resolve = multi_res 1;
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   259
fun multi_resolves facts rules = Seq.flat (Seq.map (multi_resolve facts) (Seq.of_list rules));
7419
wenzelm
parents: 7367
diff changeset
   260
wenzelm
parents: 7367
diff changeset
   261
end;
wenzelm
parents: 7367
diff changeset
   262
wenzelm
parents: 7367
diff changeset
   263
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   264
(* general rule *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   265
8335
4c117393e4e6 added multi_resolveq, resolveq_tac;
wenzelm
parents: 8329
diff changeset
   266
fun gen_resolveq_tac tac rules i st =
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   267
  Seq.flat (Seq.map (fn rule => tac rule i st) rules);
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   268
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   269
val resolveq_tac = gen_resolveq_tac Tactic.rtac;
8335
4c117393e4e6 added multi_resolveq, resolveq_tac;
wenzelm
parents: 8329
diff changeset
   270
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   271
val resolveq_cases_tac = gen_resolveq_tac (fn (rule, cases) => fn i => fn st =>
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   272
  Seq.map (rpair (RuleCases.make rule cases)) (Tactic.rtac rule i st));
8335
4c117393e4e6 added multi_resolveq, resolveq_tac;
wenzelm
parents: 8329
diff changeset
   273
4c117393e4e6 added multi_resolveq, resolveq_tac;
wenzelm
parents: 8329
diff changeset
   274
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   275
(* simple rule *)
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   276
7419
wenzelm
parents: 7367
diff changeset
   277
local
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   278
7130
a17f7b5ac40f added erule;
wenzelm
parents: 6981
diff changeset
   279
fun gen_rule_tac tac rules [] = tac rules
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   280
  | gen_rule_tac tac erules facts = gen_resolveq_tac (tac o single) (multi_resolves facts erules);
7130
a17f7b5ac40f added erule;
wenzelm
parents: 6981
diff changeset
   281
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   282
fun gen_rule tac rules = METHOD (FINDGOAL o tac rules);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   283
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   284
fun gen_rule' tac arg_rules ctxt = METHOD (fn facts =>
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   285
  let val rules =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   286
    if not (null arg_rules) then arg_rules
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   287
    else if null facts then #1 (LocalRules.get ctxt)
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   288
    else op @ (LocalRules.get ctxt);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   289
  in FINDGOAL (tac rules facts) end);
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   290
8220
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   291
fun setup raw_tac =
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   292
  let val tac = gen_rule_tac raw_tac
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   293
  in (tac, gen_rule tac, gen_rule' tac) end;
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   294
7419
wenzelm
parents: 7367
diff changeset
   295
in
wenzelm
parents: 7367
diff changeset
   296
8220
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   297
val (rule_tac, rule, some_rule) = setup Tactic.resolve_tac;
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   298
val (erule_tac, erule, some_erule) = setup Tactic.eresolve_tac;
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   299
val (drule_tac, drule, some_drule) = setup Tactic.dresolve_tac;
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   300
val (frule_tac, frule, some_frule) = setup Tactic.forward_tac;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   301
7419
wenzelm
parents: 7367
diff changeset
   302
end;
wenzelm
parents: 7367
diff changeset
   303
wenzelm
parents: 7367
diff changeset
   304
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   305
(* this *)
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   306
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   307
val this = METHOD (EVERY o map (FINDGOAL o Tactic.rtac));
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   308
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   309
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   310
(* assumption *)
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   311
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   312
fun assm_tac ctxt =
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   313
  assume_tac APPEND' resolve_tac (filter Thm.no_prems (ProofContext.prems_of ctxt));
7419
wenzelm
parents: 7367
diff changeset
   314
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   315
fun assumption_tac ctxt [] = assm_tac ctxt
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   316
  | assumption_tac _ [fact] = resolve_tac [fact]
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   317
  | assumption_tac _ _ = K no_tac;
7419
wenzelm
parents: 7367
diff changeset
   318
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   319
fun assumption ctxt = METHOD (FINDGOAL o assumption_tac ctxt);
7419
wenzelm
parents: 7367
diff changeset
   320
wenzelm
parents: 7367
diff changeset
   321
8329
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   322
(* res_inst_tac emulations *)
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   323
8329
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   324
(*Note: insts refer to the implicit (!) goal context; use at your own risk*)
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   325
fun gen_res_inst tac ((i, insts), thm) =
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   326
  METHOD (fn facts => (insert_tac facts THEN' tac insts thm) i);
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   327
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   328
val res_inst = gen_res_inst Tactic.res_inst_tac;
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   329
val eres_inst = gen_res_inst Tactic.eres_inst_tac;
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   330
val dres_inst = gen_res_inst Tactic.dres_inst_tac;
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   331
val forw_inst = gen_res_inst Tactic.forw_inst_tac;
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   332
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   333
8329
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   334
(* simple Prolog interpreter *)
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   335
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   336
fun prolog_tac rules facts =
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   337
  DEPTH_SOLVE_1 (HEADGOAL (Tactic.assume_tac APPEND' Tactic.resolve_tac (facts @ rules)));
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   338
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   339
val prolog = METHOD o prolog_tac;
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   340
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   341
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   342
(* ML tactics *)
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   343
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   344
val tactic_ref = ref ((fn _ => raise Match): Proof.context -> thm list -> tactic);
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   345
fun set_tactic f = tactic_ref := f;
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   346
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   347
fun tactic txt ctxt = METHOD (fn facts =>
8372
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   348
 (Context.use_mltext
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   349
   ("let fun (tactic: Proof.context -> thm list -> tactic) ctxt facts = \
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   350
    \let val thm = ProofContext.get_thm ctxt and thms = ProofContext.get_thms ctxt in\n"
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   351
    ^ txt ^
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   352
    "\nend in Method.set_tactic tactic end")
7b2cec1e789c added METHOD_CASES, resolveq_cases_tac;
wenzelm
parents: 8351
diff changeset
   353
  false (Some (ProofContext.theory_of ctxt)); ! tactic_ref ctxt facts));
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
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   357
(** methods theory data **)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   358
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   359
(* data kind 'Isar/methods' *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   360
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   361
structure MethodsDataArgs =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   362
struct
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   363
  val name = "Isar/methods";
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   364
  type T =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   365
    {space: NameSpace.T,
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   366
     meths: (((Args.src -> Proof.context -> Proof.method) * string) * stamp) Symtab.table};
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   367
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   368
  val empty = {space = NameSpace.empty, meths = Symtab.empty};
6546
995a66249a9b theory data: copy;
wenzelm
parents: 6532
diff changeset
   369
  val copy = I;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   370
  val prep_ext = I;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   371
  fun merge ({space = space1, meths = meths1}, {space = space2, meths = meths2}) =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   372
    {space = NameSpace.merge (space1, space2),
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   373
      meths = Symtab.merge eq_snd (meths1, meths2) handle Symtab.DUPS dups =>
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   374
        error ("Attempt to merge different versions of methods " ^ commas_quote dups)};
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   375
7367
a79d4683fadf print_help;
wenzelm
parents: 7268
diff changeset
   376
  fun print_meths verbose {space, meths} =
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   377
    let
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   378
      fun prt_meth (name, ((_, comment), _)) = Pretty.block
6849
0b660860c0ad cond_extern_table;
wenzelm
parents: 6775
diff changeset
   379
        [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   380
    in
7367
a79d4683fadf print_help;
wenzelm
parents: 7268
diff changeset
   381
      if not verbose then ()
a79d4683fadf print_help;
wenzelm
parents: 7268
diff changeset
   382
      else Pretty.writeln (Display.pretty_name_space ("method name space", space));
6849
0b660860c0ad cond_extern_table;
wenzelm
parents: 6775
diff changeset
   383
      Pretty.writeln (Pretty.big_list "methods:"
0b660860c0ad cond_extern_table;
wenzelm
parents: 6775
diff changeset
   384
        (map prt_meth (NameSpace.cond_extern_table space meths)))
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   385
    end;
7367
a79d4683fadf print_help;
wenzelm
parents: 7268
diff changeset
   386
a79d4683fadf print_help;
wenzelm
parents: 7268
diff changeset
   387
  fun print _ = print_meths true;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   388
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   389
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   390
structure MethodsData = TheoryDataFun(MethodsDataArgs);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   391
val print_methods = MethodsData.print;
7611
5b5aba10c8f6 help: unkown theory context;
wenzelm
parents: 7601
diff changeset
   392
5b5aba10c8f6 help: unkown theory context;
wenzelm
parents: 7601
diff changeset
   393
fun help_methods None = writeln "methods: (unkown theory context)"
5b5aba10c8f6 help: unkown theory context;
wenzelm
parents: 7601
diff changeset
   394
  | help_methods (Some thy) = MethodsDataArgs.print_meths false (MethodsData.get thy);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   395
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   396
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   397
(* get methods *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   398
5916
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
   399
exception METHOD_FAIL of (string * Position.T) * exn;
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
   400
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   401
fun method thy =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   402
  let
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   403
    val {space, meths} = MethodsData.get thy;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   404
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   405
    fun meth src =
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   406
      let
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   407
        val ((raw_name, _), pos) = Args.dest_src src;
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   408
        val name = NameSpace.intern space raw_name;
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   409
      in
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   410
        (case Symtab.lookup (meths, name) of
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   411
          None => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
5916
4039395e29ce exception METHOD_FAIL;
wenzelm
parents: 5884
diff changeset
   412
        | Some ((mth, _), _) => transform_failure (curry METHOD_FAIL (name, pos)) (mth src))
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   413
      end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   414
  in meth end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   415
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   416
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   417
(* add_methods *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   418
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   419
fun add_methods raw_meths thy =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   420
  let
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   421
    val full = Sign.full_name (Theory.sign_of thy);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   422
    val new_meths =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   423
      map (fn (name, f, comment) => (full name, ((f, comment), stamp ()))) raw_meths;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   424
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   425
    val {space, meths} = MethodsData.get thy;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   426
    val space' = NameSpace.extend (space, map fst new_meths);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   427
    val meths' = Symtab.extend (meths, new_meths) handle Symtab.DUPS dups =>
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   428
      error ("Duplicate declaration of method(s) " ^ commas_quote dups);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   429
  in
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   430
    thy |> MethodsData.put {space = space', meths = meths'}
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   431
  end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   432
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   433
(*implicit version*)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   434
fun Method name meth cmt = Context.>> (add_methods [(name, meth, cmt)]);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   435
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   436
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   437
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   438
(** method syntax **)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   439
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   440
(* basic *)
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   441
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   442
fun syntax (scan: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list))) =
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   443
  Args.syntax "method" scan;
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   444
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   445
fun simple_args scan f src ctxt : Proof.method =
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   446
  #2 (syntax (Scan.lift (scan >> (fn x => f x ctxt))) src ctxt);
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   447
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   448
fun ctxt_args (f: Proof.context -> Proof.method) src ctxt =
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8242
diff changeset
   449
  #2 (syntax (Scan.succeed (f ctxt)) src ctxt);
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   450
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   451
fun no_args m = ctxt_args (K m);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   452
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   453
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   454
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   455
(* sections *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   456
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   457
type modifier = (Proof.context -> Proof.context) * Proof.context attribute;
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   458
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   459
local
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   460
8381
4fc7e63781f6 sect: exlude ":" from parser;
wenzelm
parents: 8372
diff changeset
   461
fun sect ss = Scan.first (map Scan.lift ss);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   462
fun thms ss = Scan.unless (sect ss) Attrib.local_thms;
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   463
fun thmss ss = Scan.repeat (thms ss) >> flat;
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   464
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   465
fun apply (f, att) (ctxt, ths) = Thm.applys_attributes ((f ctxt, ths), [att]);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   466
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   467
fun section ss = (sect ss -- thmss ss) :-- (fn (m, ths) => Scan.depend (fn ctxt =>
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   468
  Scan.succeed (apply m (ctxt, ths)))) >> #2;
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   469
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   470
fun sectioned args ss = args -- Scan.repeat (section ss);
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   471
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   472
in
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   473
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   474
fun sectioned_args args ss f src ctxt =
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8242
diff changeset
   475
  let val (ctxt', (x, _)) = syntax (sectioned args ss) src ctxt
5921
50005d6ba609 removed trace;
wenzelm
parents: 5916
diff changeset
   476
  in f x ctxt' end;
5884
113badd4dae5 several args parsers;
wenzelm
parents: 5824
diff changeset
   477
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   478
fun bang_sectioned_args ss f = sectioned_args Args.bang_facts ss f;
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   479
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
   480
8093
d5eb246c94ec added thms_ctxt_args;
wenzelm
parents: 7664
diff changeset
   481
fun thms_ctxt_args f = sectioned_args (thmss []) [] f;
d5eb246c94ec added thms_ctxt_args;
wenzelm
parents: 7664
diff changeset
   482
fun thms_args f = thms_ctxt_args (K o f);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   483
7268
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   484
end;
315655dc361b sectioned_args etc.: more general modifier;
wenzelm
parents: 7130
diff changeset
   485
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   486
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   487
(* insts *)
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   488
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   489
val insts =
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   490
  Scan.lift (Scan.optional (Args.$$$ "(" |-- Args.!!! (Args.nat --| Args.$$$ ")")) 1) --
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   491
    Args.enum1 "and" (Scan.lift (Args.name -- Args.!!! (Args.$$$ "=" |-- Args.name))) --
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   492
    (Scan.lift (Args.$$$ "in") |-- Attrib.local_thm);
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   493
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8242
diff changeset
   494
fun inst_args f = f oo (#2 oo syntax insts);
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   495
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   496
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   497
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   498
(** method text **)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   499
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   500
(* datatype text *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   501
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   502
datatype text =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   503
  Basic of (Proof.context -> Proof.method) |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   504
  Source of Args.src |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   505
  Then of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   506
  Orelse of text list |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   507
  Try of text |
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   508
  Repeat1 of text;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   509
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   510
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   511
(* refine *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   512
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   513
fun gen_refine f text state =
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   514
  let
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   515
    val thy = Proof.theory_of state;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   516
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   517
    fun eval (Basic mth) = f mth
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   518
      | eval (Source src) = f (method thy src)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   519
      | eval (Then txts) = Seq.EVERY (map eval txts)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   520
      | eval (Orelse txts) = Seq.FIRST (map eval txts)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   521
      | eval (Try txt) = Seq.TRY (eval txt)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   522
      | eval (Repeat1 txt) = Seq.REPEAT1 (eval txt);
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   523
  in eval text state end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   524
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   525
val refine = gen_refine Proof.refine;
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   526
val refine_end = gen_refine Proof.refine_end;
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6108
diff changeset
   527
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   528
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6108
diff changeset
   529
(* structured proof steps *)
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   530
7506
08a88d4ebd54 Method.refine_no_facts;
wenzelm
parents: 7504
diff changeset
   531
val default_text = Source (Args.src (("default", []), Position.none));
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   532
val this_text = Basic (K this);
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   533
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   534
fun finish ctxt = METHOD (K (FILTER Thm.no_prems (ALLGOALS (assm_tac ctxt) THEN flexflex_tac)));
7555
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   535
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   536
fun finish_text None = Basic finish
dd281afb33d7 setup for refined facts handling;
wenzelm
parents: 7526
diff changeset
   537
  | finish_text (Some txt) = Then [txt, Basic finish];
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   538
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   539
fun proof opt_text state =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   540
  state
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   541
  |> Proof.assert_backward
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6108
diff changeset
   542
  |> refine (if_none opt_text default_text)
8242
ac8ac0eba738 proof step: reset goal_facts;
wenzelm
parents: 8240
diff changeset
   543
  |> Seq.map (Proof.goal_facts (K []))
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   544
  |> Seq.map Proof.enter_forward;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   545
7439
a1b3310b4985 terminal method: always involve finish;
wenzelm
parents: 7419
diff changeset
   546
fun local_qed opt_text = Proof.local_qed (refine (finish_text opt_text));
6934
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
   547
fun local_terminal_proof (text, opt_text) pr = Seq.THEN (proof (Some text), local_qed opt_text pr);
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   548
val local_immediate_proof = local_terminal_proof (this_text, None);
6934
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
   549
val local_default_proof = local_terminal_proof (default_text, None);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   550
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   551
7439
a1b3310b4985 terminal method: always involve finish;
wenzelm
parents: 7419
diff changeset
   552
fun global_qeds opt_text = Proof.global_qed (refine (finish_text opt_text));
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   553
6951
13399b560e4e global_qed: removed alt_name, alt_att;
wenzelm
parents: 6934
diff changeset
   554
fun global_qed opt_text state =
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   555
  state
6951
13399b560e4e global_qed: removed alt_name, alt_att;
wenzelm
parents: 6934
diff changeset
   556
  |> global_qeds opt_text
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   557
  |> Proof.check_result "Failed to finish proof" state
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   558
  |> Seq.hd;
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   559
6934
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
   560
fun global_terminal_proof (text, opt_text) state =
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   561
  state
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   562
  |> proof (Some text)
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   563
  |> Proof.check_result "Terminal proof method failed" state
6951
13399b560e4e global_qed: removed alt_name, alt_att;
wenzelm
parents: 6934
diff changeset
   564
  |> (Seq.flat o Seq.map (global_qeds opt_text))
6872
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   565
  |> Proof.check_result "Failed to finish proof (after successful terminal method)" state
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   566
  |> Seq.hd;
b250da153b1e fixed backtracking of global_qed;
wenzelm
parents: 6849
diff changeset
   567
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   568
val global_immediate_proof = global_terminal_proof (this_text, None);
6934
04d051190a5f terminal_proof: 2nd method;
wenzelm
parents: 6872
diff changeset
   569
val global_default_proof = global_terminal_proof (default_text, None);
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   570
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   571
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   572
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   573
(** theory setup **)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   574
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   575
(* pure_methods *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   576
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   577
val pure_methods =
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   578
 [("fail", no_args fail, "force failure"),
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   579
  ("succeed", no_args succeed, "succeed"),
7574
5bcb7fc31caa added 'insert' method (again);
wenzelm
parents: 7555
diff changeset
   580
  ("-", no_args insert_facts, "do nothing, inserting current facts only"),
7664
c151ac595551 insert: ignore facts;
wenzelm
parents: 7611
diff changeset
   581
  ("insert", thms_args insert, "insert theorems, ignoring facts (improper!)"),
7601
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   582
  ("unfold", thms_args unfold, "unfold definitions"),
c568799bf21b simplified sectioned_args;
wenzelm
parents: 7574
diff changeset
   583
  ("fold", thms_args fold, "fold definitions"),
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   584
  ("default", thms_ctxt_args some_rule, "apply some rule"),
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   585
  ("rule", thms_ctxt_args some_rule, "apply some rule"),
8220
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   586
  ("erule", thms_ctxt_args some_erule, "apply some rule in elimination manner (improper!)"),
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   587
  ("drule", thms_ctxt_args some_drule, "apply some rule in destruct manner (improper!)"),
e04928747b18 [df]rule methods;
wenzelm
parents: 8205
diff changeset
   588
  ("frule", thms_ctxt_args some_frule, "apply some rule in forward manner (improper!)"),
8195
af2575a5c5ae '.' == by this;
wenzelm
parents: 8167
diff changeset
   589
  ("this", no_args this, "apply current facts as rules"),
8238
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   590
  ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   591
  ("res_inst_tac", inst_args res_inst, "res_inst_tac emulation (beware!)"),
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   592
  ("eres_inst_tac", inst_args eres_inst, "eres_inst_tac emulation (beware!)"),
78fd6355ebb5 added refine_end;
wenzelm
parents: 8220
diff changeset
   593
  ("dres_inst_tac", inst_args dres_inst, "dres_inst_tac emulation (beware!)"),
8329
8308b7a152a3 added 'prolog' method;
wenzelm
parents: 8282
diff changeset
   594
  ("forw_inst_tac", inst_args forw_inst, "forw_inst_tac emulation (beware!)"),
8351
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   595
  ("prolog", thms_args prolog, "simple prolog interpreter"),
1b8ac0f48233 added simple_args;
wenzelm
parents: 8335
diff changeset
   596
  ("tactic", simple_args Args.name tactic, "ML tactic as proof method")];
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   597
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   598
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   599
(* setup *)
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   600
8153
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   601
val setup =
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   602
 [GlobalRules.init, LocalRules.init, Attrib.add_attributes rule_atts,
9bdbcb71dc56 maintain standard rules (beware: classical provers provides another version!);
wenzelm
parents: 8093
diff changeset
   603
  MethodsData.init, add_methods pure_methods];
5824
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   604
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   605
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   606
end;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   607
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   608
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   609
structure BasicMethod: BASIC_METHOD = Method;
91113aa09371 Proof methods.
wenzelm
parents:
diff changeset
   610
open BasicMethod;