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 | Change (_, t1, t2, where) ->
47 let size1 = countterm (current_size + 12) t1 in (* change, with *)
48 let size2 = countterm size1 t2 in
51 | Some ident -> size2 + 3 + String.length ident)
52 (* | Change_pattern _ -> assert false (* TODO *) *)
53 | Contradiction _ -> current_size + 13
54 | Cut (_, term) -> countterm (current_size + 4) term
55 | Decompose (_, ident, principles) ->
57 (fun size s -> size + (String.length s))
58 (current_size + 11 + String.length ident) principles
59 | Discriminate (_, ident) -> current_size + 12 + (String.length ident)
60 | Elim (_, term, using) ->
61 let size1 = countterm (current_size + 5) term in
64 | Some term -> countterm (size1 + 7) term)
65 | ElimType (_, term) -> countterm (current_size + 10) term
66 | Exact (_, term) -> countterm (current_size + 6) term
67 | Exists _ -> current_size + 6
68 | Fold (_, kind, term) ->
69 countterm (current_size + 5) term
70 | Fourier _ -> current_size + 7
71 | Generalize (_,term,pattern) -> assert false (* TODO *)
72 | Goal (_, n) -> current_size + 4 + int_of_float (ceil (log10 (float n)))
73 | Injection (_, ident) -> current_size + 10 + (String.length ident)
74 | Intros (_, num, idents) ->
76 (fun size s -> size + (String.length s))
77 (current_size + 7) idents
78 | Left _ -> current_size + 4
79 | LetIn (_, term, ident) ->
80 countterm (current_size + 5 + String.length ident) term
82 | Reduce _ -> assert false (* TODO *)
83 | Reflexivity _ -> current_size + 11
84 | Replace (_, t1, t2) ->
85 let size1 = countterm (current_size + 14) t1 in (* replace, with *)
87 (* | Replace_pattern _ -> assert false (* TODO *) *)
88 | Rewrite _ -> assert false (* TODO *)
89 | Right _ -> current_size + 5
90 | Ring _ -> current_size + 4
91 | Split _ -> current_size + 5
92 | Symmetry _ -> current_size + 8
93 | Transitivity (_, term) ->
94 countterm (current_size + 13) term
98 let n = (count_tactic 0 tac) in
99 (* prerr_endline ("Lunghezza: " ^ (string_of_int n)); *)
104 let rec small_tactic2box tac =
105 Box.Text([], TacticAstPp.pp_tactic tac)
107 let string_of_kind = function
108 | `Reduce -> "reduce"
109 | `Simpl -> "simplify"
111 | `Normalize -> "normalize"
113 let dummy_tbl = Hashtbl.create 0
115 let ast2astBox ast = Ast2pres.ast2astBox (ast, dummy_tbl)
117 let pretty_append l ast =
120 Box.H([],[Box.skip; ast2astBox ast])]
122 [Box.H([],l@[Box.smallskip; ast2astBox ast])]
124 let rec tactic2box tac =
125 if (is_big_tac tac) then
130 and big_tactic2box = function
131 | Absurd (_, term) ->
132 Box.V([],[Box.Text([],"absurd");
135 Box.V([],[Box.Text([],"apply");
137 | Assumption _ -> Box.Text([],"assumption")
138 | Auto _ -> Box.Text([],"auto")
139 | Change (_, t1, t2, where) ->
146 Box.Text([],ident)]) in
149 [Box.Text([],"change")]
152 [Box.Text([],"with")]
154 (* | Change_pattern _ -> assert false (* TODO *) *)
155 | Contradiction _ -> Box.Text([],"contradiction")
157 Box.V([],[Box.Text([],"cut");
158 Box.indent(ast2astBox term)])
159 | Decompose (_, ident, principles) ->
161 List.map (fun x -> Box.Text([],x)) principles in
162 Box.V([],[Box.Text([],"decompose");
163 Box.H([],[Box.Text([],"[");
164 Box.V([],principles);
167 | Discriminate (_, ident) ->
168 Box.V([],[Box.Text([],"discriminate");
170 | Elim (_, term, using) ->
176 [Box.Text([],"using")]
180 [Box.Text([],"elim")]
182 | ElimType (_, term) ->
183 Box.V([],[Box.Text([],"elim type");
184 Box.indent(ast2astBox term)])
186 Box.V([],[Box.Text([],"exact");
187 Box.indent(ast2astBox term)])
188 | Exists _ -> Box.Text([],"exists")
189 | Fold (_, kind, term) ->
190 Box.V([],[Box.H([],[Box.Text([],"fold");
192 Box.Text([],string_of_kind kind)]);
193 Box.indent(ast2astBox term)])
194 | Fourier _ -> Box.Text([],"fourier")
195 | Generalize _ -> assert false (* TODO *)
196 | Goal (_, n) -> Box.Text([],"goal " ^ string_of_int n)
197 | Injection (_, ident) ->
198 Box.V([],[Box.Text([],"transitivity");
199 Box.indent (Box.Text([],ident))])
200 | Intros (_, num, idents) ->
204 | Some num -> [Box.Text([],string_of_int num)]) in
206 List.map (fun x -> Box.Text([],x)) idents in
207 Box.V([],[Box.Text([],"decompose");
208 Box.H([],[Box.smallskip;
210 | Left _ -> Box.Text([],"left")
211 | LetIn (_, term, ident) ->
212 Box.V([],[Box.H([],[Box.Text([],"let");
217 Box.indent (ast2astBox term)])
219 | Reduce _ -> assert false (* TODO *)
220 | Reflexivity _ -> Box.Text([],"reflexivity")
221 | Replace (_, t1, t2) ->
224 [Box.Text([],"replace")]
227 [Box.Text([],"with")]
229 (* | Replace_pattern _ -> assert false (* TODO *) *)
230 | Rewrite _ -> assert false (* TODO *)
231 | Right _ -> Box.Text([],"right")
232 | Ring _ -> Box.Text([],"ring")
233 | Split _ -> Box.Text([],"split")
234 | Symmetry _ -> Box.Text([],"symmetry")
235 | Transitivity (_, term) ->
236 Box.V([],[Box.Text([],"transitivity");
237 Box.indent (ast2astBox term)])
242 let rec tactical2box = function
243 | Tactic (_, tac) -> tactic2box tac
245 | Command cmd -> (* TODO dummy implementation *)
246 Box.Text([], TacticAstPp.pp_tactical (Command cmd))
249 | Fail _ -> Box.Text([],"fail")
250 | Do (_, count, tac) ->
251 Box.V([],[Box.Text([],"do " ^ string_of_int count);
252 Box.indent (tactical2box tac)])
253 | IdTac _ -> Box.Text([],"id")
255 Box.V([],[Box.Text([],"repeat");
256 Box.indent (tactical2box tac)])
258 Box.V([],tacticals2box tacs)
259 | Then (_, tac, tacs) ->
260 Box.V([],[tactical2box tac;
263 Box.V([],tacticals2box tacs);
264 Box.Text([],"]");])])
266 Box.V([],[Box.Text([],"try");
269 Box.V([],tacticals2box tacs);
270 Box.Text([],"]");])])
272 Box.V([],[Box.Text([],"try");
273 Box.indent (tactical2box tac)])
275 and tacticals2box tacs =
277 (function tac -> Box.H([],[tactical2box tac; Box.Text([],";")])) tacs
282 (BoxPp.to_string CicAstPp.pp_term (tactical2box tac));;