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