author | wenzelm |
Fri, 15 Aug 2008 15:50:52 +0200 | |
changeset 27885 | 76b51cd0a37c |
parent 27857 | fdf43ffceae0 |
child 28087 | a9cccdd9d521 |
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 |
22335 | 24 |
val pretty_full_theory: bool -> theory -> Pretty.T |
20311 | 25 |
val string_of_rule: Proof.context -> string -> thm -> string |
27857 | 26 |
val print_results: bool -> Proof.context -> ((string * string) * (string * thm list) list) -> unit |
27 |
val add_hook: ((string * thm list) list -> unit) -> unit |
|
28 |
val theory_results: Proof.context -> ((string * string) * (string * thm list) list) -> unit |
|
29 |
val pretty_consts: Proof.context -> (string * typ -> bool) -> (string * typ) list -> Pretty.T |
|
17369 | 30 |
end |
31 |
||
32 |
structure ProofDisplay: PROOF_DISPLAY = |
|
33 |
struct |
|
34 |
||
20235 | 35 |
(* toplevel pretty printing *) |
20211 | 36 |
|
37 |
fun pprint_context ctxt = Pretty.pprint |
|
20311 | 38 |
(if ! ProofContext.debug then |
20211 | 39 |
Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt)) |
40 |
else Pretty.str "<context>"); |
|
41 |
||
26949
a9a1ebfb4d23
pprint: proper global context via Syntax.init_pretty_global;
wenzelm
parents:
26696
diff
changeset
|
42 |
fun pprint pretty thy = Pretty.pprint o Pretty.quote o pretty (Syntax.init_pretty_global thy); |
20211 | 43 |
|
24920 | 44 |
val pprint_typ = pprint Syntax.pretty_typ; |
45 |
val pprint_term = pprint Syntax.pretty_term; |
|
20211 | 46 |
fun pprint_ctyp cT = pprint_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT); |
47 |
fun pprint_cterm ct = pprint_term (Thm.theory_of_cterm ct) (Thm.term_of ct); |
|
22872 | 48 |
val pprint_thm = Pretty.pprint o ProofContext.pretty_thm_legacy; |
20211 | 49 |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
50 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
51 |
(* theorems and theory *) |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
52 |
|
27176 | 53 |
fun pretty_theorems_diff prev_thys thy = |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
54 |
let |
27176 | 55 |
val pretty_fact = ProofContext.pretty_fact (ProofContext.init thy); |
56 |
val thmss = Facts.extern_static (map PureThy.facts_of prev_thys) (PureThy.facts_of thy); |
|
57 |
in Pretty.big_list "theorems:" (map pretty_fact thmss) end; |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
58 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
59 |
fun print_theorems_diff prev_thy thy = |
27176 | 60 |
Pretty.writeln (pretty_theorems_diff [prev_thy] thy); |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
61 |
|
27176 | 62 |
fun pretty_theorems thy = pretty_theorems_diff (Theory.parents_of thy) thy; |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
63 |
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
|
64 |
|
22872 | 65 |
fun pretty_full_theory verbose thy = |
66 |
Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]); |
|
20621 | 67 |
|
22872 | 68 |
val print_theory = Pretty.writeln o pretty_full_theory false; |
22335 | 69 |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
70 |
|
17369 | 71 |
(* refinement rule *) |
72 |
||
73 |
fun pretty_rule ctxt s thm = |
|
74 |
Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"), |
|
75 |
Pretty.fbrk, ProofContext.pretty_thm ctxt thm]; |
|
76 |
||
77 |
val string_of_rule = Pretty.string_of ooo pretty_rule; |
|
78 |
||
79 |
||
80 |
(* results *) |
|
81 |
||
82 |
local |
|
83 |
||
84 |
fun pretty_facts ctxt = |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19432
diff
changeset
|
85 |
flat o (separate [Pretty.fbrk, Pretty.str "and "]) o |
17369 | 86 |
map (single o ProofContext.pretty_fact ctxt); |
87 |
||
88 |
fun pretty_results ctxt ((kind, ""), facts) = |
|
89 |
Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts) |
|
90 |
| pretty_results ctxt ((kind, name), [fact]) = Pretty.blk (1, |
|
91 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, ProofContext.pretty_fact ctxt fact]) |
|
92 |
| pretty_results ctxt ((kind, name), facts) = Pretty.blk (1, |
|
93 |
[Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, |
|
94 |
Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]); |
|
95 |
||
27857 | 96 |
in |
97 |
||
98 |
fun print_results true = Pretty.writeln oo pretty_results |
|
99 |
| print_results false = K (K ()); |
|
100 |
||
101 |
end; |
|
102 |
||
103 |
||
104 |
(* theory results -- subject to hook *) |
|
105 |
||
106 |
local val hooks = ref ([]: ((string * thm list) list -> unit) list) in |
|
107 |
||
108 |
fun add_hook f = CRITICAL (fn () => change hooks (cons f)); |
|
109 |
fun get_hooks () = CRITICAL (fn () => ! hooks); |
|
110 |
||
111 |
end; |
|
112 |
||
113 |
local |
|
114 |
||
17369 | 115 |
fun name_results "" res = res |
116 |
| name_results name res = |
|
117 |
let |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19432
diff
changeset
|
118 |
val n = length (maps snd res); |
17369 | 119 |
fun name_res (a, ths) i = |
120 |
let |
|
121 |
val m = length ths; |
|
122 |
val j = i + m; |
|
123 |
in |
|
124 |
if a <> "" then ((a, ths), j) |
|
125 |
else if m = n then ((name, ths), j) |
|
26361 | 126 |
else ((Facts.string_of_ref (Facts.Named ((name, Position.none), |
127 |
SOME ([if m = 1 then Facts.Single i else Facts.FromTo (i, j - 1)]))), ths), j) |
|
17369 | 128 |
end; |
17756 | 129 |
in fst (fold_map name_res res 1) end; |
17369 | 130 |
|
131 |
in |
|
132 |
||
27857 | 133 |
fun theory_results ctxt ((kind, name), res) = |
21437 | 134 |
if kind = "" orelse kind = Thm.internalK then () |
27857 | 135 |
else |
136 |
let |
|
137 |
val _ = print_results true ctxt ((kind, name), res); |
|
138 |
val res' = name_results name res; |
|
139 |
val _ = List.app (fn f => f res') (get_hooks ()); |
|
140 |
in () end; |
|
17369 | 141 |
|
142 |
end; |
|
143 |
||
20889 | 144 |
|
145 |
(* consts *) |
|
146 |
||
147 |
local |
|
148 |
||
149 |
fun pretty_var ctxt (x, T) = |
|
150 |
Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1, |
|
24920 | 151 |
Pretty.quote (Syntax.pretty_typ ctxt T)]; |
20889 | 152 |
|
153 |
fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs); |
|
154 |
||
155 |
in |
|
156 |
||
157 |
fun pretty_consts ctxt pred cs = |
|
158 |
(case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of |
|
159 |
[] => pretty_vars ctxt "constants" cs |
|
160 |
| ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]); |
|
161 |
||
162 |
end; |
|
163 |
||
17369 | 164 |
end; |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
165 |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
166 |
structure BasicProofDisplay: BASIC_PROOF_DISPLAY = ProofDisplay; |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
167 |
open BasicProofDisplay; |