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