250 |
251 |
251 (*print thm A1,...,An/B in "goal style" -- premises as numbered subgoals*) |
252 (*print thm A1,...,An/B in "goal style" -- premises as numbered subgoals*) |
252 |
253 |
253 local |
254 local |
254 |
255 |
255 (* utils *) |
256 fun ins_entry (x, y) [] = [(x, [y])] |
256 |
257 | ins_entry (x, y) ((pair as (x', ys')) :: pairs) = |
257 fun ins_entry (x, y) [] = [(x, [y])] |
258 if x = x' then (x', y ins ys') :: pairs |
258 | ins_entry (x, y) ((pair as (x', ys')) :: pairs) = |
259 else pair :: ins_entry (x, y) pairs; |
259 if x = x' then (x', y ins ys') :: pairs |
260 |
260 else pair :: ins_entry (x, y) pairs; |
261 fun add_consts (Const (c, T), env) = ins_entry (T, (c, T)) env |
261 |
262 | add_consts (t $ u, env) = add_consts (u, add_consts (t, env)) |
262 fun add_consts (Const (c, T), env) = ins_entry (T, (c, T)) env |
263 | add_consts (Abs (_, _, t), env) = add_consts (t, env) |
263 | add_consts (t $ u, env) = add_consts (u, add_consts (t, env)) |
264 | add_consts (_, env) = env; |
264 | add_consts (Abs (_, _, t), env) = add_consts (t, env) |
265 |
265 | add_consts (_, env) = env; |
266 fun add_vars (Free (x, T), env) = ins_entry (T, (x, ~1)) env |
266 |
267 | add_vars (Var (xi, T), env) = ins_entry (T, xi) env |
267 fun add_vars (Free (x, T), env) = ins_entry (T, (x, ~1)) env |
268 | add_vars (Abs (_, _, t), env) = add_vars (t, env) |
268 | add_vars (Var (xi, T), env) = ins_entry (T, xi) env |
269 | add_vars (t $ u, env) = add_vars (u, add_vars (t, env)) |
269 | add_vars (Abs (_, _, t), env) = add_vars (t, env) |
270 | add_vars (_, env) = env; |
270 | add_vars (t $ u, env) = add_vars (u, add_vars (t, env)) |
271 |
271 | add_vars (_, env) = env; |
272 fun add_varsT (Type (_, Ts), env) = foldr add_varsT (Ts, env) |
272 |
273 | add_varsT (TFree (x, S), env) = ins_entry (S, (x, ~1)) env |
273 fun add_varsT (Type (_, Ts), env) = foldr add_varsT (Ts, env) |
274 | add_varsT (TVar (xi, S), env) = ins_entry (S, xi) env; |
274 | add_varsT (TFree (x, S), env) = ins_entry (S, (x, ~1)) env |
275 |
275 | add_varsT (TVar (xi, S), env) = ins_entry (S, xi) env; |
276 fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs; |
276 |
277 fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs; |
277 fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs; |
278 |
278 fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs; |
279 fun consts_of t = sort_cnsts (add_consts (t, [])); |
279 |
280 fun vars_of t = sort_idxs (add_vars (t, [])); |
280 |
281 fun varsT_of t = rev (sort_idxs (it_term_types add_varsT (t, []))); |
281 (* prepare atoms *) |
|
282 |
|
283 fun consts_of t = sort_cnsts (add_consts (t, [])); |
|
284 fun vars_of t = sort_idxs (add_vars (t, [])); |
|
285 fun varsT_of t = rev (sort_idxs (it_term_types add_varsT (t, []))); |
|
286 |
|
287 fun pretty_goals_marker_aux begin_goal print_msg print_goal maxgoals state = |
|
288 let |
|
289 val {sign, ...} = rep_thm state; |
|
290 |
|
291 val prt_term = Sign.pretty_term sign; |
|
292 val prt_typ = Sign.pretty_typ sign; |
|
293 val prt_sort = Sign.pretty_sort sign; |
|
294 |
|
295 fun prt_atoms prt prtT (X, xs) = Pretty.block |
|
296 [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::", |
|
297 Pretty.brk 1, prtT X]; |
|
298 |
|
299 fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
300 | prt_var xi = prt_term (Syntax.var xi); |
|
301 |
|
302 fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
303 | prt_varT xi = prt_typ (TVar (xi, [])); |
|
304 |
|
305 val prt_consts = prt_atoms (prt_term o Const) prt_typ; |
|
306 val prt_vars = prt_atoms prt_var prt_typ; |
|
307 val prt_varsT = prt_atoms prt_varT prt_sort; |
|
308 |
|
309 |
|
310 fun pretty_list _ _ [] = [] |
|
311 | pretty_list name prt lst = [Pretty.big_list name (map prt lst)]; |
|
312 |
|
313 fun pretty_subgoal (n, A) = |
|
314 Pretty.blk (0, [Pretty.str (begin_goal ^ " " ^ string_of_int n ^ ". "), prt_term A]); |
|
315 fun pretty_subgoals As = map pretty_subgoal (1 upto length As ~~ As); |
|
316 |
|
317 val pretty_ffpairs = pretty_list "flex-flex pairs:" (prt_term o Logic.mk_flexpair); |
|
318 |
|
319 val pretty_consts = pretty_list "constants:" prt_consts o consts_of; |
|
320 val pretty_vars = pretty_list "variables:" prt_vars o vars_of; |
|
321 val pretty_varsT = pretty_list "type variables:" prt_varsT o varsT_of; |
|
322 |
|
323 |
|
324 val {prop, ...} = rep_thm state; |
|
325 val (tpairs, As, B) = Logic.strip_horn prop; |
|
326 val ngoals = length As; |
|
327 |
|
328 fun pretty_gs (types, sorts) = |
|
329 (if print_goal then [prt_term B] else []) @ |
|
330 (if ngoals = 0 then [Pretty.str "No subgoals!"] |
|
331 else if ngoals > maxgoals then |
|
332 pretty_subgoals (take (maxgoals, As)) @ |
|
333 (if print_msg then |
|
334 [Pretty.str ("A total of " ^ string_of_int ngoals ^ " subgoals...")] |
|
335 else []) |
|
336 else pretty_subgoals As) @ |
|
337 pretty_ffpairs tpairs @ |
|
338 (if ! show_consts then pretty_consts prop else []) @ |
|
339 (if types then pretty_vars prop else []) @ |
|
340 (if sorts then pretty_varsT prop else []); |
|
341 in |
|
342 setmp show_no_free_types true |
|
343 (setmp show_types (! show_types orelse ! show_sorts) |
|
344 (setmp show_sorts false pretty_gs)) |
|
345 (! show_types orelse ! show_sorts, ! show_sorts) |
|
346 end; |
|
347 |
282 |
348 in |
283 in |
349 fun pretty_goals_marker bg = pretty_goals_marker_aux bg true true; |
284 |
350 val print_goals_marker = (Pretty.writeln o Pretty.chunks) ooo pretty_goals_marker; |
285 fun pretty_goals_aux (prt_sort, prt_typ, prt_term) begin_goal (msg, main) maxgoals state = |
351 val pretty_sub_goals = pretty_goals_marker_aux "" false; |
286 let |
352 val pretty_goals = pretty_goals_marker ""; |
287 fun prt_atoms prt prtT (X, xs) = Pretty.block |
353 val print_goals = print_goals_marker ""; |
288 [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::", |
|
289 Pretty.brk 1, prtT X]; |
|
290 |
|
291 fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
292 | prt_var xi = prt_term (Syntax.var xi); |
|
293 |
|
294 fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
295 | prt_varT xi = prt_typ (TVar (xi, [])); |
|
296 |
|
297 val prt_consts = prt_atoms (prt_term o Const) prt_typ; |
|
298 val prt_vars = prt_atoms prt_var prt_typ; |
|
299 val prt_varsT = prt_atoms prt_varT prt_sort; |
|
300 |
|
301 |
|
302 fun pretty_list _ _ [] = [] |
|
303 | pretty_list name prt lst = [Pretty.big_list name (map prt lst)]; |
|
304 |
|
305 fun pretty_subgoal (n, A) = |
|
306 Pretty.blk (0, [Pretty.str (begin_goal ^ " " ^ string_of_int n ^ ". "), prt_term A]); |
|
307 fun pretty_subgoals As = map pretty_subgoal (1 upto length As ~~ As); |
|
308 |
|
309 val pretty_ffpairs = pretty_list "flex-flex pairs:" (prt_term o Logic.mk_flexpair); |
|
310 |
|
311 val pretty_consts = pretty_list "constants:" prt_consts o consts_of; |
|
312 val pretty_vars = pretty_list "variables:" prt_vars o vars_of; |
|
313 val pretty_varsT = pretty_list "type variables:" prt_varsT o varsT_of; |
|
314 |
|
315 |
|
316 val {prop, ...} = rep_thm state; |
|
317 val (tpairs, As, B) = Logic.strip_horn prop; |
|
318 val ngoals = length As; |
|
319 |
|
320 fun pretty_gs (types, sorts) = |
|
321 (if main then [prt_term B] else []) @ |
|
322 (if ngoals = 0 then [Pretty.str "No subgoals!"] |
|
323 else if ngoals > maxgoals then |
|
324 pretty_subgoals (take (maxgoals, As)) @ |
|
325 (if msg then [Pretty.str ("A total of " ^ string_of_int ngoals ^ " subgoals...")] |
|
326 else []) |
|
327 else pretty_subgoals As) @ |
|
328 pretty_ffpairs tpairs @ |
|
329 (if ! show_consts then pretty_consts prop else []) @ |
|
330 (if types then pretty_vars prop else []) @ |
|
331 (if sorts then pretty_varsT prop else []); |
|
332 in |
|
333 setmp show_no_free_types true |
|
334 (setmp show_types (! show_types orelse ! show_sorts) |
|
335 (setmp show_sorts false pretty_gs)) |
|
336 (! show_types orelse ! show_sorts, ! show_sorts) |
|
337 end; |
|
338 |
|
339 fun pretty_goals_marker bg n th = |
|
340 let val sg = Thm.sign_of_thm th in |
|
341 pretty_goals_aux (Sign.pretty_sort sg, Sign.pretty_typ sg, Sign.pretty_term sg) |
|
342 bg (true, true) n th |
|
343 end; |
|
344 |
|
345 val pretty_goals = pretty_goals_marker ""; |
|
346 val print_goals_marker = (Pretty.writeln o Pretty.chunks) ooo pretty_goals_marker; |
|
347 val print_goals = print_goals_marker ""; |
|
348 |
354 end; |
349 end; |
355 |
350 |
356 |
351 |
357 (* print_current_goals *) |
352 (* print_current_goals *) |
358 |
353 |