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