src/Pure/display.ML
author wenzelm
Mon, 20 Oct 1997 10:51:01 +0200
changeset 3936 1954255c29ef
parent 3879 de18c0c1141c
child 3990 a8c80f5fdd16
permissions -rw-r--r--
tuned output;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     1
(*  Title:      Pure/display.ML
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     2
    ID:         $Id$
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     5
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     6
Printing of theories, theorems, etc.
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     7
*)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     8
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
     9
signature DISPLAY =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    10
  sig
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    11
  val pprint_cterm	: cterm -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    12
  val pprint_ctyp	: ctyp -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    13
  val pprint_theory	: theory -> pprint_args -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    14
  val pprint_thm	: thm -> pprint_args -> unit
3547
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    15
  val pretty_cterm	: cterm -> Pretty.T
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    16
  val pretty_thm	: thm -> Pretty.T
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    17
  val print_cterm	: cterm -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    18
  val print_ctyp	: ctyp -> unit
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
    19
  val show_consts	: bool ref
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    20
  val print_goals	: int -> thm -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    21
  val print_syntax	: theory -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    22
  val print_theory	: theory -> unit
3873
64f496e0885d improved print_data;
wenzelm
parents: 3866
diff changeset
    23
  val print_data	: theory -> string -> unit
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    24
  val print_thm		: thm -> unit
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    25
  val prth		: thm -> thm
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    26
  val prthq		: thm Sequence.seq -> thm Sequence.seq
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    27
  val prths		: thm list -> thm list
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    28
  val show_hyps		: bool ref
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    29
  val string_of_cterm	: cterm -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    30
  val string_of_ctyp	: ctyp -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    31
  val string_of_thm	: thm -> string
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    32
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    33
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    34
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    35
structure Display : DISPLAY =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    36
struct
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    37
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    38
(*If false, hypotheses are printed as dots*)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    39
val show_hyps = ref true;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    40
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    41
fun pretty_thm th =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    42
  let
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    43
    val {sign, hyps, prop, ...} = rep_thm th;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    44
    val xshyps = extra_shyps th;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    45
    val hlen = length xshyps + length hyps;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    46
    val hsymbs =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    47
      if hlen = 0 then []
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    48
      else if ! show_hyps then
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    49
        [Pretty.brk 2, Pretty.list "[" "]"
3785
0830d11b8916 now uses new Sign.pretty_sort;
wenzelm
parents: 3669
diff changeset
    50
          (map (Sign.pretty_term sign) hyps @
0830d11b8916 now uses new Sign.pretty_sort;
wenzelm
parents: 3669
diff changeset
    51
           map (Sign.pretty_sort sign) xshyps)]
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    52
      else
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    53
        [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")];
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    54
  in
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    55
    Pretty.block (Sign.pretty_term sign prop :: hsymbs)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    56
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    57
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    58
val string_of_thm = Pretty.string_of o pretty_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    59
val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    60
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    61
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    62
(** Top-level commands for printing theorems **)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    63
val print_thm = writeln o string_of_thm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    64
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    65
fun prth th = (print_thm th; th);
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    66
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    67
(*Print and return a sequence of theorems, separated by blank lines. *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    68
fun prthq thseq =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    69
  (Sequence.prints (fn _ => print_thm) 100000 thseq; thseq);
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    70
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    71
(*Print and return a list of theorems, separated by blank lines. *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    72
fun prths ths = (print_list_ln print_thm ths; ths);
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    73
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    74
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    75
(* other printing commands *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    76
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    77
fun pprint_ctyp cT =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    78
  let val {sign, T} = rep_ctyp cT in Sign.pprint_typ sign T end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    79
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    80
fun string_of_ctyp cT =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    81
  let val {sign, T} = rep_ctyp cT in Sign.string_of_typ sign T end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    82
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    83
val print_ctyp = writeln o string_of_ctyp;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    84
3547
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    85
fun pretty_cterm ct =
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    86
  let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end;
977d58464d7f added pretty_cterm;
wenzelm
parents: 3531
diff changeset
    87
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    88
fun pprint_cterm ct =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    89
  let val {sign, t, ...} = rep_cterm ct in Sign.pprint_term sign t end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    90
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    91
fun string_of_cterm ct =
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    92
  let val {sign, t, ...} = rep_cterm ct in Sign.string_of_term sign t end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    93
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    94
val print_cterm = writeln o string_of_cterm;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    95
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    96
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    97
(* print theory *)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    98
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
    99
val pprint_theory = Sign.pprint_sg o sign_of;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   100
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   101
val print_syntax = Syntax.print_syntax o syn_of;
3873
64f496e0885d improved print_data;
wenzelm
parents: 3866
diff changeset
   102
val print_data = Sign.print_data o sign_of;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   103
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   104
fun print_thy thy =
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   105
  let
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   106
    val {sign, new_axioms, oracles, ...} = rep_theory thy;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   107
    val axioms = Symtab.dest new_axioms;
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   108
    val oras = map fst (Symtab.dest oracles);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   109
3936
1954255c29ef tuned output;
wenzelm
parents: 3879
diff changeset
   110
    fun prt_axm (a, t) = Pretty.block
1954255c29ef tuned output;
wenzelm
parents: 3879
diff changeset
   111
      [Pretty.str (Sign.cond_extern sign Theory.thmK a ^ ":"), Pretty.brk 1,
1954255c29ef tuned output;
wenzelm
parents: 3879
diff changeset
   112
        Pretty.quote (Sign.pretty_term sign t)];
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   113
  in
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   114
    Pretty.writeln (Pretty.big_list "additional axioms:" (map prt_axm axioms));
3873
64f496e0885d improved print_data;
wenzelm
parents: 3866
diff changeset
   115
    Pretty.writeln (Pretty.strs ("oracles:" :: oras))
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   116
  end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   117
3811
ec27ddb5104c print_theory: added oracles;
wenzelm
parents: 3785
diff changeset
   118
fun print_theory thy = (Sign.print_sg (sign_of thy); print_thy thy);
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   119
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   120
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   121
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   122
(** Print thm A1,...,An/B in "goal style" -- premises as numbered subgoals **)
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   123
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   124
(*show consts in case of showing types?*)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   125
val show_consts = ref false;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   126
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   127
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   128
local
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   129
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   130
  (* utils *)
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   131
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   132
  fun ins_entry (x, y) [] = [(x, [y])]
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   133
    | ins_entry (x, y) ((pair as (x', ys')) :: pairs) =
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   134
        if x = x' then (x', y ins ys') :: pairs
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   135
        else pair :: ins_entry (x, y) pairs;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   136
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   137
  fun add_consts (Const (c, T), env) = ins_entry (T, c) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   138
    | add_consts (t $ u, env) = add_consts (u, add_consts (t, env))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   139
    | add_consts (Abs (_, _, t), env) = add_consts (t, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   140
    | add_consts (_, env) = env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   141
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   142
  fun add_vars (Free (x, T), env) = ins_entry (T, (x, ~1)) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   143
    | add_vars (Var (xi, T), env) = ins_entry (T, xi) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   144
    | add_vars (Abs (_, _, t), env) = add_vars (t, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   145
    | add_vars (t $ u, env) = add_vars (u, add_vars (t, env))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   146
    | add_vars (_, env) = env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   147
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   148
  fun add_varsT (Type (_, Ts), env) = foldr add_varsT (Ts, env)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   149
    | add_varsT (TFree (x, S), env) = ins_entry (S, (x, ~1)) env
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   150
    | add_varsT (TVar (xi, S), env) = ins_entry (S, xi) env;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   151
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   152
  fun less_idx ((x, i):indexname, (y, j):indexname) =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   153
    x < y orelse x = y andalso i < j;
3879
de18c0c1141c Eta-expansion of function declarations, for value polymorphism
paulson
parents: 3873
diff changeset
   154
  fun sort_idxs l = map (apsnd (sort less_idx)) l;
de18c0c1141c Eta-expansion of function declarations, for value polymorphism
paulson
parents: 3873
diff changeset
   155
  fun sort_strs l = map (apsnd sort_strings) l;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   156
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   157
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   158
  (* prepare atoms *)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   159
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   160
  fun consts_of t = sort_strs (add_consts (t, []));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   161
  fun vars_of t = sort_idxs (add_vars (t, []));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   162
  fun varsT_of t = rev (sort_idxs (it_term_types add_varsT (t, [])));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   163
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   164
in
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   165
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   166
  (* print_goals *)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   167
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   168
  fun print_goals maxgoals state =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   169
    let
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   170
      val {sign, ...} = rep_thm state;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   171
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   172
      val prt_term = Sign.pretty_term sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   173
      val prt_typ = Sign.pretty_typ sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   174
      val prt_sort = Sign.pretty_sort sign;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   175
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   176
      fun prt_atoms prt prtT (X, xs) = Pretty.block
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   177
        [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::",
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   178
          Pretty.brk 1, prtT X];
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   179
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   180
      fun prt_var (x, ~1) = prt_term (Syntax.free x)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   181
        | prt_var xi = prt_term (Syntax.var xi);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   182
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   183
      fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   184
        | prt_varT xi = prt_typ (TVar (xi, []));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   185
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   186
      val prt_consts = prt_atoms (prt_term o Syntax.const) prt_typ;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   187
      val prt_vars = prt_atoms prt_var prt_typ;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   188
      val prt_varsT = prt_atoms prt_varT prt_sort;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   189
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   190
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   191
      fun print_list _ _ [] = ()
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   192
        | print_list name prt lst = (writeln "";
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   193
            Pretty.writeln (Pretty.big_list name (map prt lst)));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   194
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   195
      fun print_subgoals (_, []) = ()
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   196
        | print_subgoals (n, A :: As) = (Pretty.writeln (Pretty.blk (0,
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   197
            [Pretty.str (" " ^ string_of_int n ^ ". "), prt_term A]));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   198
              print_subgoals (n + 1, As));
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   199
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   200
      val print_ffpairs =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   201
        print_list "Flex-flex pairs:" (prt_term o Logic.mk_flexpair);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   202
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   203
      val print_consts = print_list "Constants:" prt_consts o consts_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   204
      val print_vars = print_list "Variables:" prt_vars o vars_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   205
      val print_varsT = print_list "Type variables:" prt_varsT o varsT_of;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   206
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   207
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   208
      val {prop, ...} = rep_thm state;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   209
      val (tpairs, As, B) = Logic.strip_horn prop;
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   210
      val ngoals = length As;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   211
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   212
      fun print_gs (types, sorts) =
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   213
       (Pretty.writeln (prt_term B);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   214
        if ngoals = 0 then writeln "No subgoals!"
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   215
        else if ngoals > maxgoals then
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   216
          (print_subgoals (1, take (maxgoals, As));
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   217
            writeln ("A total of " ^ string_of_int ngoals ^ " subgoals..."))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   218
        else print_subgoals (1, As);
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   219
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   220
        print_ffpairs tpairs;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   221
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   222
        if types andalso ! show_consts then print_consts prop else ();
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   223
        if types then print_vars prop else ();
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   224
        if sorts then print_varsT prop else ());
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   225
    in
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   226
      setmp show_no_free_types true
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   227
        (setmp show_types (! show_types orelse ! show_sorts)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   228
          (setmp show_sorts false print_gs))
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   229
     (! show_types orelse ! show_sorts, ! show_sorts)
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   230
  end;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   231
3851
fe9932a7cd46 print_goals: optional output of const types (set show_consts);
wenzelm
parents: 3811
diff changeset
   232
end;
1591
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   233
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   234
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   235
end;
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   236
7fa0265dcd13 New module for display/printing operations, taken from drule.ML
paulson
parents:
diff changeset
   237
open Display;