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