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