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_idents idents =
35 let map = function Some s -> s | None -> "_" in
36 "(" ^ String.concat " " (List.map map idents) ^ ")"
37 let pp_hyps idents = String.concat " " idents
39 let pp_reduction_kind ~term_pp = function
40 | `Normalize -> "normalize"
42 | `Simpl -> "simplify"
43 | `Unfold (Some t) -> "unfold " ^ term_pp t
44 | `Unfold None -> "unfold"
47 let pp_tactic_pattern ~map_unicode_to_tex ~term_pp ~lazy_term_pp (what, hyp, goal) =
48 if what = None && hyp = [] && goal = None then "" else
52 | Some t -> Printf.sprintf "in match (%s) " (lazy_term_pp t) in
55 (List.map (fun (name, p) -> Printf.sprintf "%s:(%s)" name (term_pp p)) hyp) in
60 let vdash = if map_unicode_to_tex then "\\vdash" else "⊢" in
61 Printf.sprintf "%s (%s)" vdash (term_pp t)
63 Printf.sprintf "%sin %s%s" what_text hyp_text goal_text
65 let pp_intros_specs s = function
67 | Some num, [] -> Printf.sprintf " %s%i" s num
68 | None, idents -> Printf.sprintf " %s%s" s (pp_idents idents)
69 | Some num, idents -> Printf.sprintf " %s%i %s" s num (pp_idents idents)
71 let pp_terms ~term_pp terms = String.concat ", " (List.map term_pp terms)
73 let opt_string_pp = function
75 | Some what -> what ^ " "
77 let pp_auto_params ~term_pp (univ, params) =
79 (List.map (fun (k,v) -> if v <> "" then k ^ "=" ^ v else k) params) ^
81 (if params <> [] then " " else "") ^ "by " ^
82 String.concat " " (List.map term_pp univ)
86 let pp_just ~term_pp =
88 `Term term -> "exact " ^ term_pp term
89 | `Auto params -> pp_auto_params ~term_pp params
92 let rec pp_tactic ~map_unicode_to_tex ~term_pp ~lazy_term_pp =
93 let pp_terms = pp_terms ~term_pp in
94 let pp_tactics = pp_tactics ~map_unicode_to_tex ~term_pp ~lazy_term_pp in
95 let pp_reduction_kind = pp_reduction_kind ~term_pp in
96 let pp_tactic_pattern =
97 pp_tactic_pattern ~map_unicode_to_tex ~lazy_term_pp ~term_pp in
100 (* Higher order tactics *)
101 | Do (_, count, tac) ->
102 Printf.sprintf "do %d %s" count (pp_tactic tac)
103 | Repeat (_, tac) -> "repeat " ^ pp_tactic tac
104 | Seq (_, tacs) -> pp_tactics ~sep:"; " tacs
105 | Then (_, tac, tacs) ->
106 Printf.sprintf "%s; [%s]" (pp_tactic tac)
107 (pp_tactics ~sep:" | " tacs)
109 Printf.sprintf "tries [%s]" (pp_tactics ~sep:" | " tacs)
110 | Try (_, tac) -> "try " ^ pp_tactic tac
112 Printf.sprintf "solve [%s]" (pp_tactics ~sep:" | " tac)
113 | Progress (_, tac) -> "progress " ^ pp_tactic tac
114 (* First order tactics *)
115 | Absurd (_, term) -> "absurd" ^ term_pp term
116 | Apply (_, term) -> "apply " ^ term_pp term
117 | ApplyRule (_, term) -> "apply rule " ^ term_pp term
118 | ApplyP (_, term) -> "applyP " ^ term_pp term
119 | ApplyS (_, term, params) ->
120 "applyS " ^ term_pp term ^ pp_auto_params ~term_pp params
121 | AutoBatch (_,params) -> "autobatch " ^
122 pp_auto_params ~term_pp params
123 | Assumption _ -> "assumption"
124 | Cases (_, term, pattern, specs) -> Printf.sprintf "cases " ^ term_pp term ^
125 pp_tactic_pattern pattern ^
126 pp_intros_specs "names " specs
127 | Change (_, where, with_what) ->
128 Printf.sprintf "change %s with %s" (pp_tactic_pattern where) (lazy_term_pp with_what)
129 | Clear (_,ids) -> Printf.sprintf "clear %s" (pp_hyps ids)
130 | ClearBody (_,id) -> Printf.sprintf "clearbody %s" (pp_hyps [id])
131 | Constructor (_,n) -> "constructor " ^ string_of_int n
132 | Compose (_,t1, t2, times, intro_specs) ->
133 Printf.sprintf "compose %s%s %s%s"
134 (if times > 0 then string_of_int times ^ " " else "")
135 (term_pp t1) (match t2 with None -> "" | Some t2 -> "with "^term_pp t2)
136 (pp_intros_specs " as " intro_specs)
137 | Contradiction _ -> "contradiction"
138 | Cut (_, ident, term) ->
139 "cut " ^ term_pp term ^
140 (match ident with None -> "" | Some id -> " as " ^ id)
141 | Decompose (_, names) ->
142 Printf.sprintf "decompose%s"
143 (pp_intros_specs "names " (None, names))
144 | Demodulate (_, params) -> "demodulate " ^ pp_auto_params ~term_pp params
145 | Destruct (_, None) -> "destruct"
146 | Destruct (_, Some terms) -> "destruct " ^ pp_terms terms
147 | Elim (_, what, using, pattern, specs) ->
148 Printf.sprintf "elim %s%s %s%s"
150 (match using with None -> "" | Some term -> " using " ^ term_pp term)
151 (pp_tactic_pattern pattern)
152 (pp_intros_specs "names " specs)
153 | ElimType (_, term, using, specs) ->
154 Printf.sprintf "elim type %s%s%s"
156 (match using with None -> "" | Some term -> " using " ^ term_pp term)
157 (pp_intros_specs "names " specs)
158 | Exact (_, term) -> "exact " ^ term_pp term
159 | Exists _ -> "exists"
160 | Fold (_, kind, term, pattern) ->
161 Printf.sprintf "fold %s %s %s" (pp_reduction_kind kind)
162 (lazy_term_pp term) (pp_tactic_pattern pattern)
163 | FwdSimpl (_, hyp, names) ->
164 Printf.sprintf "fwd %s%s" hyp (pp_intros_specs "names " (None, names))
165 | Generalize (_, pattern, ident) ->
166 Printf.sprintf "generalize %s%s" (pp_tactic_pattern pattern)
167 (match ident with None -> "" | Some id -> " as " ^ id)
169 | Fourier _ -> "fourier"
171 | Intros (_, specs) -> Printf.sprintf "intros%s" (pp_intros_specs "" specs)
172 | Inversion (_, term) -> "inversion " ^ term_pp term
173 | LApply (_, linear, level_opt, terms, term, ident_opt) ->
174 Printf.sprintf "lapply %s%s%s%s%s"
175 (if linear then " linear " else "")
176 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
178 (match terms with [] -> "" | _ -> " to " ^ pp_terms terms)
179 (match ident_opt with None -> "" | Some ident -> " as " ^ ident)
181 | LetIn (_, term, ident) ->
182 Printf.sprintf "letin %s \\def %s" ident (term_pp term)
183 | Reduce (_, kind, pat) ->
184 Printf.sprintf "%s %s" (pp_reduction_kind kind) (pp_tactic_pattern pat)
185 | Reflexivity _ -> "reflexivity"
186 | Replace (_, pattern, t) ->
187 Printf.sprintf "replace %s with %s" (pp_tactic_pattern pattern) (lazy_term_pp t)
188 | Rewrite (_, pos, t, pattern, names) ->
189 Printf.sprintf "rewrite %s %s %s%s"
190 (if pos = `LeftToRight then ">" else "<")
192 (pp_tactic_pattern pattern)
193 (if names = [] then "" else " as " ^ pp_idents names)
197 | Symmetry _ -> "symmetry"
198 | Transitivity (_, term) -> "transitivity " ^ term_pp term
199 (* Tattiche Aggiunte *)
200 | Assume (_, ident , term) -> "assume" ^ ident ^ ":" ^ term_pp term
201 | Suppose (_, term, ident,term1) -> "suppose" ^ term_pp term ^ "(" ^ ident ^ ")" ^ (match term1 with None -> " " | Some term1 -> term_pp term1)
202 | Bydone (_, just) -> pp_just ~term_pp just ^ "done"
203 | By_just_we_proved (_, just, term1, ident, term2) -> pp_just ~term_pp just ^ "we proved" ^ term_pp term1 ^ (match ident with None -> "" | Some ident -> "(" ^ident^ ")") ^
204 (match term2 with None -> " " | Some term2 -> term_pp term2)
205 | We_need_to_prove (_, term, ident, term1) -> "we need to prove" ^ term_pp term ^ (match ident with None -> "" | Some ident -> "(" ^ ident ^ ")") ^ (match term1 with None -> " " | Some term1 -> term_pp term1)
206 | We_proceed_by_cases_on (_, term, term1) -> "we proceed by cases on" ^ term_pp term ^ "to prove" ^ term_pp term1
207 | We_proceed_by_induction_on (_, term, term1) -> "we proceed by induction on" ^ term_pp term ^ "to prove" ^ term_pp term1
208 | Byinduction (_, term, ident) -> "by induction hypothesis we know" ^ term_pp term ^ "(" ^ ident ^ ")"
209 | Thesisbecomes (_, term) -> "the thesis becomes " ^ term_pp term
210 | ExistsElim (_, just, ident, term, ident1, term1) -> pp_just ~term_pp just ^ "let " ^ ident ^ ":" ^ term_pp term ^ "such that " ^ lazy_term_pp term1 ^ "(" ^ ident1 ^ ")"
211 | AndElim (_, just, ident1, term1, ident2, term2) -> pp_just ~term_pp just ^ "we have " ^ term_pp term1 ^ " (" ^ ident1 ^ ") " ^ "and " ^ term_pp term2 ^ " (" ^ ident2 ^ ")"
212 | RewritingStep (_, term, term1, term2, cont) ->
215 | Some (None,term) -> "conclude " ^ term_pp term
216 | Some (Some name,term) ->
217 "obtain (" ^ name ^ ") " ^ term_pp term)
221 | `Auto params -> pp_auto_params ~term_pp params
222 | `Term term2 -> " exact " ^ term_pp term2
224 | `SolveWith term -> " using " ^ term_pp term)
225 ^ (if cont then " done" else "")
226 | Case (_, id, args) ->
229 (List.map (function (id,term) -> "(" ^ id ^ ": " ^ term_pp term ^ ")")
233 and pp_tactics ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~sep tacs =
235 (List.map (pp_tactic ~map_unicode_to_tex ~lazy_term_pp ~term_pp) tacs)
237 let pp_search_kind = function
238 | `Locate -> "locate"
242 | `Instance -> "instance"
244 let pp_arg ~term_pp arg =
245 let s = term_pp arg in
246 if s = "" || (s.[0] = '(' && s.[String.length s - 1] = ')') then
247 (* _nice_ heuristic *)
252 let pp_macro ~term_pp ~lazy_term_pp =
253 let term_pp = pp_arg ~term_pp in
254 let style_pp = function
256 | Procedural None -> "procedural "
257 | Procedural (Some i) -> Printf.sprintf "procedural %u " i
259 let prefix_pp prefix =
260 if prefix = "" then "" else Printf.sprintf " \"%s\"" prefix
262 let flavour_pp = function
264 | Some `Definition -> " as definition"
265 | Some `MutualDefinition -> " as mutual"
266 | Some `Fact -> " as fact"
267 | Some `Lemma -> " as lemma"
268 | Some `Remark -> " as remark"
269 | Some `Theorem -> " as theorem"
270 | Some `Variant -> " as variant"
271 | Some `Axiom -> " as axiom"
273 let pp_reduction_kind = pp_reduction_kind ~term_pp:lazy_term_pp in
276 | WInstance (_, term) -> "whelp instance " ^ term_pp term
277 | WHint (_, t) -> "whelp hint " ^ term_pp t
278 | WLocate (_, s) -> "whelp locate \"" ^ s ^ "\""
279 | WElim (_, t) -> "whelp elim " ^ term_pp t
280 | WMatch (_, term) -> "whelp match " ^ term_pp term
282 | Eval (_, kind, term) ->
283 Printf.sprintf "eval %s on %s" (pp_reduction_kind kind) (term_pp term)
284 | Check (_, term) -> Printf.sprintf "check %s" (term_pp term)
285 | Hint (_, true) -> "hint rewrite"
286 | Hint (_, false) -> "hint"
287 | AutoInteractive (_,params) -> "auto " ^ pp_auto_params ~term_pp params
288 | Inline (_, style, suri, prefix, flavour) ->
289 Printf.sprintf "inline %s\"%s\"%s%s" (style_pp style) suri (prefix_pp prefix) (flavour_pp flavour)
291 let pp_associativity = function
292 | Gramext.LeftA -> "left associative"
293 | Gramext.RightA -> "right associative"
294 | Gramext.NonA -> "non associative"
296 let pp_precedence i = Printf.sprintf "with precedence %d" i
298 let pp_dir_opt = function
300 | Some `LeftToRight -> "> "
301 | Some `RightToLeft -> "< "
303 let pp_default what uris =
304 Printf.sprintf "default \"%s\" %s" what
305 (String.concat " " (List.map UriManager.string_of_uri uris))
307 let pp_coercion ~term_pp t do_composites arity saturations=
308 Printf.sprintf "coercion %s %d %d %s"
309 (term_pp t) arity saturations
310 (if do_composites then "" else "nocomposites")
312 let pp_command ~term_pp ~obj_pp = function
313 | Index (_,_,uri) -> "Indexing " ^ UriManager.string_of_uri uri
314 | Coercion (_, t, do_composites, i, j) ->
315 pp_coercion ~term_pp t do_composites i j
316 | PreferCoercion (_,t) ->
317 "prefer coercion " ^ term_pp t
318 | UnificationHint (_,t) ->
319 "unification hint " ^ term_pp t
320 | Default (_,what,uris) -> pp_default what uris
322 | Include (_,path) -> "include \"" ^ path ^ "\""
323 | Obj (_,obj) -> obj_pp obj
325 | Relation (_,id,a,aeq,refl,sym,trans) ->
326 "relation " ^ term_pp aeq ^ " on " ^ term_pp a ^
328 Some r -> " reflexivity proved by " ^ term_pp r
331 Some r -> " symmetry proved by " ^ term_pp r
334 Some r -> " transitivity proved by " ^ term_pp r
336 | Print (_,s) -> "print " ^ s
337 | Set (_, name, value) -> Printf.sprintf "set \"%s\" \"%s\"" name value
339 let pp_punctuation_tactical ~term_pp ~lazy_term_pp =
345 | Pos (_, i) -> Printf.sprintf "%s:" (String.concat "," (List.map string_of_int i))
349 let pp_non_punctuation_tactical ~term_pp ~lazy_term_pp =
351 | Focus (_, goals) ->
352 Printf.sprintf "focus %s" (String.concat " " (List.map string_of_int goals))
353 | Unfocus _ -> "unfocus"
356 let pp_executable ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp =
358 | Macro (_, macro) -> pp_macro ~term_pp ~lazy_term_pp macro ^ "."
359 | Tactic (_, Some tac, punct) ->
360 pp_tactic ~map_unicode_to_tex ~lazy_term_pp ~term_pp tac
361 ^ pp_punctuation_tactical ~lazy_term_pp ~term_pp punct
362 | Tactic (_, None, punct) ->
363 pp_punctuation_tactical ~lazy_term_pp ~term_pp punct
364 | NonPunctuationTactical (_, tac, punct) ->
365 pp_non_punctuation_tactical ~lazy_term_pp ~term_pp tac
366 ^ pp_punctuation_tactical ~lazy_term_pp ~term_pp punct
367 | Command (_, cmd) -> pp_command ~term_pp ~obj_pp cmd ^ "."
369 let pp_comment ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp =
371 | Note (_,"") -> Printf.sprintf "\n"
372 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
374 Printf.sprintf "\n(** %s. **)" (pp_executable ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp code)
376 let pp_statement ~term_pp ~lazy_term_pp ~obj_pp =
378 | Executable (_, ex) -> pp_executable ~lazy_term_pp ~term_pp ~obj_pp ex
379 | Comment (_, c) -> pp_comment ~term_pp ~lazy_term_pp ~obj_pp c