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