| author | wenzelm |
| Wed, 03 Jul 2024 21:22:52 +0200 | |
| changeset 80495 | 9591af6f6b77 |
| parent 80328 | 559909bd7715 |
| child 80808 | 34906b3db920 |
| 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 |
|
| 79127 | 15 |
val pp_ztyp: (unit -> theory) -> ztyp -> Pretty.T |
| 61267 | 16 |
val pretty_theory: bool -> Proof.context -> Pretty.T |
| 61252 | 17 |
val pretty_definitions: bool -> Proof.context -> Pretty.T |
| 61266 | 18 |
val pretty_theorems_diff: bool -> theory list -> Proof.context -> Pretty.T list |
19 |
val pretty_theorems: bool -> Proof.context -> Pretty.T list |
|
| 20311 | 20 |
val string_of_rule: Proof.context -> string -> thm -> string |
| 49860 | 21 |
val pretty_goal_header: thm -> Pretty.T |
22 |
val string_of_goal: Proof.context -> thm -> string |
|
| 76061 | 23 |
val pretty_goal_facts: Proof.context -> string -> thm list option -> Pretty.T list |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
24 |
val pretty_goal_inst: Proof.context -> term list list -> thm -> Pretty.T list |
| 49866 | 25 |
val method_error: string -> Position.T -> |
26 |
{context: Proof.context, facts: thm list, goal: thm} -> 'a Seq.result
|
|
| 74156 | 27 |
val show_results: bool Config.T |
|
78469
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
28 |
val print_results: {interactive: bool, pos: Position.T, proof_state: bool} -> Proof.context ->
|
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
29 |
((string * string) * (string * thm list) list) -> unit |
| 78465 | 30 |
val print_theorem: Position.T -> Proof.context -> string * thm list -> unit |
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
31 |
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
|
32 |
(string * typ -> bool) -> (string * typ) list -> unit |
| 78032 | 33 |
val markup_extern_label: Position.T -> (Markup.T * xstring) option |
34 |
val print_label: Position.T -> string |
|
35 |
val print_context_tracing: Context.generic * Position.T -> string |
|
| 17369 | 36 |
end |
37 |
||
| 33389 | 38 |
structure Proof_Display: PROOF_DISPLAY = |
| 17369 | 39 |
struct |
40 |
||
| 61252 | 41 |
(** toplevel pretty printing **) |
| 20211 | 42 |
|
| 30628 | 43 |
fun pp_context ctxt = |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42360
diff
changeset
|
44 |
(if Config.get ctxt Proof_Context.debug then |
| 42360 | 45 |
Pretty.quote (Pretty.big_list "proof context:" (Proof_Context.pretty_context ctxt)) |
| 20211 | 46 |
else Pretty.str "<context>"); |
47 |
||
| 60937 | 48 |
fun default_context mk_thy = |
|
79316
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
49 |
let |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
50 |
fun global_context () = |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
51 |
Config.put_global Name_Space.names_long true (mk_thy ()); |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
52 |
in |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
53 |
(case Context.get_generic_context () of |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
54 |
SOME (Context.Proof ctxt) => ctxt |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
55 |
| SOME (Context.Theory thy) => |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
56 |
try Syntax.init_pretty_global thy |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
57 |
|> \<^if_none>\<open>Syntax.init_pretty_global (global_context ())\<close> |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
58 |
| NONE => Syntax.init_pretty_global (global_context ())) |
|
7464bb64622d
clarified ML toplevel output: avoid "??." prefix;
wenzelm
parents:
79127
diff
changeset
|
59 |
end; |
| 60937 | 60 |
|
61 |
fun pp_thm mk_thy th = |
|
| 61268 | 62 |
Thm.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
|
63 |
|
| 60937 | 64 |
fun pp_typ mk_thy T = Pretty.quote (Syntax.pretty_typ (default_context mk_thy) T); |
65 |
fun pp_term mk_thy t = Pretty.quote (Syntax.pretty_term (default_context mk_thy) t); |
|
| 20211 | 66 |
|
| 60937 | 67 |
fun pp_ctyp mk_thy cT = pp_typ mk_thy (Thm.typ_of cT); |
68 |
fun pp_cterm mk_thy ct = pp_term mk_thy (Thm.term_of ct); |
|
| 20211 | 69 |
|
| 79127 | 70 |
fun pp_ztyp mk_thy T = Pretty.quote (Syntax.pretty_typ (default_context mk_thy) (ZTerm.typ_of T)); |
71 |
||
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
72 |
|
| 61252 | 73 |
|
74 |
(** theory content **) |
|
75 |
||
| 61266 | 76 |
fun pretty_theory verbose ctxt = |
77 |
let |
|
78 |
val thy = Proof_Context.theory_of ctxt; |
|
79 |
||
80 |
fun prt_cls c = Syntax.pretty_sort ctxt [c]; |
|
81 |
fun prt_sort S = Syntax.pretty_sort ctxt S; |
|
82 |
fun prt_arity t (c, Ss) = Syntax.pretty_arity ctxt (t, Ss, [c]); |
|
83 |
fun prt_typ ty = Pretty.quote (Syntax.pretty_typ ctxt ty); |
|
84 |
val prt_typ_no_tvars = prt_typ o Logic.unvarifyT_global; |
|
85 |
fun prt_term t = Pretty.quote (Syntax.pretty_term ctxt t); |
|
86 |
val prt_term_no_vars = prt_term o Logic.unvarify_global; |
|
87 |
fun prt_const (c, ty) = [Pretty.mark_str c, Pretty.str " ::", Pretty.brk 1, prt_typ_no_tvars ty]; |
|
88 |
||
89 |
fun pretty_classrel (c, []) = prt_cls c |
|
90 |
| pretty_classrel (c, cs) = Pretty.block |
|
91 |
(prt_cls c :: Pretty.str " <" :: Pretty.brk 1 :: Pretty.commas (map prt_cls cs)); |
|
92 |
||
93 |
fun pretty_default S = Pretty.block |
|
94 |
[Pretty.str "default sort:", Pretty.brk 1, prt_sort S]; |
|
95 |
||
96 |
val tfrees = map (fn v => TFree (v, [])); |
|
| 79469 | 97 |
fun pretty_type syn (t, Type.Logical_Type n) = |
| 61266 | 98 |
if syn then NONE |
99 |
else SOME (prt_typ (Type (t, tfrees (Name.invent Name.context Name.aT n)))) |
|
100 |
| pretty_type syn (t, Type.Abbreviation (vs, U, syn')) = |
|
101 |
if syn <> syn' then NONE |
|
102 |
else SOME (Pretty.block |
|
103 |
[prt_typ (Type (t, tfrees vs)), Pretty.str " =", Pretty.brk 1, prt_typ U]) |
|
104 |
| pretty_type syn (t, Type.Nonterminal) = |
|
105 |
if not syn then NONE |
|
106 |
else SOME (prt_typ (Type (t, []))); |
|
107 |
||
108 |
val pretty_arities = maps (fn (t, ars) => map (prt_arity t) ars); |
|
109 |
||
110 |
fun pretty_abbrev (c, (ty, t)) = Pretty.block |
|
| 64596 | 111 |
(prt_const (c, ty) @ [Pretty.str " \<equiv>", Pretty.brk 1, prt_term_no_vars t]); |
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
112 |
|
| 61266 | 113 |
val tsig = Sign.tsig_of thy; |
114 |
val consts = Sign.consts_of thy; |
|
115 |
val {const_space, constants, constraints} = Consts.dest consts;
|
|
116 |
val {classes, default, types, ...} = Type.rep_tsig tsig;
|
|
117 |
val type_space = Type.type_space tsig; |
|
118 |
val (class_space, class_algebra) = classes; |
|
119 |
val classes = Sorts.classes_of class_algebra; |
|
120 |
val arities = Sorts.arities_of class_algebra; |
|
121 |
||
122 |
val clsses = |
|
123 |
Name_Space.extern_entries verbose ctxt class_space |
|
124 |
(map (fn ((c, _), cs) => (c, Sign.minimize_sort thy cs)) (Graph.dest classes)) |
|
125 |
|> map (apfst #1); |
|
126 |
val tdecls = Name_Space.extern_table verbose ctxt types |> map (apfst #1); |
|
127 |
val arties = |
|
128 |
Name_Space.extern_entries verbose ctxt type_space (Symtab.dest arities) |
|
129 |
|> map (apfst #1); |
|
130 |
||
131 |
val cnsts = Name_Space.markup_entries verbose ctxt const_space constants; |
|
132 |
val log_cnsts = map_filter (fn (c, (ty, NONE)) => SOME (c, ty) | _ => NONE) cnsts; |
|
133 |
val abbrevs = map_filter (fn (c, (ty, SOME t)) => SOME (c, (ty, t)) | _ => NONE) cnsts; |
|
134 |
val cnstrs = Name_Space.markup_entries verbose ctxt const_space constraints; |
|
135 |
in |
|
| 61267 | 136 |
Pretty.chunks |
137 |
[Pretty.big_list "classes:" (map pretty_classrel clsses), |
|
| 61266 | 138 |
pretty_default default, |
139 |
Pretty.big_list "syntactic types:" (map_filter (pretty_type true) tdecls), |
|
140 |
Pretty.big_list "logical types:" (map_filter (pretty_type false) tdecls), |
|
141 |
Pretty.big_list "type arities:" (pretty_arities arties), |
|
142 |
Pretty.big_list "logical consts:" (map (Pretty.block o prt_const) log_cnsts), |
|
143 |
Pretty.big_list "abbreviations:" (map pretty_abbrev abbrevs), |
|
144 |
Pretty.big_list "constraints:" (map (Pretty.block o prt_const) cnstrs), |
|
145 |
Pretty.block |
|
146 |
(Pretty.breaks (Pretty.str "oracles:" :: |
|
| 61267 | 147 |
map Pretty.mark_str (Thm.extern_oracles verbose ctxt)))] |
148 |
end; |
|
149 |
||
150 |
||
151 |
(* theorems *) |
|
152 |
||
153 |
fun pretty_theorems_diff verbose prev_thys ctxt = |
|
154 |
let |
|
155 |
val pretty_fact = Proof_Context.pretty_fact ctxt; |
|
156 |
val facts = Global_Theory.facts_of (Proof_Context.theory_of ctxt); |
|
157 |
val thmss = Facts.dest_static verbose (map Global_Theory.facts_of prev_thys) facts; |
|
158 |
val prts = map #1 (sort_by (#1 o #2) (map (`pretty_fact) thmss)); |
|
159 |
in if null prts then [] else [Pretty.big_list "theorems:" prts] end; |
|
160 |
||
161 |
fun pretty_theorems verbose ctxt = |
|
162 |
pretty_theorems_diff verbose (Theory.parents_of (Proof_Context.theory_of ctxt)) ctxt; |
|
| 20621 | 163 |
|
| 61252 | 164 |
|
165 |
(* definitions *) |
|
166 |
||
167 |
fun pretty_definitions verbose ctxt = |
|
168 |
let |
|
169 |
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
|
170 |
val context = Proof_Context.defs_context ctxt; |
| 61252 | 171 |
|
| 61253 | 172 |
val const_space = Proof_Context.const_space ctxt; |
173 |
val type_space = Proof_Context.type_space ctxt; |
|
| 61256 | 174 |
val item_space = fn Defs.Const => const_space | Defs.Type => type_space; |
| 61253 | 175 |
fun prune_item (k, c) = not verbose andalso Name_Space.is_concealed (item_space k) c; |
176 |
||
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
177 |
fun extern_item (kind, name) = |
|
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
178 |
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
|
179 |
in (xname, (kind, name)) end; |
| 61253 | 180 |
|
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
181 |
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
|
182 |
(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
|
183 |
EQUAL => string_ord (xname1, xname2) |
|
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
184 |
| ord => ord); |
| 61253 | 185 |
|
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
186 |
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
|
187 |
|
|
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
188 |
fun pretty_entry ((_: string, item), args) = Defs.pretty_entry context (item, args); |
| 61252 | 189 |
|
190 |
fun pretty_reduct (lhs, rhs) = Pretty.block |
|
| 61253 | 191 |
([pretty_entry lhs, Pretty.str " ->", Pretty.brk 2] @ |
192 |
Pretty.commas (map pretty_entry (sort_items fst rhs))); |
|
| 61252 | 193 |
|
| 61253 | 194 |
fun pretty_restrict (entry, name) = |
195 |
Pretty.block ([pretty_entry entry, Pretty.brk 2, Pretty.str ("(from " ^ quote name ^ ")")]);
|
|
| 61252 | 196 |
|
197 |
val defs = Theory.defs_of thy; |
|
198 |
val {restricts, reducts} = Defs.dest defs;
|
|
| 22335 | 199 |
|
| 61257 | 200 |
val (reds1, reds2) = |
| 61253 | 201 |
filter_out (prune_item o #1 o #1) reducts |
| 61252 | 202 |
|> map (fn (lhs, rhs) => |
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
203 |
(apfst extern_item lhs, map (apfst extern_item) (filter_out (prune_item o fst) rhs))) |
| 61253 | 204 |
|> sort_items (#1 o #1) |
| 61257 | 205 |
|> filter_out (null o #2) |
206 |
|> List.partition (Defs.plain_args o #2 o #1); |
|
| 61253 | 207 |
|
|
61261
ddb2da7cb2e4
more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents:
61258
diff
changeset
|
208 |
val rests = restricts |> map (apfst (apfst extern_item)) |> sort_items (#1 o #1); |
| 61252 | 209 |
in |
210 |
Pretty.big_list "definitions:" |
|
| 61258 | 211 |
(map (Pretty.text_fold o single) |
212 |
[Pretty.big_list "non-overloaded LHS:" (map pretty_reduct reds1), |
|
213 |
Pretty.big_list "overloaded LHS:" (map pretty_reduct reds2), |
|
214 |
Pretty.big_list "pattern restrictions due to incomplete LHS:" (map pretty_restrict rests)]) |
|
| 61252 | 215 |
end; |
216 |
||
217 |
||
218 |
||
219 |
(** proof items **) |
|
|
19432
cae7cc072994
added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents:
18799
diff
changeset
|
220 |
|
| 17369 | 221 |
(* refinement rule *) |
222 |
||
223 |
fun pretty_rule ctxt s thm = |
|
224 |
Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"), |
|
| 61268 | 225 |
Pretty.fbrk, Thm.pretty_thm ctxt thm]; |
| 17369 | 226 |
|
227 |
val string_of_rule = Pretty.string_of ooo pretty_rule; |
|
228 |
||
229 |
||
| 49860 | 230 |
(* goals *) |
231 |
||
232 |
local |
|
233 |
||
234 |
fun subgoals 0 = [] |
|
235 |
| subgoals 1 = [Pretty.brk 1, Pretty.str "(1 subgoal)"] |
|
236 |
| subgoals n = [Pretty.brk 1, Pretty.str ("(" ^ string_of_int n ^ " subgoals)")];
|
|
237 |
||
238 |
in |
|
239 |
||
240 |
fun pretty_goal_header goal = |
|
| 55763 | 241 |
Pretty.block ([Pretty.keyword1 "goal"] @ subgoals (Thm.nprems_of goal) @ [Pretty.str ":"]); |
| 49860 | 242 |
|
243 |
end; |
|
244 |
||
245 |
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
|
246 |
Pretty.string_of (Pretty.chunks [pretty_goal_header goal, Goal_Display.pretty_goal ctxt goal]); |
| 49860 | 247 |
|
248 |
||
| 51584 | 249 |
(* goal facts *) |
250 |
||
| 76061 | 251 |
fun pretty_goal_facts _ _ NONE = [] |
252 |
| pretty_goal_facts ctxt s (SOME ths) = |
|
253 |
(single o Pretty.block o Pretty.fbreaks) |
|
254 |
[if s = "" then Pretty.str "this:" |
|
255 |
else Pretty.block [Pretty.keyword1 s, Pretty.brk 1, Pretty.str "this:"], |
|
256 |
Proof_Context.pretty_fact ctxt ("", ths)];
|
|
| 51584 | 257 |
|
258 |
||
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
259 |
(* goal instantiation *) |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
260 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
261 |
fun pretty_goal_inst ctxt propss goal = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
262 |
let |
| 76079 | 263 |
val title = "goal instantiation:"; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
264 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
265 |
fun prt_inst env = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
266 |
if Envir.is_empty env then [] |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
267 |
else |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
268 |
let |
|
76067
e39c1da9d904
proper Envir.subst operations: env is already normalized, using Envir.norm may lead to non-termination;
wenzelm
parents:
76066
diff
changeset
|
269 |
val Envir.Envir {tyenv, tenv, ...} = env;
|
|
e39c1da9d904
proper Envir.subst operations: env is already normalized, using Envir.norm may lead to non-termination;
wenzelm
parents:
76066
diff
changeset
|
270 |
|
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
271 |
val prt_type = Syntax.pretty_typ ctxt; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
272 |
val prt_term = Syntax.pretty_term ctxt; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
273 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
274 |
fun instT v = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
275 |
let |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
276 |
val T = TVar v; |
|
76067
e39c1da9d904
proper Envir.subst operations: env is already normalized, using Envir.norm may lead to non-termination;
wenzelm
parents:
76066
diff
changeset
|
277 |
val T' = Envir.subst_type tyenv T; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
278 |
in if T = T' then NONE else SOME (prt_type T, prt_type T') end; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
279 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
280 |
fun inst v = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
281 |
let |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
282 |
val t = Var v; |
|
79540
afa75b58166a
more robust (amending 1600fb749c54), to support the following corner case:
wenzelm
parents:
79469
diff
changeset
|
283 |
val t' = |
|
afa75b58166a
more robust (amending 1600fb749c54), to support the following corner case:
wenzelm
parents:
79469
diff
changeset
|
284 |
Envir.subst_term (tyenv, tenv) t handle TYPE _ => |
|
afa75b58166a
more robust (amending 1600fb749c54), to support the following corner case:
wenzelm
parents:
79469
diff
changeset
|
285 |
Envir.subst_term (tyenv, tenv) (Envir.subst_term_types tyenv t); |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
286 |
in if t aconv t' then NONE else SOME (prt_term t, prt_term t') end; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
287 |
|
| 76079 | 288 |
fun inst_pair (x, y) = Pretty.item [x, Pretty.str " \<leadsto>", Pretty.brk 1, y]; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
289 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
290 |
val prts = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
291 |
((fold o fold) Term.add_tvars propss [] |> sort Term_Ord.tvar_ord |> map_filter instT) @ |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
292 |
((fold o fold) Term.add_vars propss [] |> sort Term_Ord.var_ord |> map_filter inst); |
| 76079 | 293 |
in if null prts then [] else [Pretty.big_list title (map inst_pair prts)] end; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
294 |
|
|
76081
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
295 |
exception LOST_STRUCTURE; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
296 |
fun goal_matcher () = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
297 |
let |
|
76081
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
298 |
val concl = |
|
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
299 |
Logic.unprotect (Thm.concl_of goal) |
|
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
300 |
handle TERM _ => raise LOST_STRUCTURE; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
301 |
val goal_propss = filter_out null propss; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
302 |
val results = |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
303 |
Logic.dest_conjunction_balanced (length goal_propss) concl |
|
76081
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
304 |
|> map2 Logic.dest_conjunction_balanced (map length goal_propss) |
|
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
305 |
handle TERM _ => raise LOST_STRUCTURE; |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
306 |
in |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
307 |
Unify.matcher (Context.Proof ctxt) |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
308 |
(map (Soft_Type_System.purge ctxt) (flat goal_propss)) (flat results) |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
309 |
end; |
|
76081
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
310 |
|
|
730638d4e37a
clarified failure: warning for logical error, exception for program breakdown;
wenzelm
parents:
76079
diff
changeset
|
311 |
fun failure msg = (warning (title ^ " " ^ msg); []); |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
312 |
in |
|
76095
7cac5565e79b
discontinued somewhat pointless option: Proof_Display.pretty_goal_inst should always work smoothly (and not crash unexpectedly);
wenzelm
parents:
76081
diff
changeset
|
313 |
(case goal_matcher () of |
|
7cac5565e79b
discontinued somewhat pointless option: Proof_Display.pretty_goal_inst should always work smoothly (and not crash unexpectedly);
wenzelm
parents:
76081
diff
changeset
|
314 |
SOME env => prt_inst env |
|
7cac5565e79b
discontinued somewhat pointless option: Proof_Display.pretty_goal_inst should always work smoothly (and not crash unexpectedly);
wenzelm
parents:
76081
diff
changeset
|
315 |
| NONE => failure "match failed") |
|
7cac5565e79b
discontinued somewhat pointless option: Proof_Display.pretty_goal_inst should always work smoothly (and not crash unexpectedly);
wenzelm
parents:
76081
diff
changeset
|
316 |
handle LOST_STRUCTURE => failure "lost goal structure" |
|
76064
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
317 |
end; |
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
318 |
|
|
28ddebb43d93
show goal instantiation, notably for 'schematic_goal' command (inactive by default);
wenzelm
parents:
76061
diff
changeset
|
319 |
|
| 49860 | 320 |
(* method_error *) |
321 |
||
| 49866 | 322 |
fun method_error kind pos {context = ctxt, facts, goal} = Seq.Error (fn () =>
|
| 49860 | 323 |
let |
| 49866 | 324 |
val pr_header = |
325 |
"Failed to apply " ^ (if kind = "" then "" else kind ^ " ") ^ |
|
326 |
"proof method" ^ Position.here pos ^ ":\n"; |
|
| 49860 | 327 |
val pr_facts = |
328 |
if null facts then "" |
|
| 76061 | 329 |
else Pretty.string_of (Pretty.chunks (pretty_goal_facts ctxt "using" (SOME facts))) ^ "\n"; |
| 49860 | 330 |
val pr_goal = string_of_goal ctxt goal; |
331 |
in pr_header ^ pr_facts ^ pr_goal end); |
|
332 |
||
333 |
||
| 17369 | 334 |
(* results *) |
335 |
||
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
336 |
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
|
337 |
|
| 74156 | 338 |
val interactive = |
339 |
Config.declare_bool ("interactive", \<^here>) (K false);
|
|
340 |
||
341 |
val show_results = |
|
| 76065 | 342 |
Attrib.setup_config_bool \<^binding>\<open>show_results\<close> |
|
76073
951abf9db857
option "show_states" for more verbosity of batch-builds;
wenzelm
parents:
76071
diff
changeset
|
343 |
(fn context => |
|
951abf9db857
option "show_states" for more verbosity of batch-builds;
wenzelm
parents:
76071
diff
changeset
|
344 |
Config.get_generic context interactive orelse |
|
951abf9db857
option "show_states" for more verbosity of batch-builds;
wenzelm
parents:
76071
diff
changeset
|
345 |
Options.default_bool \<^system_option>\<open>show_states\<close>); |
| 74156 | 346 |
|
347 |
fun no_print int ctxt = not (Config.get (Config.put interactive int ctxt) show_results); |
|
348 |
||
| 28092 | 349 |
local |
350 |
||
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
351 |
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
|
352 |
| 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
|
353 |
Pretty.block [position_markup pos (Pretty.keyword1 kind), Pretty.brk 1, |
| 41551 | 354 |
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
|
355 |
|
| 17369 | 356 |
fun pretty_facts ctxt = |
| 55763 | 357 |
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
|
358 |
map (single o Proof_Context.pretty_fact ctxt); |
| 17369 | 359 |
|
| 27857 | 360 |
in |
361 |
||
|
78469
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
362 |
fun print_results {interactive, pos, proof_state} ctxt ((kind, name), facts) =
|
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
363 |
let val print = if proof_state then Output.state o Pretty.string_of else Pretty.writeln in |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
364 |
if kind = "" orelse no_print interactive ctxt then () |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
365 |
else if name = "" then |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
366 |
|
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
367 |
(Pretty.block (position_markup pos (Pretty.keyword1 kind) :: Pretty.brk 1 :: |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
368 |
pretty_facts ctxt facts)) |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
369 |
else |
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
370 |
|
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
371 |
(case facts of |
| 80328 | 372 |
[fact] => Pretty.block1 [pretty_fact_name pos (kind, name), Pretty.fbrk, |
373 |
Proof_Context.pretty_fact ctxt fact] |
|
374 |
| _ => Pretty.block1 [pretty_fact_name pos (kind, name), Pretty.fbrk, |
|
375 |
Pretty.block1 (Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])])
|
|
|
78469
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
376 |
end; |
| 17369 | 377 |
|
| 78465 | 378 |
fun print_theorem pos ctxt fact = |
|
78469
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
379 |
print_results {interactive = true, pos = pos, proof_state = false}
|
|
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
380 |
ctxt ((Thm.theoremK, ""), [fact]); |
| 78465 | 381 |
|
| 17369 | 382 |
end; |
383 |
||
| 20889 | 384 |
|
385 |
(* consts *) |
|
386 |
||
387 |
local |
|
388 |
||
389 |
fun pretty_var ctxt (x, T) = |
|
390 |
Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1, |
|
| 24920 | 391 |
Pretty.quote (Syntax.pretty_typ ctxt T)]; |
| 20889 | 392 |
|
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
393 |
fun pretty_vars pos ctxt kind vs = |
| 62188 | 394 |
Pretty.block |
395 |
(Pretty.fbreaks (position_markup pos (Pretty.mark_str kind) :: map (pretty_var ctxt) vs)); |
|
396 |
||
397 |
val fixes = (Markup.keyword2, "fixes"); |
|
398 |
val consts = (Markup.keyword1, "consts"); |
|
| 20889 | 399 |
|
|
56932
11a4001b06c6
more position markup to help locating the query context, e.g. from "Info" dockable;
wenzelm
parents:
56897
diff
changeset
|
400 |
fun pretty_consts pos ctxt pred cs = |
| 42360 | 401 |
(case filter pred (#1 (Proof_Context.inferred_fixes ctxt)) of |
| 62188 | 402 |
[] => pretty_vars pos ctxt consts cs |
403 |
| ps => Pretty.chunks [pretty_vars pos ctxt fixes ps, pretty_vars pos ctxt consts cs]); |
|
| 20889 | 404 |
|
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
405 |
in |
|
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
406 |
|
| 74156 | 407 |
fun print_consts int pos ctxt pred cs = |
408 |
if null cs orelse no_print int ctxt then () |
|
|
78469
53b59fa42696
prefer Output.writeln for theory "results", as opposed to Output.state for genuine proof states (see f8c412a45af8, c668735fb8b5, ecf80e37ed1a);
wenzelm
parents:
78465
diff
changeset
|
409 |
else Pretty.writeln (pretty_consts pos ctxt pred cs); |
|
44192
a32ca9165928
less verbosity in batch mode -- spam reduction and notable performance improvement;
wenzelm
parents:
42717
diff
changeset
|
410 |
|
| 20889 | 411 |
end; |
412 |
||
| 78032 | 413 |
|
414 |
(* position label *) |
|
415 |
||
416 |
val command_prefix = Markup.commandN ^ "."; |
|
417 |
||
418 |
fun markup_extern_label pos = |
|
419 |
Position.label_of pos |> Option.map (fn label => |
|
420 |
(case try (unprefix command_prefix) label of |
|
421 |
SOME cmd => (Markup.keyword1, Long_Name.base_name cmd) |
|
422 |
| NONE => (Markup.empty, label))); |
|
423 |
||
424 |
fun print_label pos = |
|
425 |
(case markup_extern_label pos of |
|
426 |
NONE => "" |
|
427 |
| SOME (m, s) => Markup.markup m s); |
|
428 |
||
429 |
||
430 |
(* context tracing *) |
|
431 |
||
432 |
fun context_type (Context.Theory _) = "theory" |
|
433 |
| context_type (Context.Proof ctxt) = |
|
434 |
if can Local_Theory.assert ctxt then "local_theory" else "Proof.context"; |
|
435 |
||
436 |
fun print_context_tracing (context, pos) = |
|
437 |
context_type context ^ (case print_label pos of "" => "" | s => " " ^ s) ^ Position.here pos; |
|
438 |
||
| 17369 | 439 |
end; |