| author | wenzelm |
| Thu, 18 Oct 2012 14:15:46 +0200 | |
| changeset 49912 | c6307ee2665d |
| parent 49867 | d3053a55bfcb |
| child 50126 | 3dec88149176 |
| 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 |
10 |
val pp_thm: thm -> Pretty.T |
|
11 |
val pp_typ: theory -> typ -> Pretty.T |
|
12 |
val pp_term: theory -> term -> Pretty.T |
|
13 |
val pp_ctyp: ctyp -> Pretty.T |
|
14 |
val pp_cterm: cterm -> Pretty.T |
|
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
15 |
val print_theorems_diff: bool -> theory -> theory -> unit |
|
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
16 |
val print_theorems: bool -> theory -> unit |
| 22335 | 17 |
val pretty_full_theory: bool -> theory -> Pretty.T |
| 28092 | 18 |
val print_theory: theory -> unit |
| 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 |
|
| 49866 | 22 |
val method_error: string -> Position.T -> |
23 |
{context: Proof.context, facts: thm list, goal: thm} -> 'a Seq.result
|
|
|
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
24 |
val print_results: Markup.T -> bool -> Proof.context -> |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
25 |
((string * string) * (string * thm list) list) -> unit |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
26 |
val print_consts: bool -> Proof.context -> (string * typ -> bool) -> (string * typ) list -> unit |
| 17369 | 27 |
end |
28 |
||
| 33389 | 29 |
structure Proof_Display: PROOF_DISPLAY = |
| 17369 | 30 |
struct |
31 |
||
| 20235 | 32 |
(* toplevel pretty printing *) |
| 20211 | 33 |
|
| 30628 | 34 |
fun pp_context ctxt = |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42360
diff
changeset
|
35 |
(if Config.get ctxt Proof_Context.debug then |
| 42360 | 36 |
Pretty.quote (Pretty.big_list "proof context:" (Proof_Context.pretty_context ctxt)) |
| 20211 | 37 |
else Pretty.str "<context>"); |
38 |
||
|
45269
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
39 |
fun default_context thy0 = |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
40 |
(case Context.thread_data () of |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
41 |
SOME (Context.Proof ctxt) => ctxt |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
42 |
| SOME (Context.Theory thy) => |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
43 |
(case try Syntax.init_pretty_global thy of |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
44 |
SOME ctxt => ctxt |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
45 |
| NONE => Syntax.init_pretty_global thy0) |
|
6f8949e6c71a
more robust ML pretty printing (cf. b6c527c64789);
wenzelm
parents:
44240
diff
changeset
|
46 |
| NONE => Syntax.init_pretty_global thy0); |
|
44240
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
47 |
|
| 30628 | 48 |
fun pp_thm th = |
|
30724
2e54e89bcce7
pretty_rule/print_results: no thm status here -- it is potentially slow and mostly uninformative/confusing as long as proofs are still unfinished;
wenzelm
parents:
30628
diff
changeset
|
49 |
let |
|
44240
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
50 |
val ctxt = default_context (Thm.theory_of_thm th); |
|
30724
2e54e89bcce7
pretty_rule/print_results: no thm status here -- it is potentially slow and mostly uninformative/confusing as long as proofs are still unfinished;
wenzelm
parents:
30628
diff
changeset
|
51 |
val flags = {quote = true, show_hyps = false, show_status = true};
|
|
44240
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
52 |
in Display.pretty_thm_raw ctxt flags th end; |
| 20211 | 53 |
|
|
44240
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
54 |
fun pp_typ thy T = Pretty.quote (Syntax.pretty_typ (default_context thy) T); |
|
4b1a63678839
improved default context for ML toplevel pretty-printing;
wenzelm
parents:
44192
diff
changeset
|
55 |
fun pp_term thy t = Pretty.quote (Syntax.pretty_term (default_context thy) t); |
| 30628 | 56 |
|
57 |
fun pp_ctyp cT = pp_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT); |
|
58 |
fun pp_cterm ct = pp_term (Thm.theory_of_cterm ct) (Thm.term_of ct); |
|
| 20211 | 59 |
|
|
19432
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 |
(* theorems and theory *) |
|
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
62 |
|
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
63 |
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
|
64 |
let |
| 42360 | 65 |
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
|
66 |
val facts = Global_Theory.facts_of thy; |
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
67 |
val thmss = |
|
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 |
Facts.dest_static (map Global_Theory.facts_of prev_thys) facts |
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
69 |
|> not verbose ? filter_out (Facts.is_concealed facts o #1); |
| 28210 | 70 |
in Pretty.big_list "theorems:" (map #1 (sort_wrt (#1 o #2) (map (`pretty_fact) thmss))) end; |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
71 |
|
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
72 |
fun print_theorems_diff verbose prev_thy thy = |
|
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
73 |
Pretty.writeln (pretty_theorems_diff verbose [prev_thy] thy); |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
74 |
|
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
75 |
fun pretty_theorems verbose thy = pretty_theorems_diff verbose (Theory.parents_of thy) thy; |
|
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
76 |
val print_theorems = Pretty.writeln oo pretty_theorems; |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
77 |
|
| 22872 | 78 |
fun pretty_full_theory verbose thy = |
|
33515
d066e8369a33
print_theorems: suppress concealed (global) facts, unless "!" option is given;
wenzelm
parents:
33389
diff
changeset
|
79 |
Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems verbose thy]); |
| 20621 | 80 |
|
| 22872 | 81 |
val print_theory = Pretty.writeln o pretty_full_theory false; |
| 22335 | 82 |
|
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
83 |
|
| 17369 | 84 |
(* refinement rule *) |
85 |
||
86 |
fun pretty_rule ctxt s thm = |
|
87 |
Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"), |
|
|
32091
30e2ffbba718
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents:
30724
diff
changeset
|
88 |
Pretty.fbrk, Display.pretty_thm_aux ctxt false thm]; |
| 17369 | 89 |
|
90 |
val string_of_rule = Pretty.string_of ooo pretty_rule; |
|
91 |
||
92 |
||
| 49860 | 93 |
(* goals *) |
94 |
||
95 |
local |
|
96 |
||
97 |
fun subgoals 0 = [] |
|
98 |
| subgoals 1 = [Pretty.brk 1, Pretty.str "(1 subgoal)"] |
|
99 |
| subgoals n = [Pretty.brk 1, Pretty.str ("(" ^ string_of_int n ^ " subgoals)")];
|
|
100 |
||
101 |
in |
|
102 |
||
103 |
fun pretty_goal_header goal = |
|
104 |
Pretty.block ([Pretty.command "goal"] @ subgoals (Thm.nprems_of goal) @ [Pretty.str ":"]); |
|
105 |
||
106 |
end; |
|
107 |
||
108 |
fun string_of_goal ctxt goal = |
|
109 |
Pretty.string_of (Pretty.chunks |
|
110 |
[pretty_goal_header goal, Goal_Display.pretty_goal {main = true, limit = false} ctxt goal]);
|
|
111 |
||
112 |
||
113 |
(* method_error *) |
|
114 |
||
| 49866 | 115 |
fun method_error kind pos {context = ctxt, facts, goal} = Seq.Error (fn () =>
|
| 49860 | 116 |
let |
| 49866 | 117 |
val pr_header = |
118 |
"Failed to apply " ^ (if kind = "" then "" else kind ^ " ") ^ |
|
119 |
"proof method" ^ Position.here pos ^ ":\n"; |
|
| 49860 | 120 |
val pr_facts = |
121 |
if null facts then "" |
|
122 |
else |
|
| 49867 | 123 |
(Pretty.string_of o Pretty.block o Pretty.fbreaks) |
124 |
(Pretty.block [Pretty.command "using", Pretty.brk 1, Pretty.str "this:"] :: |
|
125 |
map (Display.pretty_thm ctxt) facts) ^ "\n"; |
|
| 49860 | 126 |
val pr_goal = string_of_goal ctxt goal; |
127 |
in pr_header ^ pr_facts ^ pr_goal end); |
|
128 |
||
129 |
||
| 17369 | 130 |
(* results *) |
131 |
||
| 28092 | 132 |
local |
133 |
||
| 41551 | 134 |
fun pretty_fact_name (kind, "") = Pretty.command kind |
135 |
| pretty_fact_name (kind, name) = |
|
136 |
Pretty.block [Pretty.command kind, Pretty.brk 1, |
|
137 |
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
|
138 |
|
| 17369 | 139 |
fun pretty_facts ctxt = |
| 41551 | 140 |
flat o (separate [Pretty.fbrk, Pretty.keyword "and", Pretty.str " "]) o |
| 42360 | 141 |
map (single o Proof_Context.pretty_fact_aux ctxt false); |
| 17369 | 142 |
|
| 27857 | 143 |
in |
144 |
||
|
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
145 |
fun print_results markup do_print ctxt ((kind, name), facts) = |
|
33643
b275f26a638b
eliminated obsolete "internal" kind -- collapsed to unspecific "";
wenzelm
parents:
33515
diff
changeset
|
146 |
if not do_print orelse kind = "" then () |
| 28092 | 147 |
else if name = "" then |
|
46728
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
148 |
(Pretty.writeln o Pretty.mark markup) |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
149 |
(Pretty.block (Pretty.command kind :: Pretty.brk 1 :: pretty_facts ctxt facts)) |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
150 |
else |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
151 |
(Pretty.writeln o Pretty.mark markup) |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
152 |
(case facts of |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
153 |
[fact] => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk, |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
154 |
Proof_Context.pretty_fact_aux ctxt false fact]) |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
155 |
| _ => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk, |
|
85f8e3932712
display proof results as "state", to suppress odd squiggles in the Prover IDE (see also 9240be8c8c69);
wenzelm
parents:
45269
diff
changeset
|
156 |
Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]));
|
| 17369 | 157 |
|
158 |
end; |
|
159 |
||
| 20889 | 160 |
|
161 |
(* consts *) |
|
162 |
||
163 |
local |
|
164 |
||
165 |
fun pretty_var ctxt (x, T) = |
|
166 |
Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1, |
|
| 24920 | 167 |
Pretty.quote (Syntax.pretty_typ ctxt T)]; |
| 20889 | 168 |
|
169 |
fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs); |
|
170 |
||
171 |
fun pretty_consts ctxt pred cs = |
|
| 42360 | 172 |
(case filter pred (#1 (Proof_Context.inferred_fixes ctxt)) of |
| 20889 | 173 |
[] => pretty_vars ctxt "constants" cs |
174 |
| ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]); |
|
175 |
||
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
176 |
in |
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
177 |
|
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
178 |
fun print_consts do_print ctxt pred cs = |
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
179 |
if not do_print orelse null cs then () |
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
180 |
else Pretty.writeln (pretty_consts ctxt pred cs); |
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
181 |
|
| 20889 | 182 |
end; |
183 |
||
| 17369 | 184 |
end; |