src/Pure/Isar/proof_display.ML
author wenzelm
Tue Jul 21 01:03:18 2009 +0200 (2009-07-21)
changeset 32091 30e2ffbba718
parent 30724 2e54e89bcce7
child 32145 220c9e439d39
permissions -rw-r--r--
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm@17369
     1
(*  Title:      Pure/Isar/proof_display.ML
wenzelm@17369
     2
    Author:     Makarius
wenzelm@17369
     3
wenzelm@19432
     4
Printing of theorems, goals, results etc.
wenzelm@17369
     5
*)
wenzelm@17369
     6
wenzelm@17369
     7
signature PROOF_DISPLAY =
wenzelm@17369
     8
sig
wenzelm@30628
     9
  val pp_context: Proof.context -> Pretty.T
wenzelm@30628
    10
  val pp_thm: thm -> Pretty.T
wenzelm@30628
    11
  val pp_typ: theory -> typ -> Pretty.T
wenzelm@30628
    12
  val pp_term: theory -> term -> Pretty.T
wenzelm@30628
    13
  val pp_ctyp: ctyp -> Pretty.T
wenzelm@30628
    14
  val pp_cterm: cterm -> Pretty.T
wenzelm@19432
    15
  val print_theorems_diff: theory -> theory -> unit
wenzelm@28092
    16
  val print_theorems: theory -> unit
aspinall@22335
    17
  val pretty_full_theory: bool -> theory -> Pretty.T
wenzelm@28092
    18
  val print_theory: theory -> unit
wenzelm@20311
    19
  val string_of_rule: Proof.context -> string -> thm -> string
wenzelm@27857
    20
  val print_results: bool -> Proof.context -> ((string * string) * (string * thm list) list) -> unit
wenzelm@27857
    21
  val pretty_consts: Proof.context -> (string * typ -> bool) -> (string * typ) list -> Pretty.T
wenzelm@17369
    22
end
wenzelm@17369
    23
wenzelm@17369
    24
structure ProofDisplay: PROOF_DISPLAY =
wenzelm@17369
    25
struct
wenzelm@17369
    26
wenzelm@20235
    27
(* toplevel pretty printing *)
wenzelm@20211
    28
wenzelm@30628
    29
fun pp_context ctxt =
wenzelm@20311
    30
 (if ! ProofContext.debug then
wenzelm@20211
    31
    Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt))
wenzelm@20211
    32
  else Pretty.str "<context>");
wenzelm@20211
    33
wenzelm@30628
    34
fun pp_thm th =
wenzelm@30724
    35
  let
wenzelm@30724
    36
    val thy = Thm.theory_of_thm th;
wenzelm@30724
    37
    val flags = {quote = true, show_hyps = false, show_status = true};
wenzelm@32091
    38
  in Display.pretty_thm_raw (Syntax.pp_global thy) flags [] th end;
wenzelm@20211
    39
wenzelm@30628
    40
val pp_typ = Pretty.quote oo Syntax.pretty_typ_global;
wenzelm@30628
    41
val pp_term = Pretty.quote oo Syntax.pretty_term_global;
wenzelm@30628
    42
wenzelm@30628
    43
fun pp_ctyp cT = pp_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT);
wenzelm@30628
    44
fun pp_cterm ct = pp_term (Thm.theory_of_cterm ct) (Thm.term_of ct);
wenzelm@20211
    45
wenzelm@19432
    46
wenzelm@19432
    47
(* theorems and theory *)
wenzelm@19432
    48
wenzelm@27176
    49
fun pretty_theorems_diff prev_thys thy =
wenzelm@19432
    50
  let
wenzelm@27176
    51
    val pretty_fact = ProofContext.pretty_fact (ProofContext.init thy);
wenzelm@28210
    52
    val thmss = Facts.dest_static (map PureThy.facts_of prev_thys) (PureThy.facts_of thy);
wenzelm@28210
    53
  in Pretty.big_list "theorems:" (map #1 (sort_wrt (#1 o #2) (map (`pretty_fact) thmss))) end;
wenzelm@19432
    54
wenzelm@19432
    55
fun print_theorems_diff prev_thy thy =
wenzelm@27176
    56
  Pretty.writeln (pretty_theorems_diff [prev_thy] thy);
wenzelm@19432
    57
wenzelm@27176
    58
fun pretty_theorems thy = pretty_theorems_diff (Theory.parents_of thy) thy;
wenzelm@19432
    59
val print_theorems = Pretty.writeln o pretty_theorems;
wenzelm@19432
    60
wenzelm@22872
    61
fun pretty_full_theory verbose thy =
wenzelm@22872
    62
  Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]);
wenzelm@20621
    63
wenzelm@22872
    64
val print_theory = Pretty.writeln o pretty_full_theory false;
aspinall@22335
    65
wenzelm@19432
    66
wenzelm@17369
    67
(* refinement rule *)
wenzelm@17369
    68
wenzelm@17369
    69
fun pretty_rule ctxt s thm =
wenzelm@17369
    70
  Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
wenzelm@32091
    71
    Pretty.fbrk, Display.pretty_thm_aux ctxt false thm];
wenzelm@17369
    72
wenzelm@17369
    73
val string_of_rule = Pretty.string_of ooo pretty_rule;
wenzelm@17369
    74
wenzelm@17369
    75
wenzelm@17369
    76
(* results *)
wenzelm@17369
    77
wenzelm@28092
    78
local
wenzelm@28092
    79
wenzelm@28087
    80
fun pretty_fact_name (kind, "") = Pretty.str kind
wenzelm@28087
    81
  | pretty_fact_name (kind, name) = Pretty.block [Pretty.str kind, Pretty.brk 1,
wenzelm@30364
    82
      Pretty.str (Long_Name.base_name name), Pretty.str ":"];
wenzelm@28087
    83
wenzelm@17369
    84
fun pretty_facts ctxt =
wenzelm@19482
    85
  flat o (separate [Pretty.fbrk, Pretty.str "and "]) o
wenzelm@30724
    86
    map (single o ProofContext.pretty_fact_aux ctxt false);
wenzelm@17369
    87
wenzelm@27857
    88
in
wenzelm@27857
    89
wenzelm@28092
    90
fun print_results do_print ctxt ((kind, name), facts) =
wenzelm@28092
    91
  if not do_print orelse kind = "" orelse kind = Thm.internalK then ()
wenzelm@28092
    92
  else if name = "" then
wenzelm@28092
    93
    Pretty.writeln (Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts))
wenzelm@28092
    94
  else Pretty.writeln
wenzelm@28092
    95
    (case facts of
wenzelm@28092
    96
      [fact] => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
wenzelm@30724
    97
        ProofContext.pretty_fact_aux ctxt false fact])
wenzelm@28092
    98
    | _ => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
wenzelm@28092
    99
        Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]));
wenzelm@17369
   100
wenzelm@17369
   101
end;
wenzelm@17369
   102
wenzelm@20889
   103
wenzelm@20889
   104
(* consts *)
wenzelm@20889
   105
wenzelm@20889
   106
local
wenzelm@20889
   107
wenzelm@20889
   108
fun pretty_var ctxt (x, T) =
wenzelm@20889
   109
  Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1,
wenzelm@24920
   110
    Pretty.quote (Syntax.pretty_typ ctxt T)];
wenzelm@20889
   111
wenzelm@20889
   112
fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs);
wenzelm@20889
   113
wenzelm@20889
   114
in
wenzelm@20889
   115
wenzelm@20889
   116
fun pretty_consts ctxt pred cs =
wenzelm@20889
   117
  (case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of
wenzelm@20889
   118
    [] => pretty_vars ctxt "constants" cs
wenzelm@20889
   119
  | ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]);
wenzelm@20889
   120
wenzelm@20889
   121
end;
wenzelm@20889
   122
wenzelm@17369
   123
end;