author | wenzelm |
Wed, 27 Feb 2002 21:53:54 +0100 | |
changeset 12971 | 92195e8c6208 |
parent 12959 | bf48fd86a732 |
child 13277 | ca2511db144d |
permissions | -rw-r--r-- |
5820 | 1 |
(* Title: Pure/Isar/proof.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
8807 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
5820 | 5 |
|
6 |
Proof states and methods. |
|
7 |
*) |
|
8 |
||
8152 | 9 |
signature BASIC_PROOF = |
10 |
sig |
|
8374 | 11 |
val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
12 |
val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
|
8152 | 13 |
end; |
14 |
||
5820 | 15 |
signature PROOF = |
16 |
sig |
|
8152 | 17 |
include BASIC_PROOF |
5820 | 18 |
type context |
19 |
type state |
|
20 |
exception STATE of string * state |
|
6871 | 21 |
val check_result: string -> state -> 'a Seq.seq -> 'a Seq.seq |
12045 | 22 |
val init_state: theory -> state |
5820 | 23 |
val context_of: state -> context |
24 |
val theory_of: state -> theory |
|
25 |
val sign_of: state -> Sign.sg |
|
7924 | 26 |
val warn_extra_tfrees: state -> state -> state |
7605 | 27 |
val reset_thms: string -> state -> state |
6091 | 28 |
val the_facts: state -> thm list |
9469 | 29 |
val the_fact: state -> thm |
11079
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
30 |
val get_goal: state -> context * (thm list * thm) |
6091 | 31 |
val goal_facts: (state -> thm list) -> state -> state |
5820 | 32 |
val use_facts: state -> state |
33 |
val reset_facts: state -> state |
|
9469 | 34 |
val is_chain: state -> bool |
6891 | 35 |
val assert_forward: state -> state |
9469 | 36 |
val assert_forward_or_chain: state -> state |
5820 | 37 |
val assert_backward: state -> state |
8206 | 38 |
val assert_no_chain: state -> state |
5820 | 39 |
val enter_forward: state -> state |
6529 | 40 |
val verbose: bool ref |
12423 | 41 |
val pretty_state: int -> state -> Pretty.T list |
10360 | 42 |
val pretty_goals: bool -> state -> Pretty.T list |
6776 | 43 |
val level: state -> int |
5820 | 44 |
type method |
6848 | 45 |
val method: (thm list -> tactic) -> method |
8374 | 46 |
val method_cases: (thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq) -> method |
5820 | 47 |
val refine: (context -> method) -> state -> state Seq.seq |
8234 | 48 |
val refine_end: (context -> method) -> state -> state Seq.seq |
5936 | 49 |
val match_bind: (string list * string) list -> state -> state |
50 |
val match_bind_i: (term list * term) list -> state -> state |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
51 |
val let_bind: (string list * string) list -> state -> state |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
52 |
val let_bind_i: (term list * term) list -> state -> state |
6876 | 53 |
val simple_have_thms: string -> thm list -> state -> state |
12714 | 54 |
val have_thmss: ((bstring * context attribute list) * |
55 |
(xstring * context attribute list) list) list -> state -> state |
|
56 |
val have_thmss_i: ((bstring * context attribute list) * |
|
9196 | 57 |
(thm list * context attribute list) list) list -> state -> state |
12714 | 58 |
val with_thmss: ((bstring * context attribute list) * |
59 |
(xstring * context attribute list) list) list -> state -> state |
|
60 |
val with_thmss_i: ((bstring * context attribute list) * |
|
9196 | 61 |
(thm list * context attribute list) list) list -> state -> state |
12930 | 62 |
val using_thmss: ((xstring * context attribute list) list) list -> state -> state |
63 |
val using_thmss_i: ((thm list * context attribute list) list) list -> state -> state |
|
7412 | 64 |
val fix: (string list * string option) list -> state -> state |
7665 | 65 |
val fix_i: (string list * typ option) list -> state -> state |
9469 | 66 |
val assm: ProofContext.exporter |
10464 | 67 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
7271 | 68 |
-> state -> state |
9469 | 69 |
val assm_i: ProofContext.exporter |
10464 | 70 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 71 |
-> state -> state |
10464 | 72 |
val assume: |
73 |
((string * context attribute list) * (string * (string list * string list)) list) list |
|
7271 | 74 |
-> state -> state |
10464 | 75 |
val assume_i: ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 76 |
-> state -> state |
10464 | 77 |
val presume: |
78 |
((string * context attribute list) * (string * (string list * string list)) list) list |
|
6932 | 79 |
-> state -> state |
10464 | 80 |
val presume_i: ((string * context attribute list) * (term * (term list * term list)) list) list |
6932 | 81 |
-> state -> state |
11891 | 82 |
val def: string -> context attribute list -> string * (string * string list) -> state -> state |
83 |
val def_i: string -> context attribute list -> string * (term * term list) -> state -> state |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
84 |
val invoke_case: string * string option list * context attribute list -> state -> state |
12959 | 85 |
val multi_theorem: string |
86 |
-> (xstring * (context attribute list * context attribute list list)) option |
|
87 |
-> bstring * theory attribute list -> context attribute Locale.element list |
|
12146 | 88 |
-> ((bstring * theory attribute list) * (string * (string list * string list)) list) list |
89 |
-> theory -> state |
|
12959 | 90 |
val multi_theorem_i: string |
91 |
-> (string * (context attribute list * context attribute list list)) option |
|
92 |
-> bstring * theory attribute list |
|
93 |
-> context attribute Locale.element_i list |
|
12146 | 94 |
-> ((bstring * theory attribute list) * (term * (term list * term list)) list) list |
95 |
-> theory -> state |
|
5820 | 96 |
val chain: state -> state |
6091 | 97 |
val from_facts: thm list -> state -> state |
12971 | 98 |
val show: (bool -> state -> state) -> (state -> state Seq.seq) -> bool |
12146 | 99 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
100 |
-> bool -> state -> state |
|
12971 | 101 |
val show_i: (bool -> state -> state) -> (state -> state Seq.seq) -> bool |
12146 | 102 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
103 |
-> bool -> state -> state |
|
12971 | 104 |
val have: (state -> state Seq.seq) -> bool |
12146 | 105 |
-> ((string * context attribute list) * (string * (string list * string list)) list) list |
106 |
-> state -> state |
|
12971 | 107 |
val have_i: (state -> state Seq.seq) -> bool |
12146 | 108 |
-> ((string * context attribute list) * (term * (term list * term list)) list) list |
109 |
-> state -> state |
|
6404 | 110 |
val at_bottom: state -> bool |
6982 | 111 |
val local_qed: (state -> state Seq.seq) |
12146 | 112 |
-> (context -> string * (string * thm list) list -> unit) * (context -> thm -> unit) |
113 |
-> state -> state Seq.seq |
|
6950 | 114 |
val global_qed: (state -> state Seq.seq) -> state |
12244 | 115 |
-> (theory * ((string * string) * (string * thm list) list)) Seq.seq |
6896 | 116 |
val begin_block: state -> state |
6932 | 117 |
val end_block: state -> state Seq.seq |
6896 | 118 |
val next_block: state -> state |
5820 | 119 |
end; |
120 |
||
8152 | 121 |
signature PRIVATE_PROOF = |
5820 | 122 |
sig |
123 |
include PROOF |
|
124 |
val put_data: Object.kind -> ('a -> Object.T) -> 'a -> state -> state |
|
125 |
end; |
|
126 |
||
8152 | 127 |
structure Proof: PRIVATE_PROOF = |
5820 | 128 |
struct |
129 |
||
130 |
||
131 |
(** proof state **) |
|
132 |
||
133 |
type context = ProofContext.context; |
|
134 |
||
135 |
||
136 |
(* type goal *) |
|
137 |
||
138 |
datatype kind = |
|
12959 | 139 |
Theorem of {kind: string, |
140 |
theory_spec: (bstring * theory attribute list) * theory attribute list list, |
|
141 |
locale_spec: (string * (context attribute list * context attribute list list)) option} | |
|
142 |
Show of context attribute list list | |
|
143 |
Have of context attribute list list; |
|
5820 | 144 |
|
12959 | 145 |
fun kind_name _ (Theorem {kind = s, theory_spec = ((a, _), _), locale_spec = None}) = |
146 |
s ^ (if a = "" then "" else " " ^ a) |
|
147 |
| kind_name sg (Theorem {kind = s, theory_spec = ((a, _), _), locale_spec = Some (name, _)}) = |
|
148 |
s ^ " (in " ^ Locale.cond_extern sg name ^ ")" ^ (if a = "" then "" else " " ^ a) |
|
12015 | 149 |
| kind_name _ (Show _) = "show" |
150 |
| kind_name _ (Have _) = "have"; |
|
5820 | 151 |
|
152 |
type goal = |
|
12146 | 153 |
(kind * (*result kind*) |
154 |
string list * (*result names*) |
|
155 |
term list list) * (*result statements*) |
|
156 |
(thm list * (*use facts*) |
|
157 |
thm); (*goal: subgoals ==> statement*) |
|
5820 | 158 |
|
159 |
||
160 |
(* type mode *) |
|
161 |
||
162 |
datatype mode = Forward | ForwardChain | Backward; |
|
7201 | 163 |
val mode_name = (fn Forward => "state" | ForwardChain => "chain" | Backward => "prove"); |
5820 | 164 |
|
165 |
||
166 |
(* datatype state *) |
|
167 |
||
7176 | 168 |
datatype node = |
169 |
Node of |
|
170 |
{context: context, |
|
171 |
facts: thm list option, |
|
172 |
mode: mode, |
|
12971 | 173 |
goal: (goal * ((state -> state Seq.seq) * bool)) option} |
7176 | 174 |
and state = |
5820 | 175 |
State of |
176 |
node * (*current*) |
|
177 |
node list; (*parents wrt. block structure*) |
|
178 |
||
7176 | 179 |
fun make_node (context, facts, mode, goal) = |
180 |
Node {context = context, facts = facts, mode = mode, goal = goal}; |
|
181 |
||
182 |
||
5820 | 183 |
exception STATE of string * state; |
184 |
||
185 |
fun err_malformed name state = |
|
186 |
raise STATE (name ^ ": internal error -- malformed proof state", state); |
|
187 |
||
6871 | 188 |
fun check_result msg state sq = |
189 |
(case Seq.pull sq of |
|
190 |
None => raise STATE (msg, state) |
|
191 |
| Some s_sq => Seq.cons s_sq); |
|
192 |
||
5820 | 193 |
|
7176 | 194 |
fun map_current f (State (Node {context, facts, mode, goal}, nodes)) = |
5820 | 195 |
State (make_node (f (context, facts, mode, goal)), nodes); |
196 |
||
12045 | 197 |
fun init_state thy = |
198 |
State (make_node (ProofContext.init thy, None, Forward, None), []); |
|
199 |
||
5820 | 200 |
|
201 |
||
202 |
(** basic proof state operations **) |
|
203 |
||
204 |
(* context *) |
|
205 |
||
7176 | 206 |
fun context_of (State (Node {context, ...}, _)) = context; |
5820 | 207 |
val theory_of = ProofContext.theory_of o context_of; |
208 |
val sign_of = ProofContext.sign_of o context_of; |
|
209 |
||
210 |
fun map_context f = map_current (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal)); |
|
211 |
||
7176 | 212 |
fun map_context_result f (state as State (Node {context, facts, mode, goal}, nodes)) = |
5820 | 213 |
let val (context', result) = f context |
214 |
in (State (make_node (context', facts, mode, goal), nodes), result) end; |
|
215 |
||
216 |
||
217 |
fun put_data kind f = map_context o ProofContext.put_data kind f; |
|
7924 | 218 |
val warn_extra_tfrees = map_context o ProofContext.warn_extra_tfrees o context_of; |
10809 | 219 |
val add_binds_i = map_context o ProofContext.add_binds_i; |
6790 | 220 |
val auto_bind_goal = map_context o ProofContext.auto_bind_goal; |
12146 | 221 |
val auto_bind_facts = map_context o ProofContext.auto_bind_facts; |
6091 | 222 |
val put_thms = map_context o ProofContext.put_thms; |
223 |
val put_thmss = map_context o ProofContext.put_thmss; |
|
7605 | 224 |
val reset_thms = map_context o ProofContext.reset_thms; |
8374 | 225 |
val get_case = ProofContext.get_case o context_of; |
5820 | 226 |
|
227 |
||
228 |
(* facts *) |
|
229 |
||
7176 | 230 |
fun the_facts (State (Node {facts = Some facts, ...}, _)) = facts |
5820 | 231 |
| the_facts state = raise STATE ("No current facts available", state); |
232 |
||
9469 | 233 |
fun the_fact state = |
234 |
(case the_facts state of |
|
235 |
[thm] => thm |
|
236 |
| _ => raise STATE ("Single fact expected", state)); |
|
237 |
||
6848 | 238 |
fun assert_facts state = (the_facts state; state); |
7176 | 239 |
fun get_facts (State (Node {facts, ...}, _)) = facts; |
6848 | 240 |
|
7605 | 241 |
|
242 |
val thisN = "this"; |
|
243 |
||
5820 | 244 |
fun put_facts facts state = |
245 |
state |
|
246 |
|> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal)) |
|
7605 | 247 |
|> (case facts of None => reset_thms thisN | Some ths => put_thms (thisN, ths)); |
5820 | 248 |
|
249 |
val reset_facts = put_facts None; |
|
250 |
||
9196 | 251 |
fun these_factss (state, named_factss) = |
5820 | 252 |
state |
9196 | 253 |
|> put_thmss named_factss |
254 |
|> put_facts (Some (flat (map #2 named_factss))); |
|
5820 | 255 |
|
256 |
||
257 |
(* goal *) |
|
258 |
||
10553 | 259 |
local |
260 |
fun find i (state as State (Node {goal = Some goal, ...}, _)) = (context_of state, (i, goal)) |
|
261 |
| find i (State (Node {goal = None, ...}, node :: nodes)) = find (i + 1) (State (node, nodes)) |
|
262 |
| find _ (state as State (_, [])) = err_malformed "find_goal" state; |
|
263 |
in val find_goal = find 0 end; |
|
7176 | 264 |
|
11079
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
265 |
fun get_goal state = |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
266 |
let val (ctxt, (_, ((_, x), _))) = find_goal state |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
267 |
in (ctxt, x) end; |
a378479996f7
val get_goal: state -> context * (thm list * thm);
wenzelm
parents:
10938
diff
changeset
|
268 |
|
5820 | 269 |
fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal)); |
270 |
||
8374 | 271 |
fun map_goal f g (State (Node {context, facts, mode, goal = Some goal}, nodes)) = |
272 |
State (make_node (f context, facts, mode, Some (g goal)), nodes) |
|
273 |
| map_goal f g (State (nd, node :: nodes)) = |
|
274 |
let val State (node', nodes') = map_goal f g (State (node, nodes)) |
|
275 |
in map_context f (State (nd, node' :: nodes')) end |
|
276 |
| map_goal _ _ state = state; |
|
5820 | 277 |
|
278 |
fun goal_facts get state = |
|
279 |
state |
|
8374 | 280 |
|> map_goal I (fn ((result, (_, thm)), f) => ((result, (get state, thm)), f)); |
5820 | 281 |
|
282 |
fun use_facts state = |
|
283 |
state |
|
284 |
|> goal_facts the_facts |
|
285 |
|> reset_facts; |
|
286 |
||
287 |
||
288 |
(* mode *) |
|
289 |
||
7176 | 290 |
fun get_mode (State (Node {mode, ...}, _)) = mode; |
5820 | 291 |
fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal)); |
292 |
||
293 |
val enter_forward = put_mode Forward; |
|
294 |
val enter_forward_chain = put_mode ForwardChain; |
|
295 |
val enter_backward = put_mode Backward; |
|
296 |
||
297 |
fun assert_mode pred state = |
|
298 |
let val mode = get_mode state in |
|
299 |
if pred mode then state |
|
12010 | 300 |
else raise STATE ("Illegal application of proof command in " |
301 |
^ quote (mode_name mode) ^ " mode", state) |
|
5820 | 302 |
end; |
303 |
||
304 |
fun is_chain state = get_mode state = ForwardChain; |
|
305 |
val assert_forward = assert_mode (equal Forward); |
|
306 |
val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain); |
|
307 |
val assert_backward = assert_mode (equal Backward); |
|
8206 | 308 |
val assert_no_chain = assert_mode (not_equal ForwardChain); |
5820 | 309 |
|
310 |
||
311 |
(* blocks *) |
|
312 |
||
6776 | 313 |
fun level (State (_, nodes)) = length nodes; |
314 |
||
5820 | 315 |
fun open_block (State (node, nodes)) = State (node, node :: nodes); |
316 |
||
317 |
fun new_block state = |
|
318 |
state |
|
319 |
|> open_block |
|
320 |
|> put_goal None; |
|
321 |
||
7487
c0f9b956a3e7
close_block: removed ProofContext.transfer_used_names;
wenzelm
parents:
7478
diff
changeset
|
322 |
fun close_block (state as State (_, node :: nodes)) = State (node, nodes) |
5820 | 323 |
| close_block state = raise STATE ("Unbalanced block parentheses", state); |
324 |
||
325 |
||
326 |
||
12423 | 327 |
(** pretty_state **) |
5820 | 328 |
|
6529 | 329 |
val verbose = ProofContext.verbose; |
330 |
||
12085 | 331 |
fun pretty_goals_local ctxt = Display.pretty_goals_aux |
332 |
(ProofContext.pretty_sort ctxt, ProofContext.pretty_typ ctxt, ProofContext.pretty_term ctxt); |
|
333 |
||
12055 | 334 |
fun pretty_facts _ _ None = [] |
335 |
| pretty_facts s ctxt (Some ths) = |
|
336 |
[Pretty.big_list (s ^ "this:") (map (ProofContext.pretty_thm ctxt) ths), Pretty.str ""]; |
|
6756 | 337 |
|
12423 | 338 |
fun pretty_state nr (state as State (Node {context = ctxt, facts, mode, goal = _}, nodes)) = |
5820 | 339 |
let |
11891 | 340 |
val ref (_, _, begin_goal) = Display.current_goals_markers; |
5820 | 341 |
|
342 |
fun levels_up 0 = "" |
|
7575 | 343 |
| levels_up 1 = ", 1 level up" |
344 |
| levels_up i = ", " ^ string_of_int i ^ " levels up"; |
|
5820 | 345 |
|
11556 | 346 |
fun subgoals 0 = "" |
347 |
| subgoals 1 = ", 1 subgoal" |
|
348 |
| subgoals n = ", " ^ string_of_int n ^ " subgoals"; |
|
12146 | 349 |
|
350 |
fun prt_names names = |
|
12242
282a92bc5655
multi_theorem: common statement header (covers *all* results);
wenzelm
parents:
12223
diff
changeset
|
351 |
(case filter_out (equal "") names of [] => "" |
12308 | 352 |
| nms => " " ^ enclose "(" ")" (space_implode " and " (take (7, nms) @ |
353 |
(if length nms > 7 then ["..."] else [])))); |
|
12146 | 354 |
|
355 |
fun prt_goal (_, (i, (((kind, names, _), (goal_facts, thm)), _))) = |
|
12085 | 356 |
pretty_facts "using " ctxt |
8462 | 357 |
(if mode <> Backward orelse null goal_facts then None else Some goal_facts) @ |
12146 | 358 |
[Pretty.str ("goal (" ^ kind_name (sign_of state) kind ^ prt_names names ^ |
359 |
levels_up (i div 2) ^ subgoals (Thm.nprems_of thm) ^ "):")] @ |
|
12085 | 360 |
pretty_goals_local ctxt begin_goal (true, true) (! Display.goals_limit) thm; |
6848 | 361 |
|
8462 | 362 |
val ctxt_prts = |
12085 | 363 |
if ! verbose orelse mode = Forward then ProofContext.pretty_context ctxt |
364 |
else if mode = Backward then ProofContext.pretty_asms ctxt |
|
7575 | 365 |
else []; |
8462 | 366 |
|
367 |
val prts = |
|
8582 | 368 |
[Pretty.str ("proof (" ^ mode_name mode ^ "): step " ^ string_of_int nr ^ |
12010 | 369 |
(if ! verbose then ", depth " ^ string_of_int (length nodes div 2 - 1) |
8561 | 370 |
else "")), Pretty.str ""] @ |
8462 | 371 |
(if null ctxt_prts then [] else ctxt_prts @ [Pretty.str ""]) @ |
372 |
(if ! verbose orelse mode = Forward then |
|
12146 | 373 |
(pretty_facts "" ctxt facts @ prt_goal (find_goal state)) |
12085 | 374 |
else if mode = ForwardChain then pretty_facts "picking " ctxt facts |
12146 | 375 |
else prt_goal (find_goal state)) |
12423 | 376 |
in prts end; |
5820 | 377 |
|
12085 | 378 |
fun pretty_goals main state = |
379 |
let val (ctxt, (_, ((_, (_, thm)), _))) = find_goal state |
|
380 |
in pretty_goals_local ctxt "" (false, main) (! Display.goals_limit) thm end; |
|
10320 | 381 |
|
5820 | 382 |
|
383 |
||
384 |
(** proof steps **) |
|
385 |
||
386 |
(* datatype method *) |
|
387 |
||
8374 | 388 |
datatype method = |
389 |
Method of thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq; |
|
390 |
||
391 |
fun method tac = Method (fn facts => fn st => Seq.map (rpair []) (tac facts st)); |
|
392 |
val method_cases = Method; |
|
5820 | 393 |
|
394 |
||
395 |
(* refine goal *) |
|
396 |
||
8234 | 397 |
local |
398 |
||
5820 | 399 |
fun check_sign sg state = |
400 |
if Sign.subsig (sg, sign_of state) then state |
|
401 |
else raise STATE ("Bad signature of result: " ^ Sign.str_of_sg sg, state); |
|
402 |
||
8234 | 403 |
fun gen_refine current_context meth_fun state = |
6848 | 404 |
let |
12971 | 405 |
val (goal_ctxt, (_, ((result, (facts, thm)), x))) = find_goal state; |
8234 | 406 |
val Method meth = meth_fun (if current_context then context_of state else goal_ctxt); |
5820 | 407 |
|
8374 | 408 |
fun refn (thm', cases) = |
6848 | 409 |
state |
410 |
|> check_sign (Thm.sign_of_thm thm') |
|
12971 | 411 |
|> map_goal (ProofContext.add_cases cases) (K ((result, (facts, thm')), x)); |
6848 | 412 |
in Seq.map refn (meth facts thm) end; |
5820 | 413 |
|
8234 | 414 |
in |
415 |
||
416 |
val refine = gen_refine true; |
|
417 |
val refine_end = gen_refine false; |
|
418 |
||
419 |
end; |
|
420 |
||
5820 | 421 |
|
11917 | 422 |
(* goal addressing *) |
6932 | 423 |
|
8152 | 424 |
fun FINDGOAL tac st = |
8374 | 425 |
let fun find (i, n) = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1, n)) |
426 |
in find (1, Thm.nprems_of st) st end; |
|
8152 | 427 |
|
8166 | 428 |
fun HEADGOAL tac = tac 1; |
429 |
||
9469 | 430 |
|
431 |
(* export results *) |
|
432 |
||
11816 | 433 |
fun refine_tac rule = |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
434 |
Tactic.norm_hhf_tac THEN' Tactic.rtac rule THEN_ALL_NEW (SUBGOAL (fn (goal, i) => |
11816 | 435 |
if can Logic.dest_goal (Logic.strip_assums_concl goal) then |
436 |
Tactic.etac Drule.triv_goal i |
|
437 |
else all_tac)); |
|
438 |
||
12146 | 439 |
fun export_goal inner print_rule raw_rule state = |
6932 | 440 |
let |
12971 | 441 |
val (outer, (_, ((result, (facts, thm)), x))) = find_goal state; |
12010 | 442 |
val exp_tac = ProofContext.export true inner outer; |
9469 | 443 |
fun exp_rule rule = |
444 |
let |
|
12055 | 445 |
val _ = print_rule outer rule; |
11816 | 446 |
val thmq = FINDGOAL (refine_tac rule) thm; |
12971 | 447 |
in Seq.map (fn th => map_goal I (K ((result, (facts, th)), x)) state) thmq end; |
9469 | 448 |
in raw_rule |> exp_tac |> (Seq.flat o Seq.map exp_rule) end; |
6932 | 449 |
|
12146 | 450 |
fun export_goals inner print_rule raw_rules = |
451 |
Seq.EVERY (map (export_goal inner print_rule) raw_rules); |
|
452 |
||
6932 | 453 |
fun transfer_facts inner_state state = |
454 |
(case get_facts inner_state of |
|
455 |
None => Seq.single (reset_facts state) |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
456 |
| Some thms => |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
457 |
let |
12010 | 458 |
val exp_tac = ProofContext.export false (context_of inner_state) (context_of state); |
11816 | 459 |
val thmqs = map exp_tac thms; |
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
460 |
in Seq.map (fn ths => put_facts (Some ths) state) (Seq.commute thmqs) end); |
6932 | 461 |
|
462 |
||
463 |
(* prepare result *) |
|
464 |
||
12146 | 465 |
fun prep_result state ts raw_th = |
5820 | 466 |
let |
467 |
val ctxt = context_of state; |
|
468 |
fun err msg = raise STATE (msg, state); |
|
469 |
||
12146 | 470 |
val ngoals = Thm.nprems_of raw_th; |
5820 | 471 |
val _ = |
472 |
if ngoals = 0 then () |
|
12085 | 473 |
else (err (Pretty.string_of (Pretty.chunks (pretty_goals_local ctxt "" (true, true) |
12146 | 474 |
(! Display.goals_limit) raw_th @ |
12085 | 475 |
[Pretty.str (string_of_int ngoals ^ " unsolved goal(s)!")])))); |
5820 | 476 |
|
12146 | 477 |
val {hyps, sign, ...} = Thm.rep_thm raw_th; |
5820 | 478 |
val tsig = Sign.tsig_of sign; |
12055 | 479 |
val casms = flat (map #1 (ProofContext.assumptions_of (context_of state))); |
11816 | 480 |
val bad_hyps = Library.gen_rems Term.aconv (hyps, map Thm.term_of casms); |
12146 | 481 |
|
482 |
val th = raw_th RS Drule.rev_triv_goal; |
|
483 |
val ths = Drule.conj_elim_precise (length ts) th |
|
484 |
handle THM _ => err "Main goal structure corrupted"; |
|
5820 | 485 |
in |
12146 | 486 |
conditional (not (null bad_hyps)) (fn () => err ("Additional hypotheses:\n" ^ |
487 |
cat_lines (map (ProofContext.string_of_term ctxt) bad_hyps))); |
|
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
488 |
conditional (exists (not o Pattern.matches tsig) (ts ~~ map Thm.prop_of ths)) (fn () => |
12146 | 489 |
err ("Proved a different theorem: " ^ Pretty.string_of (ProofContext.pretty_thm ctxt th))); |
490 |
ths |
|
5820 | 491 |
end; |
492 |
||
493 |
||
494 |
||
495 |
(*** structured proof commands ***) |
|
496 |
||
497 |
(** context **) |
|
498 |
||
499 |
(* bind *) |
|
500 |
||
501 |
fun gen_bind f x state = |
|
502 |
state |
|
503 |
|> assert_forward |
|
504 |
|> map_context (f x) |
|
505 |
|> reset_facts; |
|
506 |
||
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
507 |
val match_bind = gen_bind (ProofContext.match_bind false); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
508 |
val match_bind_i = gen_bind (ProofContext.match_bind_i false); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
509 |
val let_bind = gen_bind (ProofContext.match_bind true); |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
510 |
val let_bind_i = gen_bind (ProofContext.match_bind_i true); |
5820 | 511 |
|
512 |
||
12714 | 513 |
(* have_thmss *) |
5820 | 514 |
|
12714 | 515 |
local |
516 |
||
517 |
fun gen_have_thmss f args state = |
|
5820 | 518 |
state |
519 |
|> assert_forward |
|
12714 | 520 |
|> map_context_result (f args) |
9196 | 521 |
|> these_factss; |
5820 | 522 |
|
12714 | 523 |
in |
524 |
||
525 |
val have_thmss = gen_have_thmss ProofContext.have_thmss; |
|
526 |
val have_thmss_i = gen_have_thmss ProofContext.have_thmss_i; |
|
527 |
||
528 |
fun simple_have_thms name thms = have_thmss_i [((name, []), [(thms, [])])]; |
|
529 |
||
530 |
end; |
|
531 |
||
532 |
||
533 |
(* with_thmss *) |
|
9196 | 534 |
|
12714 | 535 |
local |
536 |
||
537 |
fun gen_with_thmss f args state = |
|
538 |
let val state' = state |> f args |
|
9196 | 539 |
in state' |> simple_have_thms "" (the_facts state' @ the_facts state) end; |
6876 | 540 |
|
12714 | 541 |
in |
542 |
||
543 |
val with_thmss = gen_with_thmss have_thmss; |
|
544 |
val with_thmss_i = gen_with_thmss have_thmss_i; |
|
545 |
||
546 |
end; |
|
547 |
||
5820 | 548 |
|
12930 | 549 |
(* using_thmss *) |
550 |
||
551 |
local |
|
552 |
||
553 |
fun gen_using_thmss f args state = |
|
554 |
state |
|
555 |
|> assert_backward |
|
556 |
|> map_context_result (f (map (pair ("", [])) args)) |
|
557 |
|> (fn (st, named_facts) => |
|
12971 | 558 |
let val (_, (_, ((result, (facts, thm)), x))) = find_goal st; |
559 |
in st |> map_goal I (K ((result, (facts @ flat (map snd named_facts), thm)), x)) end); |
|
12930 | 560 |
|
561 |
in |
|
562 |
||
563 |
val using_thmss = gen_using_thmss ProofContext.have_thmss; |
|
564 |
val using_thmss_i = gen_using_thmss ProofContext.have_thmss_i; |
|
565 |
||
566 |
end; |
|
567 |
||
568 |
||
5820 | 569 |
(* fix *) |
570 |
||
571 |
fun gen_fix f xs state = |
|
572 |
state |
|
573 |
|> assert_forward |
|
574 |
|> map_context (f xs) |
|
575 |
|> reset_facts; |
|
576 |
||
577 |
val fix = gen_fix ProofContext.fix; |
|
578 |
val fix_i = gen_fix ProofContext.fix_i; |
|
579 |
||
580 |
||
11891 | 581 |
(* assume and presume *) |
5820 | 582 |
|
9469 | 583 |
fun gen_assume f exp args state = |
5820 | 584 |
state |
585 |
|> assert_forward |
|
9469 | 586 |
|> map_context_result (f exp args) |
11924 | 587 |
|> these_factss; |
6932 | 588 |
|
7271 | 589 |
val assm = gen_assume ProofContext.assume; |
590 |
val assm_i = gen_assume ProofContext.assume_i; |
|
11917 | 591 |
val assume = assm ProofContext.export_assume; |
592 |
val assume_i = assm_i ProofContext.export_assume; |
|
593 |
val presume = assm ProofContext.export_presume; |
|
594 |
val presume_i = assm_i ProofContext.export_presume; |
|
5820 | 595 |
|
7271 | 596 |
|
5820 | 597 |
|
11891 | 598 |
(** local definitions **) |
599 |
||
600 |
fun gen_def fix prep_term prep_pats raw_name atts (x, (raw_rhs, raw_pats)) state = |
|
601 |
let |
|
602 |
val _ = assert_forward state; |
|
603 |
val ctxt = context_of state; |
|
604 |
||
605 |
(*rhs*) |
|
606 |
val name = if raw_name = "" then Thm.def_name x else raw_name; |
|
607 |
val rhs = prep_term ctxt raw_rhs; |
|
608 |
val T = Term.fastype_of rhs; |
|
609 |
val pats = prep_pats T (ProofContext.declare_term rhs ctxt) raw_pats; |
|
610 |
||
611 |
(*lhs*) |
|
612 |
val lhs = ProofContext.bind_skolem ctxt [x] (Free (x, T)); |
|
613 |
in |
|
614 |
state |
|
615 |
|> fix [([x], None)] |
|
616 |
|> match_bind_i [(pats, rhs)] |
|
11917 | 617 |
|> assm_i ProofContext.export_def [((name, atts), [(Logic.mk_equals (lhs, rhs), ([], []))])] |
11891 | 618 |
end; |
619 |
||
620 |
val def = gen_def fix ProofContext.read_term ProofContext.read_term_pats; |
|
621 |
val def_i = gen_def fix_i ProofContext.cert_term ProofContext.cert_term_pats; |
|
622 |
||
623 |
||
8374 | 624 |
(* invoke_case *) |
625 |
||
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
626 |
fun invoke_case (name, xs, atts) state = |
9292 | 627 |
let |
10830 | 628 |
val (state', (lets, asms)) = |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
629 |
map_context_result (ProofContext.apply_case (get_case state name xs)) state; |
9292 | 630 |
in |
10830 | 631 |
state' |
10809 | 632 |
|> add_binds_i lets |
10830 | 633 |
|> assume_i [((name, atts), map (rpair ([], [])) asms)] |
8374 | 634 |
end; |
635 |
||
636 |
||
5820 | 637 |
|
638 |
(** goals **) |
|
639 |
||
640 |
(* forward chaining *) |
|
641 |
||
642 |
fun chain state = |
|
643 |
state |
|
644 |
|> assert_forward |
|
6848 | 645 |
|> assert_facts |
5820 | 646 |
|> enter_forward_chain; |
647 |
||
648 |
fun from_facts facts state = |
|
649 |
state |
|
650 |
|> put_facts (Some facts) |
|
651 |
|> chain; |
|
652 |
||
653 |
||
654 |
(* setup goals *) |
|
655 |
||
11549 | 656 |
val rule_contextN = "rule_context"; |
8991 | 657 |
|
12971 | 658 |
fun setup_goal opt_block prepp autofix kind after_qed pr names raw_propp state = |
5820 | 659 |
let |
12146 | 660 |
val (state', (propss, gen_binds)) = |
5936 | 661 |
state |
662 |
|> assert_forward_or_chain |
|
663 |
|> enter_forward |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
664 |
|> opt_block |
12534 | 665 |
|> map_context_result (fn ctxt => prepp (ctxt, raw_propp)); |
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
666 |
val sign' = sign_of state'; |
12146 | 667 |
|
668 |
val props = flat propss; |
|
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
669 |
val cprop = Thm.cterm_of sign' (Logic.mk_conjunction_list props); |
7556 | 670 |
val goal = Drule.mk_triv_goal cprop; |
10553 | 671 |
|
12146 | 672 |
val tvars = foldr Term.add_term_tvars (props, []); |
673 |
val vars = foldr Term.add_term_vars (props, []); |
|
5820 | 674 |
in |
10553 | 675 |
if null tvars then () |
676 |
else raise STATE ("Goal statement contains illegal schematic type variable(s): " ^ |
|
677 |
commas (map (Syntax.string_of_vname o #1) tvars), state); |
|
678 |
if null vars then () |
|
679 |
else warning ("Goal statement contains unbound schematic variable(s): " ^ |
|
12055 | 680 |
commas (map (ProofContext.string_of_term (context_of state')) vars)); |
5936 | 681 |
state' |
12146 | 682 |
|> map_context (autofix props) |
12971 | 683 |
|> put_goal (Some (((kind, names, propss), ([], goal)), |
684 |
(after_qed o map_context gen_binds, pr))) |
|
12167 | 685 |
|> map_context (ProofContext.add_cases |
12808
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
686 |
(if length props = 1 then |
a529b4b91888
RuleCases.make interface based on term instead of thm;
wenzelm
parents:
12760
diff
changeset
|
687 |
RuleCases.make true (Thm.sign_of_thm goal, Thm.prop_of goal) [rule_contextN] |
12167 | 688 |
else [(rule_contextN, RuleCases.empty)])) |
12146 | 689 |
|> auto_bind_goal props |
5820 | 690 |
|> (if is_chain state then use_facts else reset_facts) |
691 |
|> new_block |
|
692 |
|> enter_backward |
|
693 |
end; |
|
694 |
||
695 |
(*global goals*) |
|
12959 | 696 |
fun global_goal prep kind raw_locale a elems concl thy = |
12503 | 697 |
let |
12549 | 698 |
val init = init_state thy; |
12534 | 699 |
val (opt_name, locale_ctxt, elems_ctxt, propp) = |
12959 | 700 |
prep (apsome fst raw_locale) elems (map snd concl) (context_of init); |
701 |
val locale_spec = (case raw_locale of None => None | Some (_, x) => Some (the opt_name, x)); |
|
12503 | 702 |
in |
12549 | 703 |
init |
704 |
|> open_block |
|
12511 | 705 |
|> map_context (K locale_ctxt) |
12065 | 706 |
|> open_block |
12511 | 707 |
|> map_context (K elems_ctxt) |
12959 | 708 |
|> setup_goal I ProofContext.bind_propp_schematic_i ProofContext.fix_frees |
709 |
(Theorem {kind = kind, theory_spec = (a, map (snd o fst) concl), locale_spec = locale_spec}) |
|
12971 | 710 |
Seq.single true (map (fst o fst) concl) propp |
12065 | 711 |
end; |
5820 | 712 |
|
12534 | 713 |
val multi_theorem = global_goal Locale.read_context_statement; |
714 |
val multi_theorem_i = global_goal Locale.cert_context_statement; |
|
12146 | 715 |
|
5820 | 716 |
|
717 |
(*local goals*) |
|
12971 | 718 |
fun local_goal' prepp kind (check: bool -> state -> state) f pr args int state = |
7928 | 719 |
state |
12146 | 720 |
|> setup_goal open_block prepp (K I) (kind (map (snd o fst) args)) |
12971 | 721 |
f pr (map (fst o fst) args) (map snd args) |
10936 | 722 |
|> warn_extra_tfrees state |
723 |
|> check int; |
|
5820 | 724 |
|
12971 | 725 |
fun local_goal prepp kind f pr args = local_goal' prepp kind (K I) f pr args false; |
10936 | 726 |
|
727 |
val show = local_goal' ProofContext.bind_propp Show; |
|
728 |
val show_i = local_goal' ProofContext.bind_propp_i Show; |
|
729 |
val have = local_goal ProofContext.bind_propp Have; |
|
10380 | 730 |
val have_i = local_goal ProofContext.bind_propp_i Have; |
5820 | 731 |
|
732 |
||
733 |
||
734 |
(** conclusions **) |
|
735 |
||
736 |
(* current goal *) |
|
737 |
||
7176 | 738 |
fun current_goal (State (Node {context, goal = Some goal, ...}, _)) = (context, goal) |
5820 | 739 |
| current_goal state = raise STATE ("No current goal!", state); |
740 |
||
7176 | 741 |
fun assert_current_goal true (state as State (Node {goal = None, ...}, _)) = |
6404 | 742 |
raise STATE ("No goal in this block!", state) |
7176 | 743 |
| assert_current_goal false (state as State (Node {goal = Some _, ...}, _)) = |
6404 | 744 |
raise STATE ("Goal present in this block!", state) |
745 |
| assert_current_goal _ state = state; |
|
5820 | 746 |
|
12010 | 747 |
fun assert_bottom b (state as State (_, nodes)) = |
748 |
let val bot = (length nodes <= 2) in |
|
749 |
if b andalso not bot then raise STATE ("Not at bottom of proof!", state) |
|
750 |
else if not b andalso bot then raise STATE ("Already at bottom of proof!", state) |
|
751 |
else state |
|
752 |
end; |
|
5820 | 753 |
|
6404 | 754 |
val at_bottom = can (assert_bottom true o close_block); |
755 |
||
6932 | 756 |
fun end_proof bot state = |
5820 | 757 |
state |
758 |
|> assert_forward |
|
759 |
|> close_block |
|
760 |
|> assert_bottom bot |
|
7011 | 761 |
|> assert_current_goal true |
762 |
|> goal_facts (K []); |
|
5820 | 763 |
|
764 |
||
6404 | 765 |
(* local_qed *) |
5820 | 766 |
|
6982 | 767 |
fun finish_local (print_result, print_rule) state = |
5820 | 768 |
let |
12971 | 769 |
val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), (after_qed, pr))) = current_goal state; |
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
770 |
val outer_state = state |> close_block; |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
771 |
val outer_ctxt = context_of outer_state; |
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
772 |
|
12146 | 773 |
val ts = flat tss; |
774 |
val results = prep_result state ts raw_thm; |
|
775 |
val resultq = |
|
776 |
results |> map (ProofContext.export false goal_ctxt outer_ctxt) |
|
777 |
|> Seq.commute |> Seq.map (Library.unflat tss); |
|
9469 | 778 |
|
12146 | 779 |
val (attss, opt_solve) = |
5820 | 780 |
(case kind of |
12971 | 781 |
Show attss => (attss, |
782 |
export_goals goal_ctxt (if pr then print_rule else (K (K ()))) results) |
|
12146 | 783 |
| Have attss => (attss, Seq.single) |
6932 | 784 |
| _ => err_malformed "finish_local" state); |
5820 | 785 |
in |
12971 | 786 |
conditional pr (fn () => print_result goal_ctxt |
787 |
(kind_name (sign_of state) kind, names ~~ Library.unflat tss results)); |
|
8617
33e2bd53aec3
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8582
diff
changeset
|
788 |
outer_state |
12549 | 789 |
|> auto_bind_facts (ProofContext.generalize goal_ctxt outer_ctxt ts) |
9469 | 790 |
|> (fn st => Seq.map (fn res => |
12714 | 791 |
have_thmss_i ((names ~~ attss) ~~ map (single o Thm.no_attributes) res) st) resultq) |
9469 | 792 |
|> (Seq.flat o Seq.map opt_solve) |
7176 | 793 |
|> (Seq.flat o Seq.map after_qed) |
5820 | 794 |
end; |
795 |
||
6982 | 796 |
fun local_qed finalize print state = |
6404 | 797 |
state |
6932 | 798 |
|> end_proof false |
6871 | 799 |
|> finalize |
6982 | 800 |
|> (Seq.flat o Seq.map (finish_local print)); |
5820 | 801 |
|
802 |
||
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
803 |
(* global_qed *) |
12065 | 804 |
|
6950 | 805 |
fun finish_global state = |
5820 | 806 |
let |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
807 |
val export = Drule.local_standard ooo ProofContext.export_single; |
12146 | 808 |
val (goal_ctxt, (((kind, names, tss), (_, raw_thm)), _)) = current_goal state; |
12065 | 809 |
val locale_ctxt = context_of (state |> close_block); |
810 |
val theory_ctxt = context_of (state |> close_block |> close_block); |
|
5820 | 811 |
|
12146 | 812 |
val ts = flat tss; |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
813 |
val locale_results = map (export goal_ctxt locale_ctxt) (prep_result state ts raw_thm); |
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
814 |
val results = map (Drule.strip_shyps_warning o export locale_ctxt theory_ctxt) locale_results; |
12959 | 815 |
val {kind = k, theory_spec = ((name, atts), attss), locale_spec} = |
12146 | 816 |
(case kind of Theorem x => x | _ => err_malformed "finish_global" state); |
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
817 |
|
12959 | 818 |
val (theory', results') = |
819 |
theory_of state |
|
820 |
|> (case locale_spec of None => I | Some (loc, (loc_atts, loc_attss)) => fn thy => |
|
821 |
if length names <> length loc_attss then |
|
822 |
raise THEORY ("Bad number of locale attributes", [thy]) |
|
823 |
else (locale_ctxt, thy) |
|
824 |
|> Locale.add_thmss loc ((names ~~ Library.unflat tss locale_results) ~~ loc_attss) |
|
825 |
|> (fn ((ctxt', thy'), res) => |
|
826 |
if name = "" andalso null loc_atts then thy' |
|
827 |
else (ctxt', thy') |
|
828 |
|> (#2 o #1 o Locale.add_thmss loc [((name, flat res), loc_atts)]))) |
|
829 |
|> Locale.smart_have_thmss k locale_spec |
|
12703
af5fec8a418f
refine_tac: Tactic.norm_hhf_tac before trying rule;
wenzelm
parents:
12698
diff
changeset
|
830 |
((names ~~ attss) ~~ map (single o Thm.no_attributes) (Library.unflat tss results)) |
12959 | 831 |
|> (fn (thy, res) => (thy, res) |
832 |
|>> (#1 o Locale.smart_have_thmss k locale_spec |
|
833 |
[((name, atts), [(flat (map #2 res), [])])])); |
|
834 |
in (theory', ((k, name), results')) end; |
|
835 |
||
5820 | 836 |
|
10553 | 837 |
(*note: clients should inspect first result only, as backtracking may destroy theory*) |
6950 | 838 |
fun global_qed finalize state = |
5820 | 839 |
state |
6932 | 840 |
|> end_proof true |
6871 | 841 |
|> finalize |
12065 | 842 |
|> Seq.map finish_global; |
5820 | 843 |
|
844 |
||
6896 | 845 |
|
846 |
(** blocks **) |
|
847 |
||
848 |
(* begin_block *) |
|
849 |
||
850 |
fun begin_block state = |
|
851 |
state |
|
852 |
|> assert_forward |
|
853 |
|> new_block |
|
854 |
|> open_block; |
|
855 |
||
856 |
||
857 |
(* end_block *) |
|
858 |
||
859 |
fun end_block state = |
|
860 |
state |
|
861 |
|> assert_forward |
|
862 |
|> close_block |
|
863 |
|> assert_current_goal false |
|
864 |
|> close_block |
|
6932 | 865 |
|> transfer_facts state; |
6896 | 866 |
|
867 |
||
868 |
(* next_block *) |
|
869 |
||
870 |
fun next_block state = |
|
871 |
state |
|
872 |
|> assert_forward |
|
873 |
|> close_block |
|
8718 | 874 |
|> new_block |
875 |
|> reset_facts; |
|
6896 | 876 |
|
877 |
||
5820 | 878 |
end; |
8152 | 879 |
|
880 |
structure BasicProof: BASIC_PROOF = Proof; |
|
881 |
open BasicProof; |