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_terms_ast terms = String.concat ", " (List.map pp_term_ast terms)
42 let pp_reduction_kind = function
44 | `Simpl -> "simplify"
46 | `Normalize -> "normalize"
49 let pp_pattern (t, hyp, goal) =
50 let pp_hyp_pattern l =
52 (List.map (fun (name, p) -> sprintf "%s : %s" name (pp_term_ast p)) l) in
56 | Some t -> pp_term_ast t
58 pp_t t ^ " in " ^ pp_hyp_pattern hyp ^ " \\vdash " ^ pp_term_ast goal
60 let rec pp_tactic = function
61 | Absurd (_, term) -> "absurd" ^ pp_term_ast term
62 | Apply (_, term) -> "apply " ^ pp_term_ast term
64 | Assumption _ -> "assumption"
65 | Change (_, where, with_what) ->
66 sprintf "change %s with %s" (pp_pattern where) (pp_term_ast with_what)
67 | Clear (_,id) -> sprintf "clear %s" id
68 | ClearBody (_,id) -> sprintf "clearbody %s" id
69 | Compare (_,term) -> "compare " ^ pp_term_ast term
70 | Constructor (_,n) -> "constructor " ^ string_of_int n
71 | Contradiction _ -> "contradiction"
72 | Cut (_, ident, term) ->
73 "cut " ^ pp_term_ast term ^
74 (match ident with None -> "" | Some id -> " as " ^ id)
75 | DecideEquality _ -> "decide equality"
76 | Decompose (_, term) ->
77 sprintf "decompose %s" (pp_term_ast term)
78 | Discriminate (_, term) -> "discriminate " ^ pp_term_ast term
79 | Elim (_, term, using) ->
80 sprintf "elim " ^ pp_term_ast term ^
81 (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
82 | ElimType (_, term) -> "elim type " ^ pp_term_ast term
83 | Exact (_, term) -> "exact " ^ pp_term_ast term
84 | Exists _ -> "exists"
85 | Fold (_, kind, term, pattern) ->
86 sprintf "fold %s %s %s" (pp_reduction_kind kind)
87 (pp_term_ast term) (pp_pattern pattern)
88 | FwdSimpl (_, hyp, idents) ->
89 sprintf "fwd %s%s" hyp
90 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
91 | Generalize (_, pattern, ident) ->
92 sprintf "generalize %s%s" (pp_pattern pattern)
93 (match ident with None -> "" | Some id -> " as " ^ id)
94 | Goal (_, n) -> "goal " ^ string_of_int n
96 | Fourier _ -> "fourier"
98 | Injection (_, term) -> "injection " ^ pp_term_ast term
99 | Intros (_, None, []) -> "intro"
100 | Intros (_, num, idents) ->
102 (match num with None -> "" | Some num -> " " ^ string_of_int num)
103 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
104 | LApply (_, level_opt, terms, term, ident_opt) ->
105 sprintf "lapply %s%s%s%s"
106 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
108 (match terms with [] -> "" | _ -> " to " ^ pp_terms_ast terms)
109 (match ident_opt with None -> "" | Some ident -> " using " ^ ident)
111 | LetIn (_, term, ident) -> sprintf "let %s in %s" (pp_term_ast term) ident
112 | Reduce (_, kind, pat) ->
113 sprintf "%s %s" (pp_reduction_kind kind) (pp_pattern pat)
114 | Reflexivity _ -> "reflexivity"
115 | Replace (_, pattern, t) ->
116 sprintf "replace %s with %s" (pp_pattern pattern) (pp_term_ast t)
117 | Rewrite (_, pos, t, pattern) ->
118 sprintf "rewrite %s %s %s"
119 (if pos = `LeftToRight then ">" else "<")
125 | Symmetry _ -> "symmetry"
126 | Transitivity (_, term) -> "transitivity " ^ pp_term_ast term
128 let pp_flavour = function
129 | `Definition -> "Definition"
133 | `Remark -> "Remark"
134 | `Theorem -> "Theorem"
136 let pp_search_kind = function
137 | `Locate -> "locate"
142 let pp_macro pp_term = function
144 | WInstance (_, term) -> "whelp instance " ^ pp_term term
145 | WHint (_, t) -> "whelp hint " ^ pp_term t
146 | WLocate (_, s) -> "whelp locate " ^ s
147 | WElim (_, t) -> "whelp elim " ^ pp_term t
148 | WMatch (_, term) -> "whelp match " ^ pp_term term
150 (* | Abort _ -> "Abort" *)
151 | Check (_, term) -> sprintf "Check %s" (pp_term term)
153 (* | Redo (_, None) -> "Redo"
154 | Redo (_, Some n) -> sprintf "Redo %d" n *)
155 | Search_pat (_, kind, pat) ->
156 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
157 | Search_term (_, kind, term) ->
158 sprintf "search %s %s" (pp_search_kind kind) (pp_term term)
159 (* | Undo (_, None) -> "Undo"
160 | Undo (_, Some n) -> sprintf "Undo %d" n *)
161 | Print (_, name) -> sprintf "Print \"%s\"" name
164 let pp_macro_ast = pp_macro pp_term_ast
165 let pp_macro_cic = pp_macro pp_term_cic
167 let pp_alias = function
168 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"" id uri
169 | Symbol_alias (symb, instance, desc) ->
170 sprintf "alias symbol \"%s\" (instance %d) = \"%s\""
172 | Number_alias (instance,desc) ->
173 sprintf "alias num (instance %d) = \"%s\"" instance desc
175 let pp_params = function
181 (fun (name, typ) -> sprintf "(%s:%s)" name (pp_term_ast typ))
184 let pp_fields fields =
185 (if fields <> [] then "\n" else "") ^
187 (List.map (fun (name,ty) -> " " ^ name ^ ": " ^ pp_term_ast ty) fields)
189 let pp_obj = function
190 | Inductive (params, types) ->
191 let pp_constructors constructors =
193 (List.map (fun (name, typ) -> sprintf "| %s: %s" name (pp_term_ast typ))
196 let pp_type (name, _, typ, constructors) =
197 sprintf "\nwith %s: %s \\def\n%s" name (pp_term_ast typ)
198 (pp_constructors constructors)
202 | (name, inductive, typ, constructors) :: tl ->
204 sprintf "%sinductive %s%s: %s \\def\n%s"
205 (if inductive then "" else "co") name (pp_params params)
206 (pp_term_ast typ) (pp_constructors constructors)
208 fst_typ_pp ^ String.concat "" (List.map pp_type tl))
209 | Theorem (flavour, name, typ, body) ->
210 sprintf "%s %s: %s %s"
216 | Some body -> "\\def " ^ pp_term_ast body)
217 | Record (params,name,ty,fields) ->
218 "record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
219 pp_fields fields ^ "}"
222 let pp_command = function
223 | Include (_,path) -> "include " ^ path
226 | Set (_, name, value) -> sprintf "Set \"%s\" \"%s\"" name value
227 | Coercion (_,_) -> "Coercion IMPLEMENT ME!!!!!"
228 | Alias (_,s) -> pp_alias s
229 | Obj (_,obj) -> pp_obj obj
231 let rec pp_tactical = function
232 | Tactic (_, tac) -> pp_tactic tac
233 | Do (_, count, tac) -> sprintf "do %d %s" count (pp_tactical tac)
234 | Repeat (_, tac) -> "repeat " ^ pp_tactical tac
235 | Seq (_, tacs) -> pp_tacticals tacs
236 | Then (_, tac, tacs) ->
237 sprintf "%s [%s]" (pp_tactical tac) (pp_tacticals tacs)
238 | Tries (_, tacs) -> sprintf "tries [%s]" (pp_tacticals tacs)
239 | Try (_, tac) -> "try " ^ pp_tactical tac
241 and pp_tacticals tacs =
242 String.concat (tactical_separator ^ " ") (List.map pp_tactical tacs)
244 let pp_tactical tac = pp_tactical tac ^ tactical_terminator
245 let pp_tactic tac = pp_tactic tac ^ tactic_terminator
246 let pp_command tac = pp_command tac ^ command_terminator
248 let pp_executable = function
249 | Macro (_,x) -> pp_macro_ast x
250 | Tactical (_,x) -> pp_tactical x
251 | Command (_,x) -> pp_command x
253 let pp_comment = function
254 | Note (_,str) -> sprintf "(* %s *)" str
255 | Code (_,code) -> sprintf "(** %s. **)" (pp_executable code)
257 let pp_statement = function
258 | Executable (_, ex) -> pp_executable ex
259 | Comment (_, c) -> pp_comment c