src/Pure/display.ML
author wenzelm
Mon May 22 22:29:16 2006 +0200 (2006-05-22)
changeset 19698 f48cfaacd92c
parent 19642 ea7162f84677
child 19702 2ab12e94156f
permissions -rw-r--r--
pretty_full_theory: defs;
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
wenzelm@19420
     6
Printing of theorems, goals, results etc.
paulson@1591
     7
*)
paulson@1591
     8
wenzelm@11883
     9
signature BASIC_DISPLAY =
wenzelm@11883
    10
sig
wenzelm@12081
    11
  val goals_limit: int ref
wenzelm@11883
    12
  val show_hyps: bool ref
wenzelm@11883
    13
  val show_tags: bool ref
wenzelm@11883
    14
  val string_of_thm: thm -> string
wenzelm@11883
    15
  val print_thm: thm -> unit
wenzelm@11883
    16
  val print_thms: thm list -> unit
wenzelm@11883
    17
  val prth: thm -> thm
wenzelm@11883
    18
  val prthq: thm Seq.seq -> thm Seq.seq
wenzelm@11883
    19
  val prths: thm list -> thm list
wenzelm@11883
    20
  val string_of_ctyp: ctyp -> string
wenzelm@11883
    21
  val print_ctyp: ctyp -> unit
wenzelm@11883
    22
  val string_of_cterm: cterm -> string
wenzelm@11883
    23
  val print_cterm: cterm -> unit
wenzelm@11883
    24
  val print_syntax: theory -> unit
wenzelm@11883
    25
  val show_consts: bool ref
wenzelm@11883
    26
end;
wenzelm@11883
    27
paulson@1591
    28
signature DISPLAY =
wenzelm@4950
    29
sig
wenzelm@11883
    30
  include BASIC_DISPLAY
wenzelm@19591
    31
  val raw_string_of_sort: sort -> string
wenzelm@19591
    32
  val raw_string_of_typ: typ -> string
wenzelm@19591
    33
  val raw_string_of_term: term -> string
wenzelm@14876
    34
  val pretty_flexpair: Pretty.pp -> term * term -> Pretty.T
wenzelm@17447
    35
  val pretty_thm_aux: Pretty.pp -> bool -> bool -> term list -> thm -> Pretty.T
wenzelm@6976
    36
  val pretty_thm_no_quote: thm -> Pretty.T
wenzelm@11883
    37
  val pretty_thm: thm -> Pretty.T
wenzelm@11883
    38
  val pretty_thms: thm list -> Pretty.T
wenzelm@16437
    39
  val pretty_thm_sg: theory -> thm -> Pretty.T
wenzelm@16437
    40
  val pretty_thms_sg: theory -> thm list -> Pretty.T
wenzelm@11883
    41
  val pprint_thm: thm -> pprint_args -> unit
wenzelm@11883
    42
  val pretty_ctyp: ctyp -> Pretty.T
wenzelm@11883
    43
  val pprint_ctyp: ctyp -> pprint_args -> unit
wenzelm@11883
    44
  val pretty_cterm: cterm -> Pretty.T
wenzelm@11883
    45
  val pprint_cterm: cterm -> pprint_args -> unit
wenzelm@8720
    46
  val pretty_full_theory: theory -> Pretty.T list
wenzelm@14876
    47
  val pretty_goals_aux: Pretty.pp -> string -> bool * bool -> int -> thm -> Pretty.T list
wenzelm@11883
    48
  val pretty_goals: int -> thm -> Pretty.T list
wenzelm@11883
    49
  val print_goals: int -> thm -> unit
wenzelm@11883
    50
  val current_goals_markers: (string * string * string) ref
wenzelm@12418
    51
  val pretty_current_goals: int -> int -> thm -> Pretty.T list
wenzelm@12418
    52
  val print_current_goals_default: int -> int -> thm -> unit
wenzelm@12418
    53
  val print_current_goals_fn: (int -> int -> thm -> unit) ref
wenzelm@4950
    54
end;
paulson@1591
    55
wenzelm@4950
    56
structure Display: DISPLAY =
paulson@1591
    57
struct
paulson@1591
    58
wenzelm@19591
    59
(** raw output **)
wenzelm@19591
    60
wenzelm@19591
    61
val raw_string_of_sort = Sign.string_of_sort ProtoPure.thy;
wenzelm@19591
    62
val raw_string_of_typ = Sign.string_of_typ ProtoPure.thy;
wenzelm@19591
    63
val raw_string_of_term = Sign.string_of_term ProtoPure.thy;
wenzelm@19591
    64
wenzelm@19591
    65
wenzelm@11883
    66
wenzelm@6087
    67
(** print thm **)
wenzelm@6087
    68
wenzelm@16534
    69
val goals_limit = ref 10;       (*max number of goals to print*)
wenzelm@12831
    70
val show_hyps = ref false;      (*false: print meta-hypotheses as dots*)
wenzelm@11883
    71
val show_tags = ref false;      (*false: suppress tags*)
wenzelm@6087
    72
berghofe@14598
    73
fun pretty_tag (name, args) = Pretty.strs (name :: map Library.quote args);
wenzelm@6087
    74
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
paulson@1591
    75
wenzelm@14876
    76
fun pretty_flexpair pp (t, u) = Pretty.block
wenzelm@14876
    77
  [Pretty.term pp t, Pretty.str " =?=", Pretty.brk 1, Pretty.term pp u];
berghofe@13658
    78
wenzelm@17447
    79
fun pretty_thm_aux pp quote show_hyps' asms raw_th =
paulson@1591
    80
  let
wenzelm@17447
    81
    val th = Thm.strip_shyps raw_th;
wenzelm@16290
    82
    val {hyps, tpairs, prop, der = (ora, _), ...} = Thm.rep_thm th;
wenzelm@6087
    83
    val xshyps = Thm.extra_shyps th;
wenzelm@6087
    84
    val (_, tags) = Thm.get_name_tags th;
wenzelm@6087
    85
berghofe@13658
    86
    val q = if quote then Pretty.quote else I;
wenzelm@14876
    87
    val prt_term = q o (Pretty.term pp);
wenzelm@6279
    88
wenzelm@19300
    89
    val hyps' = if ! show_hyps then hyps else subtract (op aconv) asms hyps;
wenzelm@17475
    90
    val ora' = ora andalso (! show_hyps orelse not (! quick_and_dirty));
wenzelm@17447
    91
    val hlen = length xshyps + length hyps' + length tpairs;
paulson@1591
    92
    val hsymbs =
wenzelm@17475
    93
      if hlen = 0 andalso not ora' then []
wenzelm@17447
    94
      else if ! show_hyps orelse show_hyps' then
paulson@1591
    95
        [Pretty.brk 2, Pretty.list "[" "]"
wenzelm@17447
    96
          (map (q o pretty_flexpair pp) tpairs @ map prt_term hyps' @
wenzelm@14876
    97
           map (Pretty.sort pp) xshyps @
wenzelm@17475
    98
            (if ora' then [Pretty.str "!"] else []))]
wenzelm@6889
    99
      else [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^
wenzelm@17475
   100
        (if ora' then "!" else "") ^ "]")];
wenzelm@6087
   101
    val tsymbs =
wenzelm@6087
   102
      if null tags orelse not (! show_tags) then []
wenzelm@6087
   103
      else [Pretty.brk 1, pretty_tags tags];
wenzelm@6279
   104
  in Pretty.block (prt_term prop :: (hsymbs @ tsymbs)) end;
paulson@1591
   105
wenzelm@12067
   106
fun gen_pretty_thm quote th =
wenzelm@17447
   107
  pretty_thm_aux (Sign.pp (Thm.theory_of_thm th)) quote false [] th;
wenzelm@6889
   108
wenzelm@12067
   109
val pretty_thm = gen_pretty_thm true;
wenzelm@12067
   110
val pretty_thm_no_quote = gen_pretty_thm false;
wenzelm@6889
   111
wenzelm@6889
   112
paulson@1591
   113
val string_of_thm = Pretty.string_of o pretty_thm;
wenzelm@6279
   114
val pprint_thm = Pretty.pprint o pretty_thm;
paulson@1591
   115
wenzelm@6087
   116
fun pretty_thms [th] = pretty_thm th
wenzelm@6087
   117
  | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths));
paulson@1591
   118
wenzelm@16437
   119
val pretty_thm_sg = pretty_thm oo Thm.transfer;
wenzelm@16437
   120
val pretty_thms_sg = pretty_thms oo (map o Thm.transfer);
wenzelm@10010
   121
wenzelm@6087
   122
wenzelm@6087
   123
(* top-level commands for printing theorems *)
wenzelm@6087
   124
wenzelm@6087
   125
val print_thm = Pretty.writeln o pretty_thm;
wenzelm@6087
   126
val print_thms = Pretty.writeln o pretty_thms;
paulson@1591
   127
paulson@1591
   128
fun prth th = (print_thm th; th);
wenzelm@16534
   129
fun prthq thq = (Seq.print (K print_thm) 100000 thq; thq);
wenzelm@16534
   130
fun prths ths = (prthq (Seq.of_list ths); ths);
paulson@1591
   131
paulson@1591
   132
paulson@1591
   133
(* other printing commands *)
paulson@1591
   134
wenzelm@4126
   135
fun pretty_ctyp cT =
wenzelm@16437
   136
  let val {thy, T, ...} = rep_ctyp cT in Sign.pretty_typ thy T end;
wenzelm@4126
   137
paulson@1591
   138
fun pprint_ctyp cT =
wenzelm@16437
   139
  let val {thy, T, ...} = rep_ctyp cT in Sign.pprint_typ thy T end;
paulson@1591
   140
paulson@1591
   141
fun string_of_ctyp cT =
wenzelm@16437
   142
  let val {thy, T, ...} = rep_ctyp cT in Sign.string_of_typ thy T end;
paulson@1591
   143
paulson@1591
   144
val print_ctyp = writeln o string_of_ctyp;
paulson@1591
   145
wenzelm@3547
   146
fun pretty_cterm ct =
wenzelm@16437
   147
  let val {thy, t, ...} = rep_cterm ct in Sign.pretty_term thy t end;
wenzelm@3547
   148
paulson@1591
   149
fun pprint_cterm ct =
wenzelm@16437
   150
  let val {thy, t, ...} = rep_cterm ct in Sign.pprint_term thy t end;
paulson@1591
   151
paulson@1591
   152
fun string_of_cterm ct =
wenzelm@16437
   153
  let val {thy, t, ...} = rep_cterm ct in Sign.string_of_term thy t end;
paulson@1591
   154
paulson@1591
   155
val print_cterm = writeln o string_of_cterm;
paulson@1591
   156
paulson@1591
   157
wenzelm@4250
   158
wenzelm@4250
   159
(** print theory **)
paulson@1591
   160
wenzelm@16437
   161
val print_syntax = Syntax.print_syntax o Sign.syn_of;
wenzelm@4498
   162
wenzelm@4498
   163
wenzelm@11883
   164
(* pretty_full_theory *)
wenzelm@4250
   165
wenzelm@8720
   166
fun pretty_full_theory thy =
wenzelm@4250
   167
  let
wenzelm@16437
   168
    fun prt_cls c = Sign.pretty_sort thy [c];
wenzelm@16437
   169
    fun prt_sort S = Sign.pretty_sort thy S;
wenzelm@19521
   170
    fun prt_arity t (c, (_, Ss)) = Sign.pretty_arity thy (t, Ss, [c]);
wenzelm@16437
   171
    fun prt_typ ty = Pretty.quote (Sign.pretty_typ thy ty);
wenzelm@16290
   172
    val prt_typ_no_tvars = prt_typ o Type.freeze_type;
wenzelm@16437
   173
    fun prt_term t = Pretty.quote (Sign.pretty_term thy t);
wenzelm@18936
   174
    val prt_term_no_vars = prt_term o Logic.unvarify;
wenzelm@19698
   175
    fun prt_const (c, ty) = [Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ_no_tvars ty];
wenzelm@19698
   176
    val prt_const' = Defs.pretty_const (Sign.pp thy);
wenzelm@4250
   177
wenzelm@14794
   178
    fun pretty_classrel (c, []) = prt_cls c
wenzelm@14794
   179
      | pretty_classrel (c, cs) = Pretty.block
wenzelm@14794
   180
          (prt_cls c :: Pretty.str " <" :: Pretty.brk 1 ::
wenzelm@14794
   181
            Pretty.commas (map prt_cls cs));
wenzelm@4250
   182
wenzelm@4250
   183
    fun pretty_default S = Pretty.block
wenzelm@14794
   184
      [Pretty.str "default sort:", Pretty.brk 1, prt_sort S];
wenzelm@4250
   185
skalberg@15531
   186
    fun pretty_witness NONE = Pretty.str "universal non-emptiness witness: -"
skalberg@15531
   187
      | pretty_witness (SOME (T, S)) = Pretty.block
wenzelm@14794
   188
          [Pretty.str "universal non-emptiness witness:", Pretty.brk 1,
wenzelm@14794
   189
            prt_typ_no_tvars T, Pretty.str " ::", Pretty.brk 1, prt_sort S];
wenzelm@14794
   190
wenzelm@14996
   191
    val tfrees = map (fn v => TFree (v, []));
wenzelm@16364
   192
    fun pretty_type syn (t, (Type.LogicalType n, _)) =
skalberg@15531
   193
          if syn then NONE
skalberg@15531
   194
          else SOME (prt_typ (Type (t, tfrees (Term.invent_names [] "'a" n))))
wenzelm@16364
   195
      | pretty_type syn (t, (Type.Abbreviation (vs, U, syn'), _)) =
skalberg@15531
   196
          if syn <> syn' then NONE
skalberg@15531
   197
          else SOME (Pretty.block
wenzelm@14996
   198
            [prt_typ (Type (t, tfrees vs)), Pretty.str " =", Pretty.brk 1, prt_typ U])
wenzelm@16364
   199
      | pretty_type syn (t, (Type.Nonterminal, _)) =
skalberg@15531
   200
          if not syn then NONE
skalberg@15531
   201
          else SOME (prt_typ (Type (t, [])));
wenzelm@4250
   202
wenzelm@19482
   203
    val pretty_arities = maps (fn (t, ars) => map (prt_arity t) ars);
skalberg@14223
   204
wenzelm@19698
   205
    fun pretty_abbrev (c, (ty, t)) = Pretty.block
wenzelm@19698
   206
      (prt_const (c, ty) @ [Pretty.str " ==", Pretty.brk 1, prt_term_no_vars t]);
wenzelm@19698
   207
wenzelm@19698
   208
    fun pretty_axm (a, t) = Pretty.block [Pretty.str (a ^ ":"), Pretty.brk 1, prt_term_no_vars t];
wenzelm@19365
   209
wenzelm@19698
   210
    fun pretty_reduct (lhs, rhs) = Pretty.block
wenzelm@19698
   211
      ([prt_const' lhs, Pretty.str "  ->", Pretty.brk 2] @ Pretty.commas (map prt_const' rhs));
wenzelm@4250
   212
wenzelm@19698
   213
    fun pretty_restrict (const, name) =
wenzelm@19698
   214
      Pretty.block ([prt_const' const, Pretty.brk 2, Pretty.str ("(from " ^ quote name ^ ")")]);
wenzelm@8720
   215
wenzelm@19698
   216
    val {axioms, defs, oracles} = Theory.rep_theory thy;
wenzelm@19698
   217
    val {restricts, reducts} = Defs.dest defs;
wenzelm@18061
   218
    val {naming, syn = _, tsig, consts} = Sign.rep_sg thy;
wenzelm@18936
   219
    val {constants, constraints} = Consts.dest consts;
wenzelm@19698
   220
    val extern_const = NameSpace.extern (#1 constants);
wenzelm@19698
   221
    val {classes, default, types, witness, ...} = Type.rep_tsig tsig;
wenzelm@19698
   222
    val (class_space, class_algebra) = classes;
wenzelm@19642
   223
    val {classes, arities} = Sorts.rep_algebra class_algebra;
wenzelm@14996
   224
wenzelm@19642
   225
    val clsses = NameSpace.dest_table (class_space, Symtab.make (Graph.dest classes));
wenzelm@16845
   226
    val tdecls = NameSpace.dest_table types;
wenzelm@16845
   227
    val arties = NameSpace.dest_table (Sign.type_space thy, arities);
wenzelm@18936
   228
    val cnsts = NameSpace.extern_table constants;
wenzelm@19482
   229
    val log_cnsts = map_filter (fn (c, (ty, NONE)) => SOME (c, ty) | _ => NONE) cnsts;
wenzelm@19482
   230
    val abbrevs = map_filter (fn (c, (ty, SOME t)) => SOME (c, (ty, t)) | _ => NONE) cnsts;
wenzelm@19365
   231
    val cnstrs = NameSpace.extern_table constraints;
wenzelm@16334
   232
    val axms = NameSpace.extern_table axioms;
wenzelm@16334
   233
    val oras = NameSpace.extern_table oracles;
wenzelm@19698
   234
wenzelm@19698
   235
    val reds = reducts |> map_filter (fn (lhs, rhs) =>
wenzelm@19698
   236
      if null rhs then NONE
wenzelm@19698
   237
      else SOME (apfst extern_const lhs, map (apfst extern_const) rhs)) |> sort_wrt (#1 o #1);
wenzelm@19698
   238
    val rests = restricts |> map (apfst (apfst extern_const)) |> sort_wrt (#1 o #1);
wenzelm@4250
   239
  in
wenzelm@16437
   240
    [Pretty.strs ("names:" :: Context.names_of thy),
wenzelm@16534
   241
      Pretty.strs ("theory data:" :: Context.theory_data_of thy),
wenzelm@16534
   242
      Pretty.strs ("proof data:" :: Context.proof_data_of thy),
wenzelm@16127
   243
      Pretty.strs ["name prefix:", NameSpace.path_of naming],
wenzelm@16364
   244
      Pretty.big_list "classes:" (map pretty_classrel clsses),
wenzelm@8720
   245
      pretty_default default,
wenzelm@14794
   246
      pretty_witness witness,
wenzelm@19482
   247
      Pretty.big_list "syntactic types:" (map_filter (pretty_type true) tdecls),
wenzelm@19482
   248
      Pretty.big_list "logical types:" (map_filter (pretty_type false) tdecls),
wenzelm@16534
   249
      Pretty.big_list "type arities:" (pretty_arities arties),
wenzelm@19698
   250
      Pretty.big_list "logical consts:" (map (Pretty.block o prt_const) log_cnsts),
wenzelm@19365
   251
      Pretty.big_list "abbreviations:" (map pretty_abbrev abbrevs),
wenzelm@19698
   252
      Pretty.big_list "constraints:" (map (Pretty.block o prt_const) cnstrs),
wenzelm@19698
   253
      Pretty.big_list "axioms:" (map pretty_axm axms),
wenzelm@19698
   254
      Pretty.big_list "definitions:"
wenzelm@19698
   255
        [Pretty.big_list "open dependencies:" (map pretty_reduct reds),
wenzelm@19698
   256
         Pretty.big_list "pattern restrictions:" (map pretty_restrict rests)],
wenzelm@8720
   257
      Pretty.strs ("oracles:" :: (map #1 oras))]
wenzelm@4250
   258
  end;
wenzelm@4250
   259
wenzelm@4250
   260
wenzelm@11883
   261
wenzelm@11883
   262
(** print_goals **)
wenzelm@11883
   263
wenzelm@11883
   264
(* print_goals etc. *)
wenzelm@11883
   265
wenzelm@16534
   266
val show_consts = ref false;  (*true: show consts with types in proof state output*)
wenzelm@3851
   267
paulson@1591
   268
wenzelm@11883
   269
(*print thm A1,...,An/B in "goal style" -- premises as numbered subgoals*)
wenzelm@11883
   270
wenzelm@11883
   271
local
wenzelm@11883
   272
wenzelm@18980
   273
fun ins_entry (x, y) =
wenzelm@18980
   274
  AList.default (op =) (x, []) #>
wenzelm@18980
   275
  AList.map_entry (op =) x (insert (op =) y);
wenzelm@12081
   276
wenzelm@18980
   277
val add_consts = Term.fold_aterms
wenzelm@18980
   278
  (fn Const (c, T) => ins_entry (T, (c, T))
wenzelm@18980
   279
    | _ => I);
wenzelm@11883
   280
wenzelm@18980
   281
val add_vars = Term.fold_aterms
wenzelm@18980
   282
  (fn Free (x, T) => ins_entry (T, (x, ~1))
wenzelm@18980
   283
    | Var (xi, T) => ins_entry (T, xi)
wenzelm@18980
   284
    | _ => I);
wenzelm@11883
   285
wenzelm@18980
   286
val add_varsT = Term.fold_atyps
wenzelm@18980
   287
  (fn TFree (x, S) => ins_entry (S, (x, ~1))
wenzelm@18980
   288
    | TVar (xi, S) => ins_entry (S, xi)
wenzelm@18980
   289
    | _ => I);
wenzelm@11883
   290
wenzelm@16490
   291
fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs;
wenzelm@12081
   292
fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs;
wenzelm@12081
   293
wenzelm@18980
   294
fun consts_of t = sort_cnsts (add_consts t []);
wenzelm@18980
   295
fun vars_of t = sort_idxs (add_vars t []);
wenzelm@18980
   296
fun varsT_of t = rev (sort_idxs (Term.fold_types add_varsT t []));
wenzelm@12081
   297
wenzelm@12081
   298
in
wenzelm@11883
   299
wenzelm@14876
   300
fun pretty_goals_aux pp begin_goal (msg, main) maxgoals state =
wenzelm@12081
   301
  let
wenzelm@12081
   302
    fun prt_atoms prt prtT (X, xs) = Pretty.block
wenzelm@12081
   303
      [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::",
wenzelm@12081
   304
        Pretty.brk 1, prtT X];
wenzelm@11883
   305
wenzelm@14876
   306
    fun prt_var (x, ~1) = Pretty.term pp (Syntax.free x)
wenzelm@14876
   307
      | prt_var xi = Pretty.term pp (Syntax.var xi);
wenzelm@12081
   308
wenzelm@14876
   309
    fun prt_varT (x, ~1) = Pretty.typ pp (TFree (x, []))
wenzelm@14876
   310
      | prt_varT xi = Pretty.typ pp (TVar (xi, []));
wenzelm@12081
   311
wenzelm@14876
   312
    val prt_consts = prt_atoms (Pretty.term pp o Const) (Pretty.typ pp);
wenzelm@14876
   313
    val prt_vars = prt_atoms prt_var (Pretty.typ pp);
wenzelm@14876
   314
    val prt_varsT = prt_atoms prt_varT (Pretty.sort pp);
wenzelm@11883
   315
wenzelm@11883
   316
wenzelm@12081
   317
    fun pretty_list _ _ [] = []
wenzelm@12081
   318
      | pretty_list name prt lst = [Pretty.big_list name (map prt lst)];
wenzelm@11883
   319
wenzelm@14876
   320
    fun pretty_subgoal (n, A) = Pretty.blk (0,
wenzelm@14876
   321
     [Pretty.str (begin_goal ^ " " ^ string_of_int n ^ ". "), Pretty.term pp A]);
wenzelm@12081
   322
    fun pretty_subgoals As = map pretty_subgoal (1 upto length As ~~ As);
wenzelm@11883
   323
wenzelm@14876
   324
    val pretty_ffpairs = pretty_list "flex-flex pairs:" (pretty_flexpair pp);
wenzelm@11883
   325
wenzelm@12081
   326
    val pretty_consts = pretty_list "constants:" prt_consts o consts_of;
wenzelm@12081
   327
    val pretty_vars = pretty_list "variables:" prt_vars o vars_of;
wenzelm@12081
   328
    val pretty_varsT = pretty_list "type variables:" prt_varsT o varsT_of;
wenzelm@11883
   329
wenzelm@11883
   330
wenzelm@16290
   331
    val {prop, tpairs, ...} = Thm.rep_thm state;
berghofe@13658
   332
    val (As, B) = Logic.strip_horn prop;
wenzelm@12081
   333
    val ngoals = length As;
wenzelm@11883
   334
wenzelm@12081
   335
    fun pretty_gs (types, sorts) =
wenzelm@14876
   336
      (if main then [Pretty.term pp B] else []) @
wenzelm@12081
   337
       (if ngoals = 0 then [Pretty.str "No subgoals!"]
wenzelm@12081
   338
        else if ngoals > maxgoals then
skalberg@15570
   339
          pretty_subgoals (Library.take (maxgoals, As)) @
wenzelm@12081
   340
          (if msg then [Pretty.str ("A total of " ^ string_of_int ngoals ^ " subgoals...")]
wenzelm@12081
   341
           else [])
wenzelm@12081
   342
        else pretty_subgoals As) @
wenzelm@12081
   343
      pretty_ffpairs tpairs @
wenzelm@12081
   344
      (if ! show_consts then pretty_consts prop else []) @
wenzelm@12081
   345
      (if types then pretty_vars prop else []) @
wenzelm@12081
   346
      (if sorts then pretty_varsT prop else []);
wenzelm@12081
   347
  in
wenzelm@12081
   348
    setmp show_no_free_types true
skalberg@14178
   349
      (setmp show_types (! show_types orelse ! show_sorts orelse ! show_all_types)
wenzelm@12081
   350
        (setmp show_sorts false pretty_gs))
skalberg@14178
   351
   (! show_types orelse ! show_sorts orelse ! show_all_types, ! show_sorts)
wenzelm@11883
   352
  end;
wenzelm@11883
   353
wenzelm@12081
   354
fun pretty_goals_marker bg n th =
wenzelm@16437
   355
  pretty_goals_aux (Sign.pp (Thm.theory_of_thm th)) bg (true, true) n th;
wenzelm@12081
   356
wenzelm@12081
   357
val pretty_goals = pretty_goals_marker "";
wenzelm@12418
   358
val print_goals = (Pretty.writeln o Pretty.chunks) oo pretty_goals_marker "";
wenzelm@12081
   359
paulson@1591
   360
end;
paulson@1591
   361
wenzelm@11883
   362
wenzelm@11883
   363
(* print_current_goals *)
wenzelm@11883
   364
wenzelm@11883
   365
val current_goals_markers = ref ("", "", "");
wenzelm@11883
   366
wenzelm@12418
   367
fun pretty_current_goals n m th =
wenzelm@11883
   368
  let
wenzelm@11883
   369
    val ref (begin_state, end_state, begin_goal) = current_goals_markers;
wenzelm@11883
   370
    val ngoals = nprems_of th;
wenzelm@11883
   371
  in
wenzelm@12418
   372
    (if begin_state = "" then [] else [Pretty.str begin_state]) @
wenzelm@12418
   373
    [Pretty.str ("Level " ^ string_of_int n ^
wenzelm@11883
   374
      (if ngoals > 0 then " (" ^ string_of_int ngoals ^ " subgoal" ^
wenzelm@11883
   375
        (if ngoals <> 1 then "s" else "") ^ ")"
wenzelm@12418
   376
      else ""))] @
wenzelm@12418
   377
    pretty_goals_marker begin_goal m th @
wenzelm@12418
   378
    (if end_state = "" then [] else [Pretty.str end_state])
wenzelm@11883
   379
  end;
wenzelm@11883
   380
wenzelm@12418
   381
fun print_current_goals_default n m th =
wenzelm@12418
   382
  Pretty.writeln (Pretty.chunks (pretty_current_goals n m th));
wenzelm@12418
   383
wenzelm@11883
   384
val print_current_goals_fn = ref print_current_goals_default;
wenzelm@11883
   385
wenzelm@11883
   386
end;
wenzelm@11883
   387
wenzelm@11883
   388
structure BasicDisplay: BASIC_DISPLAY = Display;
wenzelm@11883
   389
open BasicDisplay;