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 LocatedTactic (_, tac) -> count_tactic current_size tac
43 | Absurd -> current_size + 6
44 | Apply term -> countterm (current_size+6) term
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 | Injection ident -> current_size + 10 + (String.length ident)
72 | Intros (num, idents) ->
74 (fun size s -> size + (String.length s))
75 (current_size + 7) idents
76 | Left -> current_size + 4
77 | LetIn (term, ident) ->
78 countterm (current_size + 5 + String.length ident) term
79 | Reduce (_, _, _) -> assert false (* TODO *)
80 | Reflexivity -> current_size + 11
82 let size1 = countterm (current_size + 14) t1 in (* replace, with *)
84 | Replace_pattern (_, _) -> assert false (* TODO *)
85 | Rewrite (_, _, _) -> assert false (* TODO *)
86 | Right -> current_size + 5
87 | Ring -> current_size + 4
88 | Split -> current_size + 5
89 | Symmetry -> current_size + 8
90 | Transitivity term ->
91 countterm (current_size + 13) term
95 let n = (count_tactic 0 tac) in
96 (* prerr_endline ("Lunghezza: " ^ (string_of_int n)); *)
101 let rec small_tactic2box ?(attr = []) tac =
102 Box.Text([], TacticAstPp.pp_tactic tac)
104 let string_of_kind = function
105 | `Reduce -> "reduce"
109 let rec tactic2box ?(attr = []) tac =
110 if (is_big_tac tac) then
111 big_tactic2box ~attr tac
113 small_tactic2box ~attr tac
115 and big_tactic2box ?(attr = []) = function
116 LocatedTactic (loc, tac) ->
117 big_tactic2box ~attr tac
118 | Absurd -> Box.Text([],"absurd")
120 Box.V([],[Box.Text([],"apply");
122 | Assumption -> Box.Text([],"assumption")
123 | Change (t1, t2, where) ->
130 Box.Text([],ident)]) in
133 [Box.Text([],"change")]
137 [Box.Text([],"with")]
140 | Change_pattern (_, _, _) -> assert false (* TODO *)
141 | Contradiction -> Box.Text([],"contradiction")
143 Box.V([],[Box.Text([],"cut");
144 Box.indent(ast2box term)])
145 | Decompose (ident, principles) ->
147 List.map (fun x -> Box.Text([],x)) principles in
148 Box.V([],[Box.Text([],"decompose");
149 Box.H([],[Box.Text([],"[");
150 Box.V([],principles);
153 | Discriminate ident ->
154 Box.V([],[Box.Text([],"discriminate");
156 | Elim (term, using) ->
162 [Box.Text([],"using")]
167 [Box.Text([],"elim")]
171 Box.V([],[Box.Text([],"elim type");
172 Box.indent(ast2box term)])
174 Box.V([],[Box.Text([],"exact");
175 Box.indent(ast2box term)])
176 | Exists -> Box.Text([],"exists")
177 | Fold (kind, term) ->
178 Box.V([],[Box.H([],[Box.Text([],"fold");
180 Box.Text([],string_of_kind kind)]);
181 Box.indent(ast2box term)])
182 | Fourier -> Box.Text([],"fourier")
184 Box.V([],[Box.Text([],"transitivity");
185 Box.indent (Box.Text([],ident))])
186 | Intros (num, idents) ->
190 | Some num -> [Box.Text([],string_of_int num)]) in
192 List.map (fun x -> Box.Text([],x)) idents in
193 Box.V([],[Box.Text([],"decompose");
194 Box.H([],[Box.smallskip;
196 | Left -> Box.Text([],"left")
197 | LetIn (term, ident) ->
198 Box.V([],[Box.H([],[Box.Text([],"let");
203 Box.indent (ast2box term)])
204 | Reduce (_, _, _) -> assert false (* TODO *)
205 | Reflexivity -> Box.Text([],"reflexivity")
206 | Replace (t1, t2) ->
209 [Box.Text([],"replace")]
213 [Box.Text([],"with")]
216 | Replace_pattern (_, _) -> assert false (* TODO *)
217 | Rewrite (_, _, _) -> assert false (* TODO *)
218 | Right -> Box.Text([],"right")
219 | Ring -> Box.Text([],"ring")
220 | Split -> Box.Text([],"split")
221 | Symmetry -> Box.Text([],"symmetry")
222 | Transitivity term ->
223 Box.V([],[Box.Text([],"transitivity");
224 Box.indent (ast2box term)])
229 let rec tactical2box ?(attr = []) = function
230 | LocatedTactical (loc, tac) -> tactical2box tac
232 | Tactic tac -> tactic2box tac
233 | Command cmd -> (* TODO dummy implementation *)
234 Box.Text([], TacticAstPp.pp_tactical (Command cmd))
236 | Fail -> Box.Text([],"fail")
238 Box.V([],[Box.Text([],"do " ^ string_of_int count);
239 Box.indent (tactical2box tac)])
240 | IdTac -> Box.Text([],"id")
242 Box.V([],[Box.Text([],"repeat");
243 Box.indent (tactical2box tac)])
245 Box.V([],tacticals2box tacs)
246 | Then (tac, tacs) ->
247 Box.V([],[tactical2box tac;
250 Box.V([],tacticals2box tacs);
251 Box.Text([],"]");])])
253 Box.V([],[Box.Text([],"try");
256 Box.V([],tacticals2box tacs);
257 Box.Text([],"]");])])
259 Box.V([],[Box.Text([],"try");
260 Box.indent (tactical2box tac)])
262 and tacticals2box tacs =
264 (function tac -> Box.H([],[tactical2box tac; Box.Text([],";")])) tacs
269 (BoxPp.to_string CicAstPp.pp_term (tactical2box tac));;