1 (* Title: Pure/Isar/proof_display.ML
5 Printing of theorems, goals, results etc.
8 signature BASIC_PROOF_DISPLAY =
10 val print_theorems: theory -> unit
11 val print_theory: theory -> unit
14 signature PROOF_DISPLAY =
16 include BASIC_PROOF_DISPLAY
17 val pprint_context: Proof.context -> pprint_args -> unit
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
23 val print_theorems_diff: theory -> theory -> unit
24 val pretty_full_theory: bool -> theory -> Pretty.T
25 val string_of_rule: Proof.context -> string -> thm -> string
26 val print_results: bool -> Proof.context ->
27 ((string * string) * (string * thm list) list) -> unit
28 val present_results: Proof.context ->
29 ((string * string) * (string * thm list) list) -> unit
30 val pretty_consts: Proof.context ->
31 (string * typ -> bool) -> (string * typ) list -> Pretty.T
34 structure ProofDisplay: PROOF_DISPLAY =
37 (* toplevel pretty printing *)
39 fun pprint_context ctxt = Pretty.pprint
40 (if ! ProofContext.debug then
41 Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt))
42 else Pretty.str "<context>");
44 fun pprint pretty thy = Pretty.pprint o Pretty.quote o pretty (ProofContext.init thy);
46 val pprint_typ = pprint Syntax.pretty_typ;
47 val pprint_term = pprint Syntax.pretty_term;
48 fun pprint_ctyp cT = pprint_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT);
49 fun pprint_cterm ct = pprint_term (Thm.theory_of_cterm ct) (Thm.term_of ct);
50 val pprint_thm = Pretty.pprint o ProofContext.pretty_thm_legacy;
53 (* theorems and theory *)
55 fun pretty_theorems_diff prev_thms thy =
57 val ctxt = ProofContext.init thy;
58 val (space, thms) = PureThy.theorems_of thy;
59 val diff_thmss = Symtab.fold (fn fact =>
60 if not (Symtab.member Thm.eq_thms prev_thms fact) then cons fact else I) thms [];
61 val thmss = diff_thmss |> map (apfst (NameSpace.extern space)) |> Library.sort_wrt #1;
62 in Pretty.big_list "theorems:" (map (ProofContext.pretty_fact ctxt) thmss) end;
64 fun print_theorems_diff prev_thy thy =
65 Pretty.writeln (pretty_theorems_diff (#2 (PureThy.theorems_of prev_thy)) thy);
67 fun pretty_theorems thy = pretty_theorems_diff Symtab.empty thy;
69 val print_theorems = Pretty.writeln o pretty_theorems;
71 fun pretty_full_theory verbose thy =
72 Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]);
74 val print_theory = Pretty.writeln o pretty_full_theory false;
79 fun pretty_rule ctxt s thm =
80 Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
81 Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
83 val string_of_rule = Pretty.string_of ooo pretty_rule;
90 fun pretty_facts ctxt =
91 flat o (separate [Pretty.fbrk, Pretty.str "and "]) o
92 map (single o ProofContext.pretty_fact ctxt);
94 fun pretty_results ctxt ((kind, ""), facts) =
95 Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts)
96 | pretty_results ctxt ((kind, name), [fact]) = Pretty.blk (1,
97 [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, ProofContext.pretty_fact ctxt fact])
98 | pretty_results ctxt ((kind, name), facts) = Pretty.blk (1,
99 [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk,
100 Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]);
102 fun name_results "" res = res
103 | name_results name res =
105 val n = length (maps snd res);
106 fun name_res (a, ths) i =
111 if a <> "" then ((a, ths), j)
112 else if m = n then ((name, ths), j)
114 ((PureThy.string_of_thmref (NameSelection (name, [Single i])), ths), j)
115 else ((PureThy.string_of_thmref (NameSelection (name, [FromTo (i, j - 1)])), ths), j)
117 in fst (fold_map name_res res 1) end;
121 fun print_results true = Pretty.writeln oo pretty_results
122 | print_results false = K (K ());
124 fun present_results ctxt ((kind, name), res) =
125 if kind = "" orelse kind = Thm.internalK then ()
126 else (print_results true ctxt ((kind, name), res);
127 ML_Context.setmp (SOME (Context.Proof ctxt))
128 (Present.results kind) (name_results name res));
137 fun pretty_var ctxt (x, T) =
138 Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1,
139 Pretty.quote (Syntax.pretty_typ ctxt T)];
141 fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs);
145 fun pretty_consts ctxt pred cs =
146 (case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of
147 [] => pretty_vars ctxt "constants" cs
148 | ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]);
154 structure BasicProofDisplay: BASIC_PROOF_DISPLAY = ProofDisplay;
155 open BasicProofDisplay;