author  wenzelm 
Thu, 20 Nov 1997 12:51:31 +0100  
changeset 4250  3806a00677ff 
parent 4210  abce78c8a931 
child 4256  e768c42069bb 
permissions  rwrr 
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 
4126  15 
val pretty_ctyp : ctyp > Pretty.T 
3547  16 
val pretty_cterm : cterm > Pretty.T 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

17 
val pretty_thm : thm > Pretty.T 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

18 
val print_cterm : cterm > unit 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

19 
val print_ctyp : ctyp > unit 
3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

20 
val show_consts : bool ref 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

21 
val print_goals : int > thm > unit 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

22 
val print_syntax : theory > unit 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

23 
val print_theory : theory > unit 
3873  24 
val print_data : theory > string > unit 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

25 
val print_thm : thm > unit 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

26 
val prth : thm > thm 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

27 
val prthq : thm Sequence.seq > thm Sequence.seq 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

28 
val prths : thm list > thm list 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

29 
val show_hyps : bool ref 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

30 
val string_of_cterm : cterm > string 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

31 
val string_of_ctyp : ctyp > string 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

32 
val string_of_thm : thm > string 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

33 
end; 
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 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

36 
structure Display : DISPLAY = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

37 
struct 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

38 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

39 
(*If false, hypotheses are printed as dots*) 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

40 
val show_hyps = ref true; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

41 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

42 
fun pretty_thm th = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

43 
let 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

44 
val {sign, hyps, prop, ...} = rep_thm th; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

45 
val xshyps = extra_shyps th; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

46 
val hlen = length xshyps + length hyps; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

47 
val hsymbs = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

48 
if hlen = 0 then [] 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

49 
else if ! show_hyps then 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

50 
[Pretty.brk 2, Pretty.list "[" "]" 
3785  51 
(map (Sign.pretty_term sign) hyps @ 
52 
map (Sign.pretty_sort sign) xshyps)] 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

53 
else 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

54 
[Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")]; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

55 
in 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

56 
Pretty.block (Sign.pretty_term sign prop :: hsymbs) 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

57 
end; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

58 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

59 
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

60 
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

61 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

62 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

63 
(** Toplevel commands for printing theorems **) 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

64 
val print_thm = writeln o string_of_thm; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

65 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

66 
fun prth th = (print_thm th; th); 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

67 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

68 
(*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

69 
fun prthq thseq = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

70 
(Sequence.prints (fn _ => print_thm) 100000 thseq; thseq); 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

71 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

72 
(*Print and return a list of theorems, separated by blank lines. *) 
4210  73 
fun prths ths = (seq (fn th => (print_thm th; writeln "")) ths; ths); 
1591
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 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

76 
(* other printing commands *) 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

77 

4126  78 
fun pretty_ctyp cT = 
79 
let val {sign, T} = rep_ctyp cT in Sign.pretty_typ sign T end; 

80 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

81 
fun pprint_ctyp cT = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

82 
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

83 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

84 
fun string_of_ctyp cT = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

85 
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

86 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

87 
val print_ctyp = writeln o string_of_ctyp; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

88 

3547  89 
fun pretty_cterm ct = 
90 
let val {sign, t, ...} = rep_cterm ct in Sign.pretty_term sign t end; 

91 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

92 
fun pprint_cterm ct = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

93 
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

94 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

95 
fun string_of_cterm ct = 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

96 
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

97 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

98 
val print_cterm = writeln o string_of_cterm; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

99 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

100 

4250  101 

102 
(** print theory **) 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

103 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

104 
val pprint_theory = Sign.pprint_sg o sign_of; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

105 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

106 
val print_syntax = Syntax.print_syntax o syn_of; 
3873  107 
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

108 

4250  109 

110 
(* print signature *) 

111 

112 
fun print_sign sg = 

113 
let 

114 
fun prt_cls c = Sign.pretty_sort sg [c]; 

115 
fun prt_sort S = Sign.pretty_sort sg S; 

116 
fun prt_arity t (c, Ss) = Sign.pretty_arity sg (t, Ss, [c]); 

117 
fun prt_typ ty = Pretty.quote (Sign.pretty_typ sg ty); 

118 

119 
val ext_class = Sign.cond_extern sg Sign.classK; 

120 
val ext_tycon = Sign.cond_extern sg Sign.typeK; 

121 
val ext_const = Sign.cond_extern sg Sign.constK; 

122 

123 

124 
fun pretty_space (kind, space) = Pretty.block (Pretty.breaks 

125 
(map Pretty.str (kind ^ ":" :: map quote (NameSpace.dest space)))); 

126 

127 
fun pretty_classes cs = Pretty.block 

128 
(Pretty.breaks (Pretty.str "classes:" :: map prt_cls cs)); 

129 

130 
fun pretty_classrel (c, cs) = Pretty.block 

131 
(prt_cls c :: Pretty.str " <" :: Pretty.brk 1 :: 

132 
Pretty.commas (map prt_cls cs)); 

133 

134 
fun pretty_default S = Pretty.block 

135 
[Pretty.str "default:", Pretty.brk 1, prt_sort S]; 

136 

137 
fun pretty_ty (t, n) = Pretty.block 

138 
[Pretty.str (ext_tycon t), Pretty.str (" " ^ string_of_int n)]; 

139 

140 
fun pretty_abbr (t, (vs, rhs)) = Pretty.block 

141 
[prt_typ (Type (t, map (fn v => TVar ((v, 0), [])) vs)), 

142 
Pretty.str " =", Pretty.brk 1, prt_typ rhs]; 

143 

144 
fun pretty_arities (t, ars) = map (prt_arity t) ars; 

145 

146 
fun pretty_const (c, ty) = Pretty.block 

147 
[Pretty.str c, Pretty.str " ::", Pretty.brk 1, prt_typ ty]; 

148 

149 
val {self = _, tsig, const_tab, syn = _, path, spaces, data} = Sign.rep_sg sg; 

150 
val spaces' = sort (fn ((k1, _), (k2, _)) => k1 < k2) spaces; 

151 
val {classes, classrel, default, tycons, abbrs, arities} = 

152 
Type.rep_tsig tsig; 

153 
val consts = sort_wrt fst (map (apfst ext_const) (Symtab.dest const_tab)); 

154 
in 

155 
Pretty.writeln (Pretty.strs ("stamps:" :: Sign.stamp_names_of sg)); 

156 
Pretty.writeln (Pretty.strs ("data:" :: Data.kinds data)); 

157 
Pretty.writeln (Pretty.strs ["name entry path:", NameSpace.pack path]); 

158 
Pretty.writeln (Pretty.big_list "name spaces:" (map pretty_space spaces')); 

159 
Pretty.writeln (pretty_classes classes); 

160 
Pretty.writeln (Pretty.big_list "class relation:" (map pretty_classrel classrel)); 

161 
Pretty.writeln (pretty_default default); 

162 
Pretty.writeln (Pretty.big_list "type constructors:" (map pretty_ty tycons)); 

163 
Pretty.writeln (Pretty.big_list "type abbreviations:" (map pretty_abbr abbrs)); 

164 
Pretty.writeln (Pretty.big_list "type arities:" (flat (map pretty_arities arities))); 

165 
Pretty.writeln (Pretty.big_list "consts:" (map pretty_const consts)) 

166 
end; 

167 

168 

169 
(* print axioms, oracles, theorems *) 

170 

3811  171 
fun print_thy thy = 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

172 
let 
3990  173 
val {sign, axioms, oracles, ...} = rep_theory thy; 
174 
val axioms = Symtab.dest axioms; 

3811  175 
val oras = map fst (Symtab.dest oracles); 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

176 

3936  177 
fun prt_axm (a, t) = Pretty.block 
3990  178 
[Pretty.str (Sign.cond_extern sign Theory.axiomK a ^ ":"), Pretty.brk 1, 
3936  179 
Pretty.quote (Sign.pretty_term sign t)]; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

180 
in 
3990  181 
Pretty.writeln (Pretty.big_list "axioms:" (map prt_axm axioms)); 
182 
Pretty.writeln (Pretty.strs ("oracles:" :: oras)); 

183 
print_data thy "theorems" 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

184 
end; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

185 

4250  186 
fun print_theory thy = (print_sign (sign_of thy); print_thy thy); 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

187 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

188 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

189 

4250  190 
(** print_goals **) 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

191 

4250  192 
(*print thm A1,...,An/B in "goal style"  premises as numbered subgoals*) 
193 

194 
(*also show consts in case of showing types?*) 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

195 
val show_consts = ref false; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

196 

1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

197 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

198 
local 
3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

199 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

200 
(* utils *) 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

201 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

202 
fun ins_entry (x, y) [] = [(x, [y])] 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

203 
 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

204 
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

205 
else pair :: ins_entry (x, y) pairs; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

206 

3990  207 
fun add_consts (Const (c, T), env) = ins_entry (T, (c, T)) env 
3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

208 
 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

209 
 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

210 
 add_consts (_, env) = env; 
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 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

213 
 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

214 
 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

215 
 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

216 
 add_vars (_, env) = env; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

217 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

218 
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

219 
 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

220 
 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

221 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

222 
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

223 
x < y orelse x = y andalso i < j; 
3879
de18c0c1141c
Etaexpansion of function declarations, for value polymorphism
paulson
parents:
3873
diff
changeset

224 
fun sort_idxs l = map (apsnd (sort less_idx)) l; 
3990  225 
fun sort_cnsts l = map (apsnd (sort_wrt fst)) l; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

226 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

227 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

228 
(* prepare atoms *) 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

229 

3990  230 
fun consts_of t = sort_cnsts (add_consts (t, [])); 
3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

231 
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

232 
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

233 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

234 
in 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

235 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

236 
fun print_goals maxgoals state = 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

237 
let 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

238 
val {sign, ...} = rep_thm state; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

239 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

240 
val prt_term = Sign.pretty_term sign; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

241 
val prt_typ = Sign.pretty_typ sign; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

242 
val prt_sort = Sign.pretty_sort sign; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

243 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

244 
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

245 
[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

246 
Pretty.brk 1, prtT X]; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

247 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

248 
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

249 
 prt_var xi = prt_term (Syntax.var xi); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

250 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

251 
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

252 
 prt_varT xi = prt_typ (TVar (xi, [])); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

253 

3990  254 
val prt_consts = prt_atoms (prt_term o Const) prt_typ; 
3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

255 
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

256 
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

257 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

258 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

259 
fun print_list _ _ [] = () 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

260 
 print_list name prt lst = (writeln ""; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

261 
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

262 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

263 
fun print_subgoals (_, []) = () 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

264 
 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

265 
[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

266 
print_subgoals (n + 1, As)); 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

267 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

268 
val print_ffpairs = 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

269 
print_list "Flexflex pairs:" (prt_term o Logic.mk_flexpair); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

270 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

271 
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

272 
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

273 
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

274 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

275 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

276 
val {prop, ...} = rep_thm state; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

277 
val (tpairs, As, B) = Logic.strip_horn prop; 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

278 
val ngoals = length As; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

279 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

280 
fun print_gs (types, sorts) = 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

281 
(Pretty.writeln (prt_term B); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

282 
if ngoals = 0 then writeln "No subgoals!" 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

283 
else if ngoals > maxgoals then 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

284 
(print_subgoals (1, take (maxgoals, As)); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

285 
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

286 
else print_subgoals (1, As); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

287 

fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

288 
print_ffpairs tpairs; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

289 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

290 
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

291 
if types then print_vars prop else (); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

292 
if sorts then print_varsT prop else ()); 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

293 
in 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

294 
setmp show_no_free_types true 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

295 
(setmp show_types (! show_types orelse ! show_sorts) 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

296 
(setmp show_sorts false print_gs)) 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

297 
(! show_types orelse ! show_sorts, ! show_sorts) 
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

298 
end; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

299 

3851
fe9932a7cd46
print_goals: optional output of const types (set show_consts);
wenzelm
parents:
3811
diff
changeset

300 
end; 
1591
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

301 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

302 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

303 
end; 
7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

304 

7fa0265dcd13
New module for display/printing operations, taken from drule.ML
paulson
parents:
diff
changeset

305 
open Display; 