(* Copyright (C) 2004, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) (**************************************************************************) (* *) (* PROJECT HELM *) (* *) (* Andrea Asperti *) (* 18/2/2004 *) (* *) (**************************************************************************) open Ast2pres open TacticAst let rec count_tactic current_size tac = if current_size > maxsize then current_size else match tac with | Absurd (_, term) -> countterm (current_size + 6) term | Apply (_, term) -> countterm (current_size + 6) term | Auto _ -> current_size + 4 | Assumption _ -> current_size + 10 | Compare (_, term) -> countterm (current_size + 7) term | Constructor (_, n) -> current_size + 12 | Contradiction _ -> current_size + 13 | Cut (_, ident, term) -> let id_size = match ident with None -> 0 | Some id -> String.length id + 4 in countterm (current_size + 4 + id_size) term | DecideEquality _ -> current_size + 15 | Decompose (_, term) -> countterm (current_size + 11) term | Discriminate (_, term) -> countterm (current_size + 12) term | Elim (_, term, using) -> let size1 = countterm (current_size + 5) term in (match using with None -> size1 | Some term -> countterm (size1 + 7) term) | ElimType (_, term) -> countterm (current_size + 10) term | Exact (_, term) -> countterm (current_size + 6) term | Exists _ -> current_size + 6 | Fourier _ -> current_size + 7 | Goal (_, n) -> current_size + 4 + int_of_float (ceil (log10 (float n))) | Injection (_, term) -> countterm (current_size + 10) term | Intros (_, num, idents) -> List.fold_left (fun size s -> size + (String.length s)) (current_size + 7) idents | Left _ -> current_size + 4 | LetIn (_, term, ident) -> countterm (current_size + 5 + String.length ident) term | Reflexivity _ -> current_size + 11 | Right _ -> current_size + 5 | Ring _ -> current_size + 4 | Split _ -> current_size + 5 | Symmetry _ -> current_size + 8 | Transitivity (_, term) -> countterm (current_size + 13) term ;; let is_big_tac tac = let n = (count_tactic 0 tac) in (* prerr_endline ("Lunghezza: " ^ (string_of_int n)); *) n > maxsize ;; (* prova *) let rec small_tactic2box tac = Box.Text([], TacticAstPp.pp_tactic tac) let string_of_kind = function | `Reduce -> "reduce" | `Simpl -> "simplify" | `Whd -> "whd" | `Normalize -> "normalize" let dummy_tbl = Hashtbl.create 0 let ast2astBox ast = Ast2pres.ast2astBox (ast, dummy_tbl) let pretty_append l ast = if is_big ast then [Box.H([],l); Box.H([],[Box.skip; ast2astBox ast])] else [Box.H([],l@[Box.smallskip; ast2astBox ast])] let rec tactic2box tac = if (is_big_tac tac) then big_tactic2box tac else small_tactic2box tac and big_tactic2box = function | Absurd (_, term) -> Box.V([],[Box.Text([],"absurd"); ast2astBox term]) | Apply (_, term) -> Box.V([],[Box.Text([],"apply"); ast2astBox term]) | Assumption _ -> Box.Text([],"assumption") | Auto _ -> Box.Text([],"auto") | Compare (_, term) -> Box.V([],[Box.Text([],"compare"); Box.indent(ast2astBox term)]) | Constructor (_,n) -> Box.Text ([],"constructor " ^ string_of_int n) | Contradiction _ -> Box.Text([],"contradiction") | DecideEquality _ -> Box.Text([],"decide equality") | Decompose (_, term) -> Box.V([],[Box.Text([],"decompose"); Box.indent(ast2astBox term)]) | Discriminate (_, term) -> Box.V([],pretty_append [Box.Text([],"discriminate")] term) | Elim (_, term, using) -> let using = (match using with None -> [] | Some term -> (pretty_append [Box.Text([],"using")] term)) in Box.V([], (pretty_append [Box.Text([],"elim")] term)@using) | ElimType (_, term) -> Box.V([],[Box.Text([],"elim type"); Box.indent(ast2astBox term)]) | Exact (_, term) -> Box.V([],[Box.Text([],"exact"); Box.indent(ast2astBox term)]) | Exists _ -> Box.Text([],"exists") | Fourier _ -> Box.Text([],"fourier") | Goal (_, n) -> Box.Text([],"goal " ^ string_of_int n) | Intros (_, num, idents) -> let num = (match num with None -> [] | Some num -> [Box.Text([],string_of_int num)]) in let idents = List.map (fun x -> Box.Text([],x)) idents in Box.V([],[Box.Text([],"decompose"); Box.H([],[Box.smallskip; Box.V([],idents)])]) | Left _ -> Box.Text([],"left") | LetIn (_, term, ident) -> Box.V([],[Box.H([],[Box.Text([],"let"); Box.smallskip; Box.Text([],ident); Box.smallskip; Box.Text([],"=")]); Box.indent (ast2astBox term)]) | Reflexivity _ -> Box.Text([],"reflexivity") | Right _ -> Box.Text([],"right") | Ring _ -> Box.Text([],"ring") | Split _ -> Box.Text([],"split") | Symmetry _ -> Box.Text([],"symmetry") | Transitivity (_, term) -> Box.V([],[Box.Text([],"transitivity"); Box.indent (ast2astBox term)]) ;; open TacticAst let rec tactical2box = function | Tactic (_, tac) -> tactic2box tac | Do (_, count, tac) -> Box.V([],[Box.Text([],"do " ^ string_of_int count); Box.indent (tactical2box tac)]) | Repeat (_, tac) -> Box.V([],[Box.Text([],"repeat"); Box.indent (tactical2box tac)]) | Seq (_, tacs) -> Box.V([],tacticals2box tacs) | Then (_, tac, tacs) -> Box.V([],[tactical2box tac; Box.H([],[Box.skip; Box.Text([],"["); Box.V([],tacticals2box tacs); Box.Text([],"]");])]) | Tries (_, tacs) -> Box.V([],[Box.Text([],"try"); Box.H([],[Box.skip; Box.Text([],"["); Box.V([],tacticals2box tacs); Box.Text([],"]");])]) | Try (_, tac) -> Box.V([],[Box.Text([],"try"); Box.indent (tactical2box tac)]) and tacticals2box tacs = List.map (function tac -> Box.H([],[tactical2box tac; Box.Text([],";")])) tacs ;; let tacticalPp tac = String.concat "\n" (BoxPp.to_string CicAstPp.pp_term (tactical2box tac));;