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