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