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