src/Pure/Isar/proof_display.ML
author wenzelm
Sat, 13 Dec 2008 15:00:39 +0100
changeset 29091 b81fe045e799
parent 28210 c164d1892553
child 29606 fedb8be05f24
permissions -rw-r--r--
Context.display_names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/proof_display.ML
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     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
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     6
*)
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     7
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     8
signature PROOF_DISPLAY =
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
     9
sig
20311
3666316adad6 moved debug option to proof_display.ML (again);
wenzelm
parents: 20253
diff changeset
    10
  val pprint_context: Proof.context -> pprint_args -> unit
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    11
  val pprint_typ: theory -> typ -> pprint_args -> unit
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    12
  val pprint_term: theory -> term -> pprint_args -> unit
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    13
  val pprint_ctyp: ctyp -> pprint_args -> unit
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    14
  val pprint_cterm: cterm -> pprint_args -> unit
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    15
  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
    16
  val print_theorems_diff: theory -> theory -> unit
28092
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    17
  val print_theorems: theory -> unit
22335
6c4204df6863 pretty_full_theory: expose in signature.
aspinall
parents: 22095
diff changeset
    18
  val pretty_full_theory: bool -> theory -> Pretty.T
28092
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    19
  val print_theory: theory -> unit
20311
3666316adad6 moved debug option to proof_display.ML (again);
wenzelm
parents: 20253
diff changeset
    20
  val string_of_rule: Proof.context -> string -> thm -> string
27857
fdf43ffceae0 removed obsolete present_results;
wenzelm
parents: 27176
diff changeset
    21
  val print_results: bool -> Proof.context -> ((string * string) * (string * thm list) list) -> unit
fdf43ffceae0 removed obsolete present_results;
wenzelm
parents: 27176
diff changeset
    22
  val pretty_consts: Proof.context -> (string * typ -> bool) -> (string * typ) list -> Pretty.T
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    23
end
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    24
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    25
structure ProofDisplay: PROOF_DISPLAY =
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    26
struct
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    27
20235
3cbf73ed92f8 ProofContext.legacy_pretty_thm;
wenzelm
parents: 20211
diff changeset
    28
(* toplevel pretty printing *)
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    29
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    30
fun pprint_context ctxt = Pretty.pprint
20311
3666316adad6 moved debug option to proof_display.ML (again);
wenzelm
parents: 20253
diff changeset
    31
 (if ! ProofContext.debug then
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    32
    Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt))
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    33
  else Pretty.str "<context>");
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    34
26949
a9a1ebfb4d23 pprint: proper global context via Syntax.init_pretty_global;
wenzelm
parents: 26696
diff changeset
    35
fun pprint pretty thy = Pretty.pprint o Pretty.quote o pretty (Syntax.init_pretty_global thy);
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    36
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 22872
diff changeset
    37
val pprint_typ = pprint Syntax.pretty_typ;
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 22872
diff changeset
    38
val pprint_term = pprint Syntax.pretty_term;
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    39
fun pprint_ctyp cT = pprint_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT);
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    40
fun pprint_cterm ct = pprint_term (Thm.theory_of_cterm ct) (Thm.term_of ct);
22872
d7189dc8939c tuned ProofDisplay.pretty_full_theory;
wenzelm
parents: 22335
diff changeset
    41
val pprint_thm = Pretty.pprint o ProofContext.pretty_thm_legacy;
20211
c7f907f41f7c moved pprint functions to Isar/proof_display.ML;
wenzelm
parents: 19482
diff changeset
    42
19432
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    43
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    44
(* theorems and theory *)
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    45
27176
3735b80d06fc Facts.dest/export_static: content difference;
wenzelm
parents: 26949
diff changeset
    46
fun pretty_theorems_diff prev_thys thy =
19432
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    47
  let
27176
3735b80d06fc Facts.dest/export_static: content difference;
wenzelm
parents: 26949
diff changeset
    48
    val pretty_fact = ProofContext.pretty_fact (ProofContext.init thy);
28210
c164d1892553 more procise printing of fact names;
wenzelm
parents: 28092
diff changeset
    49
    val thmss = Facts.dest_static (map PureThy.facts_of prev_thys) (PureThy.facts_of thy);
c164d1892553 more procise printing of fact names;
wenzelm
parents: 28092
diff changeset
    50
  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
    51
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    52
fun print_theorems_diff prev_thy thy =
27176
3735b80d06fc Facts.dest/export_static: content difference;
wenzelm
parents: 26949
diff changeset
    53
  Pretty.writeln (pretty_theorems_diff [prev_thy] thy);
19432
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    54
27176
3735b80d06fc Facts.dest/export_static: content difference;
wenzelm
parents: 26949
diff changeset
    55
fun pretty_theorems thy = pretty_theorems_diff (Theory.parents_of thy) thy;
19432
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    56
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
    57
22872
d7189dc8939c tuned ProofDisplay.pretty_full_theory;
wenzelm
parents: 22335
diff changeset
    58
fun pretty_full_theory verbose thy =
d7189dc8939c tuned ProofDisplay.pretty_full_theory;
wenzelm
parents: 22335
diff changeset
    59
  Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]);
20621
29d57880ba00 'print_theory': bang option for full verbosity;
wenzelm
parents: 20311
diff changeset
    60
22872
d7189dc8939c tuned ProofDisplay.pretty_full_theory;
wenzelm
parents: 22335
diff changeset
    61
val print_theory = Pretty.writeln o pretty_full_theory false;
22335
6c4204df6863 pretty_full_theory: expose in signature.
aspinall
parents: 22095
diff changeset
    62
19432
cae7cc072994 added print_theorems/theory, print_theorems_diff (from pure_thy.ML);
wenzelm
parents: 18799
diff changeset
    63
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    64
(* refinement rule *)
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    65
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    66
fun pretty_rule ctxt s thm =
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    67
  Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    68
    Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    69
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    70
val string_of_rule = Pretty.string_of ooo pretty_rule;
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    71
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    72
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    73
(* results *)
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    74
28092
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    75
local
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    76
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
    77
fun pretty_fact_name (kind, "") = Pretty.str kind
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
    78
  | pretty_fact_name (kind, name) = Pretty.block [Pretty.str kind, Pretty.brk 1,
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
    79
      Pretty.str (NameSpace.base name), Pretty.str ":"];
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
    80
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    81
fun pretty_facts ctxt =
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19432
diff changeset
    82
  flat o (separate [Pretty.fbrk, Pretty.str "and "]) o
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    83
    map (single o ProofContext.pretty_fact ctxt);
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    84
27857
fdf43ffceae0 removed obsolete present_results;
wenzelm
parents: 27176
diff changeset
    85
in
fdf43ffceae0 removed obsolete present_results;
wenzelm
parents: 27176
diff changeset
    86
28092
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    87
fun print_results do_print ctxt ((kind, name), facts) =
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    88
  if not do_print orelse kind = "" orelse kind = Thm.internalK then ()
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    89
  else if name = "" then
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    90
    Pretty.writeln (Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts))
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    91
  else Pretty.writeln
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    92
    (case facts of
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    93
      [fact] => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    94
        ProofContext.pretty_fact ctxt fact])
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    95
    | _ => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
5886e9359aa8 no pervasive bindings;
wenzelm
parents: 28087
diff changeset
    96
        Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]));
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    97
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    98
end;
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
    99
20889
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   100
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   101
(* consts *)
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   102
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   103
local
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   104
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   105
fun pretty_var ctxt (x, T) =
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   106
  Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1,
24920
2a45e400fdad generic Syntax.pretty/string_of operations;
wenzelm
parents: 22872
diff changeset
   107
    Pretty.quote (Syntax.pretty_typ ctxt T)];
20889
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   108
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   109
fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs);
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   110
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   111
in
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   112
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   113
fun pretty_consts ctxt pred cs =
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   114
  (case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   115
    [] => pretty_vars ctxt "constants" cs
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   116
  | ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]);
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   117
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   118
end;
f625a65bfed5 added pretty_consts (from specification.ML);
wenzelm
parents: 20621
diff changeset
   119
17369
dec2ddbb3edf Printing of Isar proof elements etc.
wenzelm
parents:
diff changeset
   120
end;