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 pp_hyp_pattern hyp ^ separator ^ pp_goal_pattern goal
61 let rec pp_tactic = function
62 | Absurd (_, term) -> "absurd" ^ pp_term_ast term
63 | Apply (_, term) -> "apply " ^ pp_term_ast term
65 | Assumption _ -> "assumption"
66 | Change (_, t1, t2, where) ->
67 sprintf "change %s with %s%s" (pp_term_ast t1) (pp_term_ast t2)
68 (match where with None -> "" | Some ident -> "in " ^ ident)
69 (* | Change_pattern (_, _, _, _) -> assert false (* TODO *) *)
70 | Contradiction _ -> "contradiction"
71 | Cut (_, term) -> "cut " ^ pp_term_ast term
72 | Decompose (_, ident, principles) ->
73 sprintf "decompose %s %s" (pp_idents principles) ident
74 | Discriminate (_, ident) -> "discriminate " ^ ident
75 | Elim (_, term, using) ->
76 sprintf "elim " ^ pp_term_ast term ^
77 (match using with None -> "" | Some term -> " using " ^ pp_term_ast term)
78 | ElimType (_, term) -> "elim type " ^ pp_term_ast term
79 | Exact (_, term) -> "exact " ^ pp_term_ast term
80 | Exists _ -> "exists"
81 | Fold (_, kind, term) ->
82 sprintf "fold %s %s" (pp_reduction_kind kind) (pp_term_ast term)
83 | Goal (_, n) -> "goal " ^ string_of_int n
84 | Fourier _ -> "fourier"
85 | Injection (_, ident) -> "injection " ^ ident
86 | Intros (_, None, []) -> "intro"
87 | Intros (_, num, idents) ->
89 (match num with None -> "" | Some num -> " " ^ string_of_int num)
90 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
92 | LetIn (_, term, ident) -> sprintf "let %s in %s" (pp_term_ast term) ident
93 (* | Reduce (_, kind, None) *)
94 (* | Reduce (_, kind, Some ([], `Goal)) -> pp_reduction_kind kind *)
95 (* | Reduce (_, kind, Some ([], `Everywhere)) -> *)
96 (* sprintf "%s in hyp" (pp_reduction_kind kind) *)
97 (* | Reduce (_, kind, Some (terms, `Goal)) -> *)
98 (* sprintf "%s %s" (pp_reduction_kind kind) *)
99 (* (String.concat ", " (List.map pp_term_ast terms)) *)
100 (* | Reduce (_, kind, Some (terms, `Everywhere)) -> *)
101 (* sprintf "%s in hyp %s" (pp_reduction_kind kind) *)
102 (* (String.concat ", " (List.map pp_term_ast terms)) *)
103 | Reduce (_, kind, pat) ->
104 sprintf "%s in %s" (pp_reduction_kind kind) (pp_pattern pat)
105 | Reflexivity _ -> "reflexivity"
106 | Replace (_, t1, t2) ->
107 sprintf "replace %s with %s" (pp_term_ast t1) (pp_term_ast t2)
108 (* | Replace_pattern (_, _, _) -> assert false (* TODO *) *)
109 | Rewrite (_, pos, t, pattern) ->
110 sprintf "rewrite %s %s in %s"
111 (if pos = `Left then "left" else "right") (pp_term_ast t)
116 | Symmetry _ -> "symmetry"
117 | Transitivity (_, term) -> "transitivity " ^ pp_term_ast term
118 | FwdSimpl (_, ident) -> sprintf "fwd %s" ident
120 let pp_flavour = function
121 | `Definition -> "Definition"
125 | `Remark -> "Remark"
126 | `Theorem -> "Theorem"
128 let pp_search_kind = function
129 | `Locate -> "locate"
134 let pp_macro pp_term = function
136 | WInstance (_, term) -> "whelp instance " ^ pp_term term
137 | WHint (_, t) -> "whelp hint " ^ pp_term t
138 | WLocate (_, s) -> "whelp locate " ^ s
139 | WElim (_, t) -> "whelp elim " ^ pp_term t
140 | WMatch (_, term) -> "whelp match " ^ pp_term term
142 (* | Abort _ -> "Abort" *)
143 | Check (_, term) -> sprintf "Check %s" (pp_term term)
145 (* | Redo (_, None) -> "Redo"
146 | Redo (_, Some n) -> sprintf "Redo %d" n *)
147 | Search_pat (_, kind, pat) ->
148 sprintf "search %s \"%s\"" (pp_search_kind kind) pat
149 | Search_term (_, kind, term) ->
150 sprintf "search %s %s" (pp_search_kind kind) (pp_term term)
151 (* | Undo (_, None) -> "Undo"
152 | Undo (_, Some n) -> sprintf "Undo %d" n *)
153 | Print (_, name) -> sprintf "Print \"%s\"" name
156 let pp_macro_ast = pp_macro pp_term_ast
157 let pp_macro_cic = pp_macro pp_term_cic
159 let pp_alias = function
160 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"" id uri
161 | Symbol_alias (symb, instance, desc) ->
162 sprintf "alias symbol \"%s\" (instance %d) = \"%s\""
164 | Number_alias (instance,desc) ->
165 sprintf "alias num (instance %d) = \"%s\"" instance desc
167 let pp_params = function
173 (fun (name, typ) -> sprintf "(%s:%s)" name (pp_term_ast typ))
176 let pp_fields fields =
177 (if fields <> [] then "\n" else "") ^
179 (List.map (fun (name,ty) -> " " ^ name ^ ": " ^ pp_term_ast ty) fields)
181 let pp_obj = function
182 | Inductive (params, types) ->
183 let pp_constructors constructors =
185 (List.map (fun (name, typ) -> sprintf "| %s: %s" name (pp_term_ast typ))
188 let pp_type (name, _, typ, constructors) =
189 sprintf "\nwith %s: %s \\def\n%s" name (pp_term_ast typ)
190 (pp_constructors constructors)
194 | (name, inductive, typ, constructors) :: tl ->
196 sprintf "%sinductive %s%s: %s \\def\n%s"
197 (if inductive then "" else "co") name (pp_params params)
198 (pp_term_ast typ) (pp_constructors constructors)
200 fst_typ_pp ^ String.concat "" (List.map pp_type tl))
201 | Theorem (flavour, name, typ, body) ->
202 sprintf "%s %s: %s %s"
208 | Some body -> "\\def " ^ pp_term_ast body)
209 | Record (params,name,ty,fields) ->
210 "record " ^ name ^ " " ^ pp_params params ^ " \\def {" ^
211 pp_fields fields ^ "}"
214 let pp_command = function
216 | Set (_, name, value) -> sprintf "Set \"%s\" \"%s\"" name value
217 | Coercion (_,_) -> "Coercion IMPLEMENT ME!!!!!"
218 | Alias (_,s) -> pp_alias s
219 | Obj (_,obj) -> pp_obj obj
221 let rec pp_tactical = function
222 | Tactic (_, tac) -> pp_tactic tac
225 | Do (_, count, tac) -> sprintf "do %d %s" count (pp_tactical tac)
227 | Repeat (_, tac) -> "repeat " ^ pp_tactical tac
228 | Seq (_, tacs) -> pp_tacticals tacs
229 | Then (_, tac, tacs) ->
230 sprintf "%s [%s]" (pp_tactical tac) (pp_tacticals tacs)
231 | Tries (_, tacs) -> sprintf "tries [%s]" (pp_tacticals tacs)
232 | Try (_, tac) -> "try " ^ pp_tactical tac
234 and pp_tacticals tacs =
235 String.concat (tactical_separator ^ " ") (List.map pp_tactical tacs)
237 let pp_tactical tac = pp_tactical tac ^ tactical_terminator
238 let pp_tactic tac = pp_tactic tac ^ tactic_terminator
239 let pp_command tac = pp_command tac ^ command_terminator
241 let pp_executable = function
242 | Macro (_,x) -> pp_macro_ast x
243 | Tactical (_,x) -> pp_tactical x
244 | Command (_,x) -> pp_command x
246 let pp_comment = function
247 | Note (_,str) -> sprintf "(* %s *)" str
248 | Code (_,code) -> sprintf "(** %s. **)" (pp_executable code)
250 let pp_statement = function
251 | Executable (_, ex) -> pp_executable ex
252 | Comment (_, c) -> pp_comment c