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