src/Pure/Isar/proof_display.ML
author wenzelm
Thu Mar 05 12:08:00 2009 +0100 (2009-03-05)
changeset 30280 eb98b49ef835
parent 29606 fedb8be05f24
child 30364 577edc39b501
permissions -rw-r--r--
renamed NameSpace.base to NameSpace.base_name;
renamed NameSpace.map_base to NameSpace.map_base_name;
eliminated alias Sign.base_name = NameSpace.base_name;
     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 pprint_context: Proof.context -> pprint_args -> unit
    10   val pprint_typ: theory -> typ -> pprint_args -> unit
    11   val pprint_term: theory -> term -> pprint_args -> unit
    12   val pprint_ctyp: ctyp -> pprint_args -> unit
    13   val pprint_cterm: cterm -> pprint_args -> unit
    14   val pprint_thm: thm -> pprint_args -> unit
    15   val print_theorems_diff: theory -> theory -> unit
    16   val print_theorems: 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 ProofDisplay: PROOF_DISPLAY =
    25 struct
    26 
    27 (* toplevel pretty printing *)
    28 
    29 fun pprint_context ctxt = Pretty.pprint
    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 pprint pretty thy = Pretty.pprint o Pretty.quote o pretty (Syntax.init_pretty_global thy);
    35 
    36 val pprint_typ = pprint Syntax.pretty_typ;
    37 val pprint_term = pprint Syntax.pretty_term;
    38 fun pprint_ctyp cT = pprint_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT);
    39 fun pprint_cterm ct = pprint_term (Thm.theory_of_cterm ct) (Thm.term_of ct);
    40 val pprint_thm = Pretty.pprint o ProofContext.pretty_thm_legacy;
    41 
    42 
    43 (* theorems and theory *)
    44 
    45 fun pretty_theorems_diff prev_thys thy =
    46   let
    47     val pretty_fact = ProofContext.pretty_fact (ProofContext.init thy);
    48     val thmss = Facts.dest_static (map PureThy.facts_of prev_thys) (PureThy.facts_of thy);
    49   in Pretty.big_list "theorems:" (map #1 (sort_wrt (#1 o #2) (map (`pretty_fact) thmss))) end;
    50 
    51 fun print_theorems_diff prev_thy thy =
    52   Pretty.writeln (pretty_theorems_diff [prev_thy] thy);
    53 
    54 fun pretty_theorems thy = pretty_theorems_diff (Theory.parents_of thy) thy;
    55 val print_theorems = Pretty.writeln o pretty_theorems;
    56 
    57 fun pretty_full_theory verbose thy =
    58   Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]);
    59 
    60 val print_theory = Pretty.writeln o pretty_full_theory false;
    61 
    62 
    63 (* refinement rule *)
    64 
    65 fun pretty_rule ctxt s thm =
    66   Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
    67     Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
    68 
    69 val string_of_rule = Pretty.string_of ooo pretty_rule;
    70 
    71 
    72 (* results *)
    73 
    74 local
    75 
    76 fun pretty_fact_name (kind, "") = Pretty.str kind
    77   | pretty_fact_name (kind, name) = Pretty.block [Pretty.str kind, Pretty.brk 1,
    78       Pretty.str (NameSpace.base_name name), Pretty.str ":"];
    79 
    80 fun pretty_facts ctxt =
    81   flat o (separate [Pretty.fbrk, Pretty.str "and "]) o
    82     map (single o ProofContext.pretty_fact ctxt);
    83 
    84 in
    85 
    86 fun print_results do_print ctxt ((kind, name), facts) =
    87   if not do_print orelse kind = "" orelse kind = Thm.internalK then ()
    88   else if name = "" then
    89     Pretty.writeln (Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts))
    90   else Pretty.writeln
    91     (case facts of
    92       [fact] => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
    93         ProofContext.pretty_fact ctxt fact])
    94     | _ => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
    95         Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]));
    96 
    97 end;
    98 
    99 
   100 (* consts *)
   101 
   102 local
   103 
   104 fun pretty_var ctxt (x, T) =
   105   Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1,
   106     Pretty.quote (Syntax.pretty_typ ctxt T)];
   107 
   108 fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs);
   109 
   110 in
   111 
   112 fun pretty_consts ctxt pred cs =
   113   (case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of
   114     [] => pretty_vars ctxt "constants" cs
   115   | ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]);
   116 
   117 end;
   118 
   119 end;