src/Pure/display.ML
author wenzelm
Sat Dec 23 22:52:41 2000 +0100 (2000-12-23)
changeset 10737 c130eb1e863f
parent 10010 f6ccb6df9cb9
child 11501 3b6415035d1a
permissions -rw-r--r--
tuned output;
paulson@1591
     1
(*  Title:      Pure/display.ML
paulson@1591
     2
    ID:         $Id$
paulson@1591
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1591
     4
    Copyright   1993  University of Cambridge
paulson@1591
     5
paulson@1591
     6
Printing of theories, theorems, etc.
paulson@1591
     7
*)
paulson@1591
     8
paulson@1591
     9
signature DISPLAY =
wenzelm@4950
    10
sig
wenzelm@4950
    11
  val show_hyps		: bool ref
wenzelm@6087
    12
  val show_tags		: bool ref
wenzelm@6976
    13
  val pretty_thm_no_quote: thm -> Pretty.T
wenzelm@6926
    14
  val pretty_thm	: thm -> Pretty.T
wenzelm@6087
    15
  val pretty_thms	: thm list -> Pretty.T
wenzelm@10010
    16
  val pretty_thm_sg     : Sign.sg -> thm -> Pretty.T
wenzelm@10010
    17
  val pretty_thms_sg    : Sign.sg -> thm list -> Pretty.T
wenzelm@4950
    18
  val string_of_thm	: thm -> string
wenzelm@4950
    19
  val pprint_thm	: thm -> pprint_args -> unit
paulson@1591
    20
  val print_thm		: thm -> unit
wenzelm@6087
    21
  val print_thms	: thm list -> unit
paulson@1591
    22
  val prth		: thm -> thm
wenzelm@4270
    23
  val prthq		: thm Seq.seq -> thm Seq.seq
paulson@1591
    24
  val prths		: thm list -> thm list
wenzelm@4950
    25
  val pretty_ctyp	: ctyp -> Pretty.T
wenzelm@4950
    26
  val pprint_ctyp	: ctyp -> pprint_args -> unit
paulson@1591
    27
  val string_of_ctyp	: ctyp -> string
wenzelm@4950
    28
  val print_ctyp	: ctyp -> unit
wenzelm@4950
    29
  val pretty_cterm	: cterm -> Pretty.T
wenzelm@4950
    30
  val pprint_cterm	: cterm -> pprint_args -> unit
wenzelm@4950
    31
  val string_of_cterm	: cterm -> string
wenzelm@4950
    32
  val print_cterm	: cterm -> unit
wenzelm@4950
    33
  val pretty_theory	: theory -> Pretty.T
wenzelm@4950
    34
  val pprint_theory	: theory -> pprint_args -> unit
wenzelm@4950
    35
  val print_syntax	: theory -> unit
wenzelm@8720
    36
  val pretty_full_theory: theory -> Pretty.T list
wenzelm@4950
    37
  val pretty_name_space : string * NameSpace.T -> Pretty.T
wenzelm@4950
    38
  val show_consts	: bool ref
wenzelm@4950
    39
end;
paulson@1591
    40
wenzelm@4950
    41
structure Display: DISPLAY =
paulson@1591
    42
struct
paulson@1591
    43
wenzelm@6087
    44
(** print thm **)
wenzelm@6087
    45
wenzelm@6087
    46
val show_hyps = ref true;	(*false: print meta-hypotheses as dots*)
wenzelm@6087
    47
val show_tags = ref false;	(*false: suppress tags*)
wenzelm@6087
    48
wenzelm@6889
    49
local
wenzelm@6889
    50
wenzelm@8402
    51
fun pretty_tag (name, args) = Pretty.strs (name :: map quote args);
wenzelm@6087
    52
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
paulson@1591
    53
wenzelm@6314
    54
fun pretty_thm_aux quote th =
paulson@1591
    55
  let
wenzelm@9500
    56
    val {sign, hyps, prop, der = (ora, _), ...} = rep_thm th;
wenzelm@6087
    57
    val xshyps = Thm.extra_shyps th;
wenzelm@6087
    58
    val (_, tags) = Thm.get_name_tags th;
wenzelm@6087
    59
wenzelm@6314
    60
    val prt_term = (if quote then Pretty.quote else I) o Sign.pretty_term sign;
wenzelm@6279
    61
paulson@1591
    62
    val hlen = length xshyps + length hyps;
paulson@1591
    63
    val hsymbs =
wenzelm@9500
    64
      if hlen = 0 andalso not ora then []
paulson@1591
    65
      else if ! show_hyps then
paulson@1591
    66
        [Pretty.brk 2, Pretty.list "[" "]"
wenzelm@6889
    67
          (map prt_term hyps @ map (Sign.pretty_sort sign) xshyps @
wenzelm@9500
    68
            (if ora then [Pretty.str "!"] else []))]
wenzelm@6889
    69
      else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^
wenzelm@9500
    70
        (if ora then "!" else "") ^ "]")];
wenzelm@6087
    71
    val tsymbs =
wenzelm@6087
    72
      if null tags orelse not (! show_tags) then []
wenzelm@6087
    73
      else [Pretty.brk 1, pretty_tags tags];
wenzelm@6279
    74
  in Pretty.block (prt_term prop :: (hsymbs @ tsymbs)) end;
paulson@1591
    75
wenzelm@6889
    76
in
wenzelm@6889
    77
wenzelm@6926
    78
val pretty_thm = pretty_thm_aux true;
wenzelm@6314
    79
val pretty_thm_no_quote = pretty_thm_aux false;
wenzelm@6314
    80
wenzelm@6889
    81
end;
wenzelm@6889
    82
wenzelm@6889
    83
paulson@1591
    84
val string_of_thm = Pretty.string_of o pretty_thm;
wenzelm@6279
    85
val pprint_thm = Pretty.pprint o pretty_thm;
paulson@1591
    86
wenzelm@6087
    87
fun pretty_thms [th] = pretty_thm th
wenzelm@6087
    88
  | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths));
paulson@1591
    89
wenzelm@10010
    90
val pretty_thm_sg = pretty_thm oo Thm.transfer_sg;
wenzelm@10010
    91
val pretty_thms_sg = pretty_thms oo (map o Thm.transfer_sg);
wenzelm@10010
    92
wenzelm@6087
    93
wenzelm@6087
    94
(* top-level commands for printing theorems *)
wenzelm@6087
    95
wenzelm@6087
    96
val print_thm = Pretty.writeln o pretty_thm;
wenzelm@6087
    97
val print_thms = Pretty.writeln o pretty_thms;
paulson@1591
    98
paulson@1591
    99
fun prth th = (print_thm th; th);
paulson@1591
   100
paulson@1591
   101
(*Print and return a sequence of theorems, separated by blank lines. *)
paulson@1591
   102
fun prthq thseq =
wenzelm@4270
   103
  (Seq.print (fn _ => print_thm) 100000 thseq; thseq);
paulson@1591
   104
paulson@1591
   105
(*Print and return a list of theorems, separated by blank lines. *)
wenzelm@4210
   106
fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths);
paulson@1591
   107
paulson@1591
   108
paulson@1591
   109
(* other printing commands *)
paulson@1591
   110
wenzelm@4126
   111
fun pretty_ctyp cT =
wenzelm@4126
   112
  let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end;
wenzelm@4126
   113
paulson@1591
   114
fun pprint_ctyp cT =
paulson@1591
   115
  let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end;
paulson@1591
   116
paulson@1591
   117
fun string_of_ctyp cT =
paulson@1591
   118
  let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end;
paulson@1591
   119
paulson@1591
   120
val print_ctyp = writeln o string_of_ctyp;
paulson@1591
   121
wenzelm@3547
   122
fun pretty_cterm ct =
wenzelm@3547
   123
  let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end;
wenzelm@3547
   124
paulson@1591
   125
fun pprint_cterm ct =
paulson@1591
   126
  let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end;
paulson@1591
   127
paulson@1591
   128
fun string_of_cterm ct =
paulson@1591
   129
  let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end;
paulson@1591
   130
paulson@1591
   131
val print_cterm = writeln o string_of_cterm;
paulson@1591
   132
paulson@1591
   133
wenzelm@4250
   134
wenzelm@4250
   135
(** print theory **)
paulson@1591
   136
wenzelm@6390
   137
val pretty_theory = Sign.pretty_sg o Theory.sign_of;
wenzelm@6390
   138
val pprint_theory = Sign.pprint_sg o Theory.sign_of;
paulson@1591
   139
wenzelm@6390
   140
val print_syntax = Syntax.print_syntax o Theory.syn_of;
paulson@1591
   141
wenzelm@4250
   142
wenzelm@4498
   143
(* pretty_name_space  *)
wenzelm@4498
   144
wenzelm@4498
   145
fun pretty_name_space (kind, space) =
wenzelm@4498
   146
  let
wenzelm@4498
   147
    fun prt_entry (name, accs) = Pretty.block
wenzelm@4498
   148
      (Pretty.str (quote name ^ " =") :: Pretty.brk 1 ::
wenzelm@4498
   149
        Pretty.commas (map (Pretty.str o quote) accs));
wenzelm@4498
   150
  in
wenzelm@4498
   151
    Pretty.fbreaks (Pretty.str (kind ^ ":") :: map prt_entry (NameSpace.dest space))
wenzelm@4498
   152
    |> Pretty.block
wenzelm@4498
   153
  end;
wenzelm@4498
   154
wenzelm@4498
   155
wenzelm@4498
   156
wenzelm@8720
   157
(* print theory *)
wenzelm@4250
   158
wenzelm@8720
   159
fun pretty_full_theory thy =
wenzelm@4250
   160
  let
wenzelm@8720
   161
    val sg = Theory.sign_of thy;
wenzelm@8720
   162
wenzelm@4250
   163
    fun prt_cls c = Sign.pretty_sort sg [c];
wenzelm@4250
   164
    fun prt_sort S = Sign.pretty_sort sg S;
wenzelm@4250
   165
    fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]);
wenzelm@10737
   166
    fun prt_typ_no_tvars ty = Pretty.quote (Sign.pretty_typ sg (#1 (Type.freeze_thaw_type ty)));
wenzelm@8720
   167
    fun prt_term t = Pretty.quote (Sign.pretty_term sg t);
wenzelm@4250
   168
wenzelm@4250
   169
    fun pretty_classes cs = Pretty.block
wenzelm@4250
   170
      (Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs));
wenzelm@4250
   171
wenzelm@4250
   172
    fun pretty_classrel (c, cs) = Pretty.block
wenzelm@4250
   173
      (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 ::
wenzelm@4250
   174
        Pretty.commas (map prt_cls cs));
wenzelm@4250
   175
wenzelm@4250
   176
    fun pretty_default S = Pretty.block
wenzelm@4250
   177
      [Pretty.str "default:", Pretty.brk 1, prt_sort S];
wenzelm@4250
   178
wenzelm@4250
   179
    fun pretty_ty (t, n) = Pretty.block
wenzelm@8458
   180
      [Pretty.str t, Pretty.brk 1, Pretty.str (string_of_int n)];
wenzelm@4250
   181
wenzelm@7635
   182
    fun pretty_log_types ts = Pretty.block
wenzelm@7635
   183
      (Pretty.breaks (Pretty.str "logical types:" :: map Pretty.str ts));
wenzelm@7635
   184
wenzelm@7635
   185
    fun pretty_witness None = Pretty.str "universal non-emptiness witness: --"
wenzelm@7635
   186
      | pretty_witness (Some (T, S)) = Pretty.block
wenzelm@10737
   187
          [Pretty.str "universal non-emptiness witness:", Pretty.brk 1, prt_typ_no_tvars T,
wenzelm@8402
   188
            Pretty.brk 1, prt_sort S];
wenzelm@7635
   189
wenzelm@4250
   190
    fun pretty_abbr (t, (vs, rhs)) = Pretty.block
wenzelm@10737
   191
      [prt_typ_no_tvars (Type (t, map (fn v => TVar ((v, 0), [])) vs)),
wenzelm@10737
   192
        Pretty.str " =", Pretty.brk 1, prt_typ_no_tvars rhs];
wenzelm@4250
   193
wenzelm@4250
   194
    fun pretty_arities (t, ars) = map (prt_arity t) ars;
wenzelm@4250
   195
wenzelm@4250
   196
    fun pretty_const (c, ty) = Pretty.block
wenzelm@10737
   197
      [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ_no_tvars ty];
wenzelm@4250
   198
wenzelm@8720
   199
    fun prt_axm (a, t) = Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, prt_term t];
wenzelm@8720
   200
wenzelm@8720
   201
wenzelm@4250
   202
    val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg;
wenzelm@8720
   203
    val {axioms, oracles, ...} = Theory.rep_theory thy;
wenzelm@6846
   204
    val spaces' = Library.sort_wrt fst spaces;
wenzelm@7635
   205
    val {classes, classrel, default, tycons = type_tab, log_types, univ_witness, abbrs, arities} =
wenzelm@4250
   206
      Type.rep_tsig tsig;
wenzelm@7067
   207
    val tycons = Sign.cond_extern_table sg Sign.typeK type_tab;
wenzelm@6846
   208
    val consts = Sign.cond_extern_table sg Sign.constK const_tab;
wenzelm@8720
   209
    val axms = Sign.cond_extern_table sg Theory.axiomK axioms;
wenzelm@8720
   210
    val oras = Sign.cond_extern_table sg Theory.oracleK oracles;
wenzelm@4250
   211
  in
wenzelm@8720
   212
    [Pretty.strs ("stamps:" :: Sign.stamp_names_of sg),
wenzelm@8720
   213
      Pretty.strs ("data:" :: Sign.data_kinds data),
wenzelm@8720
   214
      Pretty.strs ["name prefix:", NameSpace.pack path],
wenzelm@8720
   215
      Pretty.big_list "name spaces:" (map pretty_name_space spaces'),
wenzelm@8720
   216
      pretty_classes classes,
wenzelm@8720
   217
      Pretty.big_list "class relation:" (map pretty_classrel (Symtab.dest classrel)),
wenzelm@8720
   218
      pretty_default default,
wenzelm@8720
   219
      pretty_log_types log_types,
wenzelm@8720
   220
      pretty_witness univ_witness,
wenzelm@8720
   221
      Pretty.big_list "type constructors:" (map pretty_ty tycons),
wenzelm@8720
   222
      Pretty.big_list "type abbreviations:" (map pretty_abbr (Symtab.dest abbrs)),
wenzelm@8720
   223
      Pretty.big_list "type arities:" (flat (map pretty_arities (Symtab.dest arities))),
wenzelm@8720
   224
      Pretty.big_list "consts:" (map pretty_const consts),
wenzelm@8720
   225
      Pretty.big_list "axioms:" (map prt_axm axms),
wenzelm@8720
   226
      Pretty.strs ("oracles:" :: (map #1 oras))]
wenzelm@4250
   227
  end;
wenzelm@4250
   228
wenzelm@4250
   229
wenzelm@8908
   230
(*show consts with types in proof state output?*)
wenzelm@3851
   231
val show_consts = ref false;
wenzelm@3851
   232
paulson@1591
   233
paulson@1591
   234
end;
paulson@1591
   235
paulson@1591
   236
open Display;