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/
30 let tactical_terminator = "."
31 let tactic_terminator = tactical_terminator
32 let command_terminator = tactical_terminator
33 let tactical_separator = ";"
35 let pp_term_ast term = CicAstPp.pp_term term
36 let pp_term_cic term = CicPp.ppterm term
38 let pp_idents idents = "[" ^ String.concat "; " idents ^ "]"
40 let pp_reduction_kind = function
42 | `Simpl -> "simplify"
44 | `Normalize -> "normalize"
47 let pp_pattern (hyp, goal) =
48 let pp_hyp_pattern l =
50 (List.map (fun (name, p) -> sprintf "%s : %s" name (pp_term_ast p)) l)
52 let pp_goal_pattern p =
55 | Some p -> pp_term_ast p
58 if hyp <> [] then " \\vdash " else " "
60 "in " ^ pp_hyp_pattern hyp ^ separator ^ pp_goal_pattern goal
62 let rec pp_tactic = function
63 | Absurd (_, term) -> "absurd" ^ pp_term_ast term
64 | Apply (_, term) -> "apply " ^ pp_term_ast term
66 | Assumption _ -> "assumption"
67 | Change (_, t1, t2, where) ->
68 sprintf "change %s with %s %s" (pp_term_ast t1) (pp_term_ast t2)
70 | Clear (_,id) -> sprintf "clear %s" id
71 | ClearBody (_,id) -> sprintf "clearbody %s" id
72 | Compare (_,term) -> "compare " ^ pp_term_ast term
73 | Constructor (_,n) -> "constructor " ^ string_of_int n
74 | Contradiction _ -> "contradiction"
75 | Cut (_, ident, term) ->
76 "cut " ^ pp_term_ast term ^
77 (match ident with None -> "" | Some id -> " as " ^ id)
78 | DecideEquality _ -> "decide equality"
79 | Decompose (_, term) ->
80 sprintf "decompose %s" (pp_term_ast term)
81 | Discriminate (_, term) -> "discriminate " ^ pp_term_ast term
82 | Elim (_, term, using) ->
83 sprintf "elim " ^ pp_term_ast term ^
84 (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
85 | ElimType (_, term) -> "elim type " ^ pp_term_ast term
86 | Exact (_, term) -> "exact " ^ pp_term_ast term
87 | Exists _ -> "exists"
88 | Fold (_, kind, term, pattern) ->
89 sprintf "fold %s %s %s" (pp_reduction_kind kind) (pp_term_ast term)
91 | Generalize (_, term, ident, pattern) ->
92 sprintf "generalize %s%s %s" (pp_term_ast term)
93 (match ident with None -> "" | Some id -> " as " ^ id)
95 | Goal (_, n) -> "goal " ^ string_of_int n
97 | Fourier _ -> "fourier"
99 | Injection (_, term) -> "injection " ^ pp_term_ast term
100 | Intros (_, None, []) -> "intro"
101 | Intros (_, num, idents) ->
103 (match num with None -> "" | Some num -> " " ^ string_of_int num)
104 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
106 | LetIn (_, term, ident) -> sprintf "let %s in %s" (pp_term_ast term) ident
107 | Reduce (_, kind, pat) ->
108 sprintf "%s %s" (pp_reduction_kind kind) (pp_pattern pat)
109 | Reflexivity _ -> "reflexivity"
110 | Replace (_, pattern, t) ->
111 sprintf "replace %s with %s" (pp_pattern pattern) (pp_term_ast t)
112 | Rewrite (_, pos, t, pattern) ->
113 sprintf "rewrite %s %s %s"
114 (if pos = `Left then "left" else "right") (pp_term_ast t)
119 | Symmetry _ -> "symmetry"
120 | Transitivity (_, term) -> "transitivity " ^ pp_term_ast term
121 | FwdSimpl (_, term) -> sprintf "fwd %s" (pp_term_ast term)
122 | LApply (_, term_opt, term, ident) ->
123 sprintf "lapply %s%s%s" (pp_term_ast term)
124 (match term_opt with None -> "" | Some t -> " to " ^ pp_term_ast t)
125 (match ident with None -> "" | Some id -> " using " ^ id)
127 let pp_flavour = function
128 | `Definition -> "Definition"
132 | `Remark -> "Remark"
133 | `Theorem -> "Theorem"
135 let pp_search_kind = function
136 | `Locate -> "locate"
141 let pp_macro pp_term = function
143 | WInstance (_, term) -> "whelp instance " ^ pp_term term
144 | WHint (_, t) -> "whelp hint " ^ pp_term t
145 | WLocate (_, s) -> "whelp locate " ^ s
146 | WElim (_, t) -> "whelp elim " ^ pp_term t
147 | WMatch (_, term) -> "whelp match " ^ pp_term term
149 (* | Abort _ -> "Abort" *)
150 | Check (_, term) -> sprintf "Check %s" (pp_term term)
152 (* | Redo (_, None) -> "Redo"
153 | Redo (_, Some n) -> sprintf "Redo %d" n *)
154 | Search_pat (_, kind, pat) ->
155 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
156 | Search_term (_, kind, term) ->
157 sprintf "search %s %s" (pp_search_kind kind) (pp_term term)
158 (* | Undo (_, None) -> "Undo"
159 | Undo (_, Some n) -> sprintf "Undo %d" n *)
160 | Print (_, name) -> sprintf "Print \"%s\"" name
163 let pp_macro_ast = pp_macro pp_term_ast
164 let pp_macro_cic = pp_macro pp_term_cic
166 let pp_alias = function
167 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"" id uri
168 | Symbol_alias (symb, instance, desc) ->
169 sprintf "alias symbol \"%s\" (instance %d) = \"%s\""
171 | Number_alias (instance,desc) ->
172 sprintf "alias num (instance %d) = \"%s\"" instance desc
174 let pp_params = function
180 (fun (name, typ) -> sprintf "(%s:%s)" name (pp_term_ast typ))
183 let pp_fields fields =
184 (if fields <> [] then "\n" else "") ^
186 (List.map (fun (name,ty) -> " " ^ name ^ ": " ^ pp_term_ast ty) fields)
188 let pp_obj = function
189 | Inductive (params, types) ->
190 let pp_constructors constructors =
192 (List.map (fun (name, typ) -> sprintf "| %s: %s" name (pp_term_ast typ))
195 let pp_type (name, _, typ, constructors) =
196 sprintf "\nwith %s: %s \\def\n%s" name (pp_term_ast typ)
197 (pp_constructors constructors)
201 | (name, inductive, typ, constructors) :: tl ->
203 sprintf "%sinductive %s%s: %s \\def\n%s"
204 (if inductive then "" else "co") name (pp_params params)
205 (pp_term_ast typ) (pp_constructors constructors)
207 fst_typ_pp ^ String.concat "" (List.map pp_type tl))
208 | Theorem (flavour, name, typ, body) ->
209 sprintf "%s %s: %s %s"
215 | Some body -> "\\def " ^ pp_term_ast body)
216 | Record (params,name,ty,fields) ->
217 "record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
218 pp_fields fields ^ "}"
221 let pp_command = function
224 | Set (_, name, value) -> sprintf "Set \"%s\" \"%s\"" name value
225 | Coercion (_,_) -> "Coercion IMPLEMENT ME!!!!!"
226 | Alias (_,s) -> pp_alias s
227 | Obj (_,obj) -> pp_obj obj
229 let rec pp_tactical = function
230 | Tactic (_, tac) -> pp_tactic tac
231 | Do (_, count, tac) -> sprintf "do %d %s" count (pp_tactical tac)
232 | Repeat (_, tac) -> "repeat " ^ pp_tactical tac
233 | Seq (_, tacs) -> pp_tacticals tacs
234 | Then (_, tac, tacs) ->
235 sprintf "%s [%s]" (pp_tactical tac) (pp_tacticals tacs)
236 | Tries (_, tacs) -> sprintf "tries [%s]" (pp_tacticals tacs)
237 | Try (_, tac) -> "try " ^ pp_tactical tac
239 and pp_tacticals tacs =
240 String.concat (tactical_separator ^ " ") (List.map pp_tactical tacs)
242 let pp_tactical tac = pp_tactical tac ^ tactical_terminator
243 let pp_tactic tac = pp_tactic tac ^ tactic_terminator
244 let pp_command tac = pp_command tac ^ command_terminator
246 let pp_executable = function
247 | Macro (_,x) -> pp_macro_ast x
248 | Tactical (_,x) -> pp_tactical x
249 | Command (_,x) -> pp_command x
251 let pp_comment = function
252 | Note (_,str) -> sprintf "(* %s *)" str
253 | Code (_,code) -> sprintf "(** %s. **)" (pp_executable code)
255 let pp_statement = function
256 | Executable (_, ex) -> pp_executable ex
257 | Comment (_, c) -> pp_comment c