author | wenzelm |
Thu, 24 Sep 2015 23:33:29 +0200 | |
changeset 61261 | ddb2da7cb2e4 |
parent 61258 | 2be9ea29f9ec |
child 61266 | eb9522a9d997 |
permissions | -rw-r--r-- |
17369 | 1 |
(* Title: Pure/Isar/proof_display.ML |
2 |
Author: Makarius |
|
3 |
||
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
4 |
Printing of theorems, goals, results etc. |
17369 | 5 |
*) |
6 |
||
7 |
signature PROOF_DISPLAY = |
|
8 |
sig |
|
30628 | 9 |
val pp_context: Proof.context -> Pretty.T |
60937 | 10 |
val pp_thm: (unit -> theory) -> thm -> Pretty.T |
11 |
val pp_typ: (unit -> theory) -> typ -> Pretty.T |
|
12 |
val pp_term: (unit -> theory) -> term -> Pretty.T |
|
13 |
val pp_ctyp: (unit -> theory) -> ctyp -> Pretty.T |
|
14 |
val pp_cterm: (unit -> theory) -> cterm -> Pretty.T |
|
61252 | 15 |
val pretty_definitions: bool -> Proof.context -> Pretty.T |
57605 | 16 |
val pretty_theorems_diff: bool -> theory list -> theory -> Pretty.T list |
17 |
val pretty_theorems: bool -> theory -> Pretty.T list |
|
22335 | 18 |
val pretty_full_theory: bool -> theory -> Pretty.T |
20311 | 19 |
val string_of_rule: Proof.context -> string -> thm -> string |
49860 | 20 |
val pretty_goal_header: thm -> Pretty.T |
21 |
val string_of_goal: Proof.context -> thm -> string |
|
51584 | 22 |
val pretty_goal_facts: Proof.context -> string -> thm list -> Pretty.T |
49866 | 23 |
val method_error: string -> Position.T -> |
24 |
{context: Proof.context, facts: thm list, goal: thm} -> 'a Seq.result |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
25 |
val print_results: bool -> Position.T -> Proof.context -> |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
26 |
((string * string) * (string * thm list) list) -> unit |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
27 |
val print_consts: bool -> Position.T -> Proof.context -> |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
28 |
(string * typ -> bool) -> (string * typ) list -> unit |
17369 | 29 |
end |
30 |
||
33389 | 31 |
structure Proof_Display: PROOF_DISPLAY = |
17369 | 32 |
struct |
33 |
||
61252 | 34 |
(** toplevel pretty printing **) |
20211 | 35 |
|
30628 | 36 |
fun pp_context ctxt = |
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42360
diff
changeset
|
37 |
(if Config.get ctxt Proof_Context.debug then |
42360 | 38 |
Pretty.quote (Pretty.big_list "proof context:" (Proof_Context.pretty_context ctxt)) |
20211 | 39 |
else Pretty.str "<context>"); |
40 |
||
60937 | 41 |
fun default_context mk_thy = |
45269
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
42 |
(case Context.thread_data () of |
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
43 |
SOME (Context.Proof ctxt) => ctxt |
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
44 |
| SOME (Context.Theory thy) => |
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
45 |
(case try Syntax.init_pretty_global thy of |
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
46 |
SOME ctxt => ctxt |
60937 | 47 |
| NONE => Syntax.init_pretty_global (mk_thy ())) |
48 |
| NONE => Syntax.init_pretty_global (mk_thy ())); |
|
49 |
||
50 |
fun pp_thm mk_thy th = |
|
51 |
Display.pretty_thm_raw (default_context mk_thy) {quote = true, show_hyps = false} th; |
|
44240
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
52 |
|
60937 | 53 |
fun pp_typ mk_thy T = Pretty.quote (Syntax.pretty_typ (default_context mk_thy) T); |
54 |
fun pp_term mk_thy t = Pretty.quote (Syntax.pretty_term (default_context mk_thy) t); |
|
20211 | 55 |
|
60937 | 56 |
fun pp_ctyp mk_thy cT = pp_typ mk_thy (Thm.typ_of cT); |
57 |
fun pp_cterm mk_thy ct = pp_term mk_thy (Thm.term_of ct); |
|
20211 | 58 |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
59 |
|
61252 | 60 |
|
61 |
(** theory content **) |
|
62 |
||
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
63 |
(* theorems and theory *) |
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
64 |
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
65 |
fun pretty_theorems_diff verbose prev_thys thy = |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
66 |
let |
42360 | 67 |
val pretty_fact = Proof_Context.pretty_fact (Proof_Context.init_global thy); |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39284
diff
changeset
|
68 |
val facts = Global_Theory.facts_of thy; |
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
55763
diff
changeset
|
69 |
val thmss = Facts.dest_static verbose (map Global_Theory.facts_of prev_thys) facts; |
60924
610794dff23c
tuned signature, in accordance to sortBy in Scala;
wenzelm
parents:
59184
diff
changeset
|
70 |
val prts = map #1 (sort_by (#1 o #2) (map (`pretty_fact) thmss)); |
57605 | 71 |
in if null prts then [] else [Pretty.big_list "theorems:" prts] end; |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
72 |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56158
diff
changeset
|
73 |
fun pretty_theorems verbose thy = |
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56158
diff
changeset
|
74 |
pretty_theorems_diff verbose (Theory.parents_of thy) thy; |
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
75 |
|
22872 | 76 |
fun pretty_full_theory verbose thy = |
57605 | 77 |
Pretty.chunks (Display.pretty_full_theory verbose thy @ pretty_theorems verbose thy); |
20621 | 78 |
|
61252 | 79 |
|
80 |
(* definitions *) |
|
81 |
||
82 |
fun pretty_definitions verbose ctxt = |
|
83 |
let |
|
84 |
val thy = Proof_Context.theory_of ctxt; |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
85 |
val context = Proof_Context.defs_context ctxt; |
61252 | 86 |
|
61253 | 87 |
val const_space = Proof_Context.const_space ctxt; |
88 |
val type_space = Proof_Context.type_space ctxt; |
|
61256 | 89 |
val item_space = fn Defs.Const => const_space | Defs.Type => type_space; |
61253 | 90 |
fun prune_item (k, c) = not verbose andalso Name_Space.is_concealed (item_space k) c; |
91 |
||
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
92 |
fun extern_item (kind, name) = |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
93 |
let val xname = Name_Space.extern ctxt (item_space kind) name |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
94 |
in (xname, (kind, name)) end; |
61253 | 95 |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
96 |
fun extern_item_ord ((xname1, (kind1, _)), (xname2, (kind2, _))) = |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
97 |
(case Defs.item_kind_ord (kind1, kind2) of |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
98 |
EQUAL => string_ord (xname1, xname2) |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
99 |
| ord => ord); |
61253 | 100 |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
101 |
fun sort_items f = sort (extern_item_ord o apply2 f); |
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
102 |
|
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
103 |
fun pretty_entry ((_: string, item), args) = Defs.pretty_entry context (item, args); |
61252 | 104 |
|
105 |
fun pretty_reduct (lhs, rhs) = Pretty.block |
|
61253 | 106 |
([pretty_entry lhs, Pretty.str " ->", Pretty.brk 2] @ |
107 |
Pretty.commas (map pretty_entry (sort_items fst rhs))); |
|
61252 | 108 |
|
61253 | 109 |
fun pretty_restrict (entry, name) = |
110 |
Pretty.block ([pretty_entry entry, Pretty.brk 2, Pretty.str ("(from " ^ quote name ^ ")")]); |
|
61252 | 111 |
|
112 |
val defs = Theory.defs_of thy; |
|
113 |
val {restricts, reducts} = Defs.dest defs; |
|
22335 | 114 |
|
61257 | 115 |
val (reds1, reds2) = |
61253 | 116 |
filter_out (prune_item o #1 o #1) reducts |
61252 | 117 |
|> map (fn (lhs, rhs) => |
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
118 |
(apfst extern_item lhs, map (apfst extern_item) (filter_out (prune_item o fst) rhs))) |
61253 | 119 |
|> sort_items (#1 o #1) |
61257 | 120 |
|> filter_out (null o #2) |
121 |
|> List.partition (Defs.plain_args o #2 o #1); |
|
61253 | 122 |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
123 |
val rests = restricts |> map (apfst (apfst extern_item)) |> sort_items (#1 o #1); |
61252 | 124 |
in |
125 |
Pretty.big_list "definitions:" |
|
61258 | 126 |
(map (Pretty.text_fold o single) |
127 |
[Pretty.big_list "non-overloaded LHS:" (map pretty_reduct reds1), |
|
128 |
Pretty.big_list "overloaded LHS:" (map pretty_reduct reds2), |
|
129 |
Pretty.big_list "pattern restrictions due to incomplete LHS:" (map pretty_restrict rests)]) |
|
61252 | 130 |
end; |
131 |
||
132 |
||
133 |
||
134 |
(** proof items **) |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
135 |
|
17369 | 136 |
(* refinement rule *) |
137 |
||
138 |
fun pretty_rule ctxt s thm = |
|
139 |
Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"), |
|
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49867
diff
changeset
|
140 |
Pretty.fbrk, Display.pretty_thm ctxt thm]; |
17369 | 141 |
|
142 |
val string_of_rule = Pretty.string_of ooo pretty_rule; |
|
143 |
||
144 |
||
49860 | 145 |
(* goals *) |
146 |
||
147 |
local |
|
148 |
||
149 |
fun subgoals 0 = [] |
|
150 |
| subgoals 1 = [Pretty.brk 1, Pretty.str "(1 subgoal)"] |
|
151 |
| subgoals n = [Pretty.brk 1, Pretty.str ("(" ^ string_of_int n ^ " subgoals)")]; |
|
152 |
||
153 |
in |
|
154 |
||
155 |
fun pretty_goal_header goal = |
|
55763 | 156 |
Pretty.block ([Pretty.keyword1 "goal"] @ subgoals (Thm.nprems_of goal) @ [Pretty.str ":"]); |
49860 | 157 |
|
158 |
end; |
|
159 |
||
160 |
fun string_of_goal ctxt goal = |
|
51958
bca32217b304
retain goal display options when printing error messages, to avoid breakdown for huge goals;
wenzelm
parents:
51601
diff
changeset
|
161 |
Pretty.string_of (Pretty.chunks [pretty_goal_header goal, Goal_Display.pretty_goal ctxt goal]); |
49860 | 162 |
|
163 |
||
51584 | 164 |
(* goal facts *) |
165 |
||
166 |
fun pretty_goal_facts ctxt s ths = |
|
167 |
(Pretty.block o Pretty.fbreaks) |
|
51601 | 168 |
[if s = "" then Pretty.str "this:" |
55763 | 169 |
else Pretty.block [Pretty.keyword1 s, Pretty.brk 1, Pretty.str "this:"], |
51601 | 170 |
Proof_Context.pretty_fact ctxt ("", ths)]; |
51584 | 171 |
|
172 |
||
49860 | 173 |
(* method_error *) |
174 |
||
49866 | 175 |
fun method_error kind pos {context = ctxt, facts, goal} = Seq.Error (fn () => |
49860 | 176 |
let |
49866 | 177 |
val pr_header = |
178 |
"Failed to apply " ^ (if kind = "" then "" else kind ^ " ") ^ |
|
179 |
"proof method" ^ Position.here pos ^ ":\n"; |
|
49860 | 180 |
val pr_facts = |
181 |
if null facts then "" |
|
51584 | 182 |
else Pretty.string_of (pretty_goal_facts ctxt "using" facts) ^ "\n"; |
49860 | 183 |
val pr_goal = string_of_goal ctxt goal; |
184 |
in pr_header ^ pr_facts ^ pr_goal end); |
|
185 |
||
186 |
||
17369 | 187 |
(* results *) |
188 |
||
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
189 |
fun position_markup pos = Pretty.mark (Position.markup pos Markup.position); |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
190 |
|
28092 | 191 |
local |
192 |
||
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
193 |
fun pretty_fact_name pos (kind, "") = position_markup pos (Pretty.keyword1 kind) |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
194 |
| pretty_fact_name pos (kind, name) = |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
195 |
Pretty.block [position_markup pos (Pretty.keyword1 kind), Pretty.brk 1, |
41551 | 196 |
Pretty.str (Long_Name.base_name name), Pretty.str ":"]; |
28087
a9cccdd9d521
pretty_fact/results: display base only, since results now come with full names (note that Facts.extern is not really well-defined unless we present the real target context);
wenzelm
parents:
27857
diff
changeset
|
197 |
|
17369 | 198 |
fun pretty_facts ctxt = |
55763 | 199 |
flat o (separate [Pretty.fbrk, Pretty.keyword2 "and", Pretty.str " "]) o |
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49867
diff
changeset
|
200 |
map (single o Proof_Context.pretty_fact ctxt); |
17369 | 201 |
|
27857 | 202 |
in |
203 |
||
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
204 |
fun print_results do_print pos ctxt ((kind, name), facts) = |
33643
b275f26a638b
eliminated obsolete "internal" kind -- collapsed to unspecific "";
wenzelm
parents:
33515
diff
changeset
|
205 |
if not do_print orelse kind = "" then () |
28092 | 206 |
else if name = "" then |
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
57605
diff
changeset
|
207 |
(Output.state o Pretty.string_of) |
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
208 |
(Pretty.block (position_markup pos (Pretty.keyword1 kind) :: Pretty.brk 1 :: |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
209 |
pretty_facts ctxt facts)) |
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
210 |
else |
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
57605
diff
changeset
|
211 |
(Output.state o Pretty.string_of) |
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
212 |
(case facts of |
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
213 |
[fact] => Pretty.blk (1, [pretty_fact_name pos (kind, name), Pretty.fbrk, |
50126
3dec88149176
theorem status about oracles/futures is no longer printed by default;
wenzelm
parents:
49867
diff
changeset
|
214 |
Proof_Context.pretty_fact ctxt fact]) |
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
215 |
| _ => Pretty.blk (1, [pretty_fact_name pos (kind, name), Pretty.fbrk, |
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
216 |
Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])])); |
17369 | 217 |
|
218 |
end; |
|
219 |
||
20889 | 220 |
|
221 |
(* consts *) |
|
222 |
||
223 |
local |
|
224 |
||
225 |
fun pretty_var ctxt (x, T) = |
|
226 |
Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1, |
|
24920 | 227 |
Pretty.quote (Syntax.pretty_typ ctxt T)]; |
20889 | 228 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
229 |
fun pretty_vars pos ctxt kind vs = |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
230 |
Pretty.block (Pretty.fbreaks (position_markup pos (Pretty.str kind) :: map (pretty_var ctxt) vs)); |
20889 | 231 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
232 |
fun pretty_consts pos ctxt pred cs = |
42360 | 233 |
(case filter pred (#1 (Proof_Context.inferred_fixes ctxt)) of |
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
234 |
[] => pretty_vars pos ctxt "constants" cs |
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
235 |
| ps => Pretty.chunks [pretty_vars pos ctxt "parameters" ps, pretty_vars pos ctxt "constants" cs]); |
20889 | 236 |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
237 |
in |
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
238 |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
239 |
fun print_consts do_print pos ctxt pred cs = |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
240 |
if not do_print orelse null cs then () |
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
57605
diff
changeset
|
241 |
else Output.state (Pretty.string_of (pretty_consts pos ctxt pred cs)); |
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
242 |
|
20889 | 243 |
end; |
244 |
||
17369 | 245 |
end; |