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
34 let pp_term_ast term = CicNotationPp.pp_term term
35 let pp_term_cic term = CicPp.ppterm term
37 let pp_idents idents = "[" ^ String.concat "; " idents ^ "]"
39 let pp_terms_ast terms = String.concat ", " (List.map pp_term_ast terms)
41 let pp_reduction_kind = function
42 | `Normalize -> "normalize"
44 | `Simpl -> "simplify"
45 | `Unfold (Some t) -> "unfold " ^ pp_term_ast t
46 | `Unfold None -> "unfold"
50 let pp_pattern (t, hyp, goal) =
51 let pp_hyp_pattern l =
53 (List.map (fun (name, p) -> sprintf "%s : %s" name (pp_term_ast p)) l) in
57 | Some t -> pp_term_ast t
59 pp_t t ^ " in " ^ pp_hyp_pattern hyp ^ " \\vdash " ^ pp_term_ast goal
61 let pp_intros_specs = function
63 | Some num, [] -> Printf.sprintf " names %i" num
64 | None, idents -> Printf.sprintf " names %s" (pp_idents idents)
65 | Some num, idents -> Printf.sprintf " names %i %s" num (pp_idents idents)
67 let rec pp_tactic = function
68 | Absurd (_, term) -> "absurd" ^ pp_term_ast term
69 | Apply (_, term) -> "apply " ^ pp_term_ast term
71 | Assumption _ -> "assumption"
72 | Change (_, where, with_what) ->
73 sprintf "change %s with %s" (pp_pattern where) (pp_term_ast with_what)
74 | Clear (_,id) -> sprintf "clear %s" id
75 | ClearBody (_,id) -> sprintf "clearbody %s" id
76 | Compare (_,term) -> "compare " ^ pp_term_ast term
77 | Constructor (_,n) -> "constructor " ^ string_of_int n
78 | Contradiction _ -> "contradiction"
79 | Cut (_, ident, term) ->
80 "cut " ^ pp_term_ast term ^
81 (match ident with None -> "" | Some id -> " as " ^ id)
82 | DecideEquality _ -> "decide equality"
83 | Decompose (_, [], what, names) ->
84 sprintf "decompose %s%s" what (pp_intros_specs (None, names))
85 | Decompose (_, types, what, names) ->
86 let to_ident = function
88 | Type _ -> assert false
90 let types = List.rev_map to_ident types in
91 sprintf "decompose %s %s%s" (pp_idents types) what (pp_intros_specs (None, names))
92 | Discriminate (_, term) -> "discriminate " ^ pp_term_ast term
93 | Elim (_, term, using, num, idents) ->
94 sprintf "elim " ^ pp_term_ast term ^
95 (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
96 ^ pp_intros_specs (num, idents)
97 | ElimType (_, term, using, num, idents) ->
98 sprintf "elim type " ^ pp_term_ast term ^
99 (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
100 ^ pp_intros_specs (num, idents)
101 | Exact (_, term) -> "exact " ^ pp_term_ast term
102 | Exists _ -> "exists"
103 | Fold (_, kind, term, pattern) ->
104 sprintf "fold %s %s %s" (pp_reduction_kind kind)
105 (pp_term_ast term) (pp_pattern pattern)
106 | FwdSimpl (_, hyp, idents) ->
107 sprintf "fwd %s%s" hyp
108 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
109 | Generalize (_, pattern, ident) ->
110 sprintf "generalize %s%s" (pp_pattern pattern)
111 (match ident with None -> "" | Some id -> " as " ^ id)
112 | Goal (_, n) -> "goal " ^ string_of_int n
114 | Fourier _ -> "fourier"
116 | Injection (_, term) -> "injection " ^ pp_term_ast term
117 | Intros (_, None, []) -> "intro"
118 | Intros (_, num, idents) ->
120 (match num with None -> "" | Some num -> " " ^ string_of_int num)
121 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
122 | LApply (_, level_opt, terms, term, ident_opt) ->
123 sprintf "lapply %s%s%s%s"
124 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
126 (match terms with [] -> "" | _ -> " to " ^ pp_terms_ast terms)
127 (match ident_opt with None -> "" | Some ident -> " using " ^ ident)
129 | LetIn (_, term, ident) -> sprintf "let %s in %s" (pp_term_ast term) ident
130 | Reduce (_, kind, pat) ->
131 sprintf "%s %s" (pp_reduction_kind kind) (pp_pattern pat)
132 | Reflexivity _ -> "reflexivity"
133 | Replace (_, pattern, t) ->
134 sprintf "replace %s with %s" (pp_pattern pattern) (pp_term_ast t)
135 | Rewrite (_, pos, t, pattern) ->
136 sprintf "rewrite %s %s %s"
137 (if pos = `LeftToRight then ">" else "<")
143 | Symmetry _ -> "symmetry"
144 | Transitivity (_, term) -> "transitivity " ^ pp_term_ast term
146 let pp_flavour = function
147 | `Definition -> "Definition"
151 | `Remark -> "Remark"
152 | `Theorem -> "Theorem"
153 | `Variant -> "Variant"
155 let pp_search_kind = function
156 | `Locate -> "locate"
160 | `Instance -> "instance"
162 let pp_macro pp_term = function
164 | WInstance (_, term) -> "whelp instance " ^ pp_term term
165 | WHint (_, t) -> "whelp hint " ^ pp_term t
166 | WLocate (_, s) -> "whelp locate " ^ s
167 | WElim (_, t) -> "whelp elim " ^ pp_term t
168 | WMatch (_, term) -> "whelp match " ^ pp_term term
170 (* | Abort _ -> "Abort" *)
171 | Check (_, term) -> sprintf "Check %s" (pp_term term)
173 (* | Redo (_, None) -> "Redo"
174 | Redo (_, Some n) -> sprintf "Redo %d" n *)
175 | Search_pat (_, kind, pat) ->
176 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
177 | Search_term (_, kind, term) ->
178 sprintf "search %s %s" (pp_search_kind kind) (pp_term term)
179 (* | Undo (_, None) -> "Undo"
180 | Undo (_, Some n) -> sprintf "Undo %d" n *)
181 | Print (_, name) -> sprintf "Print \"%s\"" name
184 let pp_macro_ast = pp_macro pp_term_ast
185 let pp_macro_cic = pp_macro pp_term_cic
187 let pp_alias = function
188 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"" id uri
189 | Symbol_alias (symb, instance, desc) ->
190 sprintf "alias symbol \"%s\" (instance %d) = \"%s\""
192 | Number_alias (instance,desc) ->
193 sprintf "alias num (instance %d) = \"%s\"" instance desc
195 let pp_params = function
201 (fun (name, typ) -> sprintf "(%s:%s)" name (pp_term_ast typ))
204 let pp_fields fields =
205 (if fields <> [] then "\n" else "") ^
207 (List.map (fun (name,ty) -> " " ^ name ^ ": " ^ pp_term_ast ty) fields)
209 let pp_obj = function
210 | Inductive (params, types) ->
211 let pp_constructors constructors =
213 (List.map (fun (name, typ) -> sprintf "| %s: %s" name (pp_term_ast typ))
216 let pp_type (name, _, typ, constructors) =
217 sprintf "\nwith %s: %s \\def\n%s" name (pp_term_ast typ)
218 (pp_constructors constructors)
222 | (name, inductive, typ, constructors) :: tl ->
224 sprintf "%sinductive %s%s: %s \\def\n%s"
225 (if inductive then "" else "co") name (pp_params params)
226 (pp_term_ast typ) (pp_constructors constructors)
228 fst_typ_pp ^ String.concat "" (List.map pp_type tl))
229 | Theorem (flavour, name, typ, body) ->
230 sprintf "%s %s: %s %s"
236 | Some body -> "\\def " ^ pp_term_ast body)
237 | Record (params,name,ty,fields) ->
238 "record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
239 pp_fields fields ^ "}"
241 let pp_argument_pattern = function
242 | CicNotationPt.IdentArg (eta_depth, name) ->
243 let eta_buf = Buffer.create 5 in
244 for i = 1 to eta_depth do
245 Buffer.add_string eta_buf "\\eta."
247 sprintf "%s%s" (Buffer.contents eta_buf) name
249 let rec pp_cic_appl_pattern = function
250 | CicNotationPt.UriPattern uri -> UriManager.string_of_uri uri
251 | CicNotationPt.VarPattern name -> name
252 | CicNotationPt.ImplicitPattern -> "_"
253 | CicNotationPt.ApplPattern aps ->
254 sprintf "(%s)" (String.concat " " (List.map pp_cic_appl_pattern aps))
256 let pp_l1_pattern = CicNotationPp.pp_term
257 let pp_l2_pattern = CicNotationPp.pp_term
259 let pp_associativity = function
260 | Gramext.LeftA -> "left associative"
261 | Gramext.RightA -> "right associative"
262 | Gramext.NonA -> "non associative"
264 let pp_precedence i = sprintf "with precedence %d" i
266 let pp_dir_opt = function
268 | Some `LeftToRight -> "> "
269 | Some `RightToLeft -> "< "
271 let pp_command = function
272 | Include (_,path) -> "include " ^ path
275 | Set (_, name, value) -> sprintf "set \"%s\" \"%s\"" name value
276 | Coercion (_,term) -> sprintf "coercion %s" (pp_term_ast term)
277 | Alias (_,s) -> pp_alias s
278 | Obj (_,obj) -> pp_obj obj
279 | Default (_,what,uris) ->
280 sprintf "default \"%s\" %s" what
281 (String.concat " " (List.map UriManager.string_of_uri uris))
282 | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
283 sprintf "interpretation \"%s\" '%s %s = %s"
285 (String.concat " " (List.map pp_argument_pattern arg_patterns))
286 (pp_cic_appl_pattern cic_appl_pattern)
287 | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
288 sprintf "notation %s\"%s\" %s %s for %s"
290 (pp_l1_pattern l1_pattern)
291 (pp_associativity assoc)
293 (pp_l2_pattern l2_pattern)
295 | Dump _ -> assert false (* ZACK: debugging *)
297 let rec pp_tactical = function
298 | Tactic (_, tac) -> pp_tactic tac
299 | Do (_, count, tac) -> sprintf "do %d %s" count (pp_tactical tac)
300 | Repeat (_, tac) -> "repeat " ^ pp_tactical tac
301 | Seq (_, tacs) -> pp_tacticals ~sep:"; " tacs
302 | Then (_, tac, tacs) ->
303 sprintf "%s; [%s]" (pp_tactical tac) (pp_tacticals ~sep:" | " tacs)
304 | First (_, tacs) -> sprintf "tries [%s]" (pp_tacticals ~sep:" | " tacs)
305 | Try (_, tac) -> "try " ^ pp_tactical tac
306 | Solve (_, tac) -> sprintf "solve [%s]" (pp_tacticals ~sep:" | " tac)
308 and pp_tacticals ~sep tacs =
309 String.concat sep (List.map pp_tactical tacs)
311 let pp_tactical tac = pp_tactical tac ^ tactical_terminator
312 let pp_tactic tac = pp_tactic tac ^ tactic_terminator
313 let pp_command tac = pp_command tac ^ command_terminator
315 let pp_executable = function
316 | Macro (_,x) -> pp_macro_ast x
317 | Tactical (_,x) -> pp_tactical x
318 | Command (_,x) -> pp_command x
320 let pp_comment = function
321 | Note (_,str) -> sprintf "(* %s *)" str
322 | Code (_,code) -> sprintf "(** %s. **)" (pp_executable code)
324 let pp_statement = function
325 | Executable (_, ex) -> pp_executable ex
326 | Comment (_, c) -> pp_comment c
328 let pp_cic_command = function
329 | Include (_,path) -> "include " ^ path
332 | Coercion (_,term) -> sprintf "coercion %s" (CicPp.ppterm term)
340 | Obj _ -> assert false (* not implemented *)