1 (* Copyright (C) 2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (**************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (**************************************************************************)
39 let rec count_tactic current_size tac =
40 if current_size > maxsize then current_size
42 | Absurd (_, term) -> countterm (current_size + 6) term
43 | Apply (_, term) -> countterm (current_size + 6) term
44 | Auto _ -> current_size + 4
45 | Assumption _ -> current_size + 10
46 | Compare (_, term) -> countterm (current_size + 7) term
47 | Constructor (_, n) -> current_size + 12
48 | Contradiction _ -> current_size + 13
49 | Cut (_, term) -> countterm (current_size + 4) term
50 | DecideEquality _ -> current_size + 15
51 | Decompose (_, term) ->
52 countterm (current_size + 11) term
53 | Discriminate (_, term) -> countterm (current_size + 12) term
54 | Elim (_, term, using) ->
55 let size1 = countterm (current_size + 5) term in
58 | Some term -> countterm (size1 + 7) term)
59 | ElimType (_, term) -> countterm (current_size + 10) term
60 | Exact (_, term) -> countterm (current_size + 6) term
61 | Exists _ -> current_size + 6
62 | Fold (_, kind, term) ->
63 countterm (current_size + 5) term
64 | Fourier _ -> current_size + 7
65 | Goal (_, n) -> current_size + 4 + int_of_float (ceil (log10 (float n)))
66 | Injection (_, term) ->
67 countterm (current_size + 10) term
68 | Intros (_, num, idents) ->
70 (fun size s -> size + (String.length s))
71 (current_size + 7) idents
72 | Left _ -> current_size + 4
73 | LetIn (_, term, ident) ->
74 countterm (current_size + 5 + String.length ident) term
75 | Reflexivity _ -> current_size + 11
76 | Replace (_, t1, t2) ->
77 let size1 = countterm (current_size + 14) t1 in (* replace, with *)
79 | Right _ -> current_size + 5
80 | Ring _ -> current_size + 4
81 | Split _ -> current_size + 5
82 | Symmetry _ -> current_size + 8
83 | Transitivity (_, term) ->
84 countterm (current_size + 13) term
88 let n = (count_tactic 0 tac) in
89 (* prerr_endline ("Lunghezza: " ^ (string_of_int n)); *)
94 let rec small_tactic2box tac =
95 Box.Text([], TacticAstPp.pp_tactic tac)
97 let string_of_kind = function
99 | `Simpl -> "simplify"
101 | `Normalize -> "normalize"
103 let dummy_tbl = Hashtbl.create 0
105 let ast2astBox ast = Ast2pres.ast2astBox (ast, dummy_tbl)
107 let pretty_append l ast =
110 Box.H([],[Box.skip; ast2astBox ast])]
112 [Box.H([],l@[Box.smallskip; ast2astBox ast])]
114 let rec tactic2box tac =
115 if (is_big_tac tac) then
120 and big_tactic2box = function
121 | Absurd (_, term) ->
122 Box.V([],[Box.Text([],"absurd");
125 Box.V([],[Box.Text([],"apply");
127 | Assumption _ -> Box.Text([],"assumption")
128 | Auto _ -> Box.Text([],"auto")
129 | Compare (_, term) ->
130 Box.V([],[Box.Text([],"compare");
131 Box.indent(ast2astBox term)])
132 | Constructor (_,n) -> Box.Text ([],"constructor " ^ string_of_int n)
133 | Contradiction _ -> Box.Text([],"contradiction")
135 Box.V([],[Box.Text([],"cut");
136 Box.indent(ast2astBox term)])
137 | DecideEquality _ -> Box.Text([],"decide equality")
138 | Decompose (_, term) ->
139 Box.V([],[Box.Text([],"decompose");
140 Box.indent(ast2astBox term)])
141 | Discriminate (_, term) ->
142 Box.V([],pretty_append [Box.Text([],"discriminate")] term)
143 | Elim (_, term, using) ->
149 [Box.Text([],"using")]
153 [Box.Text([],"elim")]
155 | ElimType (_, term) ->
156 Box.V([],[Box.Text([],"elim type");
157 Box.indent(ast2astBox term)])
159 Box.V([],[Box.Text([],"exact");
160 Box.indent(ast2astBox term)])
161 | Exists _ -> Box.Text([],"exists")
162 | Fold (_, kind, term) ->
163 Box.V([],[Box.H([],[Box.Text([],"fold");
165 Box.Text([],string_of_kind kind)]);
166 Box.indent(ast2astBox term)])
167 | Fourier _ -> Box.Text([],"fourier")
168 | Goal (_, n) -> Box.Text([],"goal " ^ string_of_int n)
169 | Intros (_, num, idents) ->
173 | Some num -> [Box.Text([],string_of_int num)]) in
175 List.map (fun x -> Box.Text([],x)) idents in
176 Box.V([],[Box.Text([],"decompose");
177 Box.H([],[Box.smallskip;
179 | Left _ -> Box.Text([],"left")
180 | LetIn (_, term, ident) ->
181 Box.V([],[Box.H([],[Box.Text([],"let");
186 Box.indent (ast2astBox term)])
187 | Reflexivity _ -> Box.Text([],"reflexivity")
188 | Replace (_, t1, t2) ->
191 [Box.Text([],"replace")]
194 [Box.Text([],"with")]
196 | Right _ -> Box.Text([],"right")
197 | Ring _ -> Box.Text([],"ring")
198 | Split _ -> Box.Text([],"split")
199 | Symmetry _ -> Box.Text([],"symmetry")
200 | Transitivity (_, term) ->
201 Box.V([],[Box.Text([],"transitivity");
202 Box.indent (ast2astBox term)])
207 let rec tactical2box = function
208 | Tactic (_, tac) -> tactic2box tac
210 | Command cmd -> (* TODO dummy implementation *)
211 Box.Text([], TacticAstPp.pp_tactical (Command cmd))
214 | Fail _ -> Box.Text([],"fail")
215 | Do (_, count, tac) ->
216 Box.V([],[Box.Text([],"do " ^ string_of_int count);
217 Box.indent (tactical2box tac)])
218 | IdTac _ -> Box.Text([],"id")
220 Box.V([],[Box.Text([],"repeat");
221 Box.indent (tactical2box tac)])
223 Box.V([],tacticals2box tacs)
224 | Then (_, tac, tacs) ->
225 Box.V([],[tactical2box tac;
228 Box.V([],tacticals2box tacs);
229 Box.Text([],"]");])])
231 Box.V([],[Box.Text([],"try");
234 Box.V([],tacticals2box tacs);
235 Box.Text([],"]");])])
237 Box.V([],[Box.Text([],"try");
238 Box.indent (tactical2box tac)])
240 and tacticals2box tacs =
242 (function tac -> Box.H([],[tactical2box tac; Box.Text([],";")])) tacs
247 (BoxPp.to_string CicAstPp.pp_term (tactical2box tac));;