author | wenzelm |
Wed, 09 Aug 2006 00:12:38 +0200 | |
changeset 20366 | 867696dc64fc |
parent 20311 | 3666316adad6 |
child 20621 | 29d57880ba00 |
permissions | -rw-r--r-- |
17369 | 1 |
(* Title: Pure/Isar/proof_display.ML |
2 |
ID: $Id$ |
|
3 |
Author: Makarius |
|
4 |
||
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
5 |
Printing of theorems, goals, results etc. |
17369 | 6 |
*) |
7 |
||
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
8 |
signature BASIC_PROOF_DISPLAY = |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
9 |
sig |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
10 |
val print_theorems: theory -> unit |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
11 |
val print_theory: theory -> unit |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
12 |
end |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
13 |
|
17369 | 14 |
signature PROOF_DISPLAY = |
15 |
sig |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
16 |
include BASIC_PROOF_DISPLAY |
20311 | 17 |
val pprint_context: Proof.context -> pprint_args -> unit |
20211 | 18 |
val pprint_typ: theory -> typ -> pprint_args -> unit |
19 |
val pprint_term: theory -> term -> pprint_args -> unit |
|
20 |
val pprint_ctyp: ctyp -> pprint_args -> unit |
|
21 |
val pprint_cterm: cterm -> pprint_args -> unit |
|
22 |
val pprint_thm: thm -> pprint_args -> unit |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
23 |
val print_theorems_diff: theory -> theory -> unit |
20311 | 24 |
val string_of_rule: Proof.context -> string -> thm -> string |
25 |
val print_results: bool -> Proof.context -> |
|
17369 | 26 |
((string * string) * (string * thm list) list) -> unit |
20311 | 27 |
val present_results: Proof.context -> |
17369 | 28 |
((string * string) * (string * thm list) list) -> unit |
29 |
end |
|
30 |
||
31 |
structure ProofDisplay: PROOF_DISPLAY = |
|
32 |
struct |
|
33 |
||
20235 | 34 |
(* toplevel pretty printing *) |
20211 | 35 |
|
36 |
fun pprint_context ctxt = Pretty.pprint |
|
20311 | 37 |
(if ! ProofContext.debug then |
20211 | 38 |
Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt)) |
39 |
else Pretty.str "<context>"); |
|
40 |
||
41 |
fun pprint pretty thy = Pretty.pprint o Pretty.quote o pretty (ProofContext.init thy); |
|
42 |
||
43 |
val pprint_typ = pprint ProofContext.pretty_typ; |
|
44 |
val pprint_term = pprint ProofContext.pretty_term; |
|
45 |
fun pprint_ctyp cT = pprint_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT); |
|
46 |
fun pprint_cterm ct = pprint_term (Thm.theory_of_cterm ct) (Thm.term_of ct); |
|
20253 | 47 |
val pprint_thm = Pretty.pprint o ProofContext.pretty_thm_legacy true; |
20211 | 48 |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
49 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
50 |
(* theorems and theory *) |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
51 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
52 |
fun pretty_theorems_diff prev_thms thy = |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
53 |
let |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
54 |
val ctxt = ProofContext.init thy; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
55 |
val (space, thms) = PureThy.theorems_of thy; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
56 |
val diff_thmss = Symtab.fold (fn fact => |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
57 |
if not (Symtab.member Thm.eq_thms prev_thms fact) then cons fact else I) thms []; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
58 |
val thmss = diff_thmss |> map (apfst (NameSpace.extern space)) |> Library.sort_wrt #1; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
59 |
in Pretty.big_list "theorems:" (map (ProofContext.pretty_fact ctxt) thmss) end; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
60 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
61 |
fun print_theorems_diff prev_thy thy = |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
62 |
Pretty.writeln (pretty_theorems_diff (#2 (PureThy.theorems_of prev_thy)) thy); |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
63 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
64 |
fun pretty_theorems thy = pretty_theorems_diff Symtab.empty thy; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
65 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
66 |
val print_theorems = Pretty.writeln o pretty_theorems; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
67 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
68 |
fun print_theory thy = |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
69 |
Pretty.writeln (Pretty.chunks (Display.pretty_full_theory thy @ [pretty_theorems thy])); |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
70 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
71 |
|
17369 | 72 |
(* refinement rule *) |
73 |
||
74 |
fun pretty_rule ctxt s thm = |
|
75 |
Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"), |
|
76 |
Pretty.fbrk, ProofContext.pretty_thm ctxt thm]; |
|
77 |
||
78 |
val string_of_rule = Pretty.string_of ooo pretty_rule; |
|
79 |
||
80 |
||
81 |
(* results *) |
|
82 |
||
83 |
local |
|
84 |
||
85 |
fun pretty_facts ctxt = |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19432
diff
changeset
|
86 |
flat o (separate [Pretty.fbrk, Pretty.str "and "]) o |
17369 | 87 |
map (single o ProofContext.pretty_fact ctxt); |
88 |
||
89 |
fun pretty_results ctxt ((kind, ""), facts) = |
|
90 |
Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts) |
|
91 |
| pretty_results ctxt ((kind, name), [fact]) = Pretty.blk (1, |
|
92 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, ProofContext.pretty_fact ctxt fact]) |
|
93 |
| pretty_results ctxt ((kind, name), facts) = Pretty.blk (1, |
|
94 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, |
|
95 |
Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]); |
|
96 |
||
97 |
fun name_results "" res = res |
|
98 |
| name_results name res = |
|
99 |
let |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19432
diff
changeset
|
100 |
val n = length (maps snd res); |
17369 | 101 |
fun name_res (a, ths) i = |
102 |
let |
|
103 |
val m = length ths; |
|
104 |
val j = i + m; |
|
105 |
in |
|
106 |
if a <> "" then ((a, ths), j) |
|
107 |
else if m = n then ((name, ths), j) |
|
108 |
else if m = 1 then |
|
109 |
((PureThy.string_of_thmref (NameSelection (name, [Single i])), ths), j) |
|
110 |
else ((PureThy.string_of_thmref (NameSelection (name, [FromTo (i, j - 1)])), ths), j) |
|
111 |
end; |
|
17756 | 112 |
in fst (fold_map name_res res 1) end; |
17369 | 113 |
|
114 |
in |
|
115 |
||
116 |
fun print_results true = Pretty.writeln oo pretty_results |
|
117 |
| print_results false = K (K ()); |
|
118 |
||
119 |
fun present_results ctxt ((kind, name), res) = |
|
18799 | 120 |
if kind = "" orelse kind = PureThy.internalK then () |
17369 | 121 |
else (print_results true ctxt ((kind, name), res); |
122 |
Context.setmp (SOME (ProofContext.theory_of ctxt)) |
|
123 |
(Present.results kind) (name_results name res)); |
|
124 |
||
125 |
end; |
|
126 |
||
127 |
end; |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
128 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
129 |
structure BasicProofDisplay: BASIC_PROOF_DISPLAY = ProofDisplay; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
130 |
open BasicProofDisplay; |