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_ntactic ~map_unicode_to_tex =
93 let term_pp = CicNotationPp.pp_term in
94 let lazy_term_pp = fun _ -> assert false in
95 let pp_tactic_pattern =
96 pp_tactic_pattern ~map_unicode_to_tex ~lazy_term_pp ~term_pp in
98 | NApply (_,t) -> "napply " ^ CicNotationPp.pp_term t
99 | NCases (_,what,where) -> "ncases " ^ CicNotationPp.pp_term what ^
100 assert false ^ " " ^ assert false
101 | NCase1 (_,n) -> "*" ^ n ^ ":"
102 | NChange (_,what,wwhat) -> "nchange " ^ assert false ^
103 " with " ^ CicNotationPp.pp_term wwhat
104 | NElim (_,what,where) -> "nelim " ^ CicNotationPp.pp_term what ^
105 assert false ^ " " ^ assert false
107 | NIntro (_,n) -> "#" ^ n
108 | NRewrite (_,dir,n,where) -> "nrewrite " ^
109 (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
110 " " ^ CicNotationPp.pp_term n ^ " " ^ pp_tactic_pattern where
111 | NAuto (_,(l,flgs)) ->
113 (if l <> [] then (" by " ^
114 (String.concat "," (List.map CicNotationPp.pp_term l))) else "") ^
115 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
116 | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
118 | NSemicolon _ -> "##;"
121 | NPos (_, l) -> "##" ^String.concat "," (List.map string_of_int l)^ ":"
122 | NWildcard _ -> "##*:"
125 Printf.sprintf "##focus %s"
126 (String.concat " " (List.map string_of_int l))
127 | NUnfocus _ -> "##unfocus"
128 | NSkip _ -> "##skip"
129 | NTry (_,tac) -> "ntry " ^ pp_ntactic ~map_unicode_to_tex tac
130 | NAssumption _ -> "nassumption"
132 "(" ^ String.concat " " (List.map (pp_ntactic ~map_unicode_to_tex) l)^ ")"
133 | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic ~map_unicode_to_tex t
136 let rec pp_tactic ~map_unicode_to_tex ~term_pp ~lazy_term_pp =
137 let pp_terms = pp_terms ~term_pp in
138 let pp_tactics = pp_tactics ~map_unicode_to_tex ~term_pp ~lazy_term_pp in
139 let pp_reduction_kind = pp_reduction_kind ~term_pp in
140 let pp_tactic_pattern =
141 pp_tactic_pattern ~map_unicode_to_tex ~lazy_term_pp ~term_pp in
144 (* Higher order tactics *)
145 | Do (_, count, tac) ->
146 Printf.sprintf "do %d %s" count (pp_tactic tac)
147 | Repeat (_, tac) -> "repeat " ^ pp_tactic tac
148 | Seq (_, tacs) -> pp_tactics ~sep:"; " tacs
149 | Then (_, tac, tacs) ->
150 Printf.sprintf "%s; [%s]" (pp_tactic tac)
151 (pp_tactics ~sep:" | " tacs)
153 Printf.sprintf "tries [%s]" (pp_tactics ~sep:" | " tacs)
154 | Try (_, tac) -> "try " ^ pp_tactic tac
156 Printf.sprintf "solve [%s]" (pp_tactics ~sep:" | " tac)
157 | Progress (_, tac) -> "progress " ^ pp_tactic tac
158 (* First order tactics *)
159 | Absurd (_, term) -> "absurd" ^ term_pp term
160 | Apply (_, term) -> "apply " ^ term_pp term
161 | ApplyRule (_, term) -> "apply rule " ^ term_pp term
162 | ApplyP (_, term) -> "applyP " ^ term_pp term
163 | ApplyS (_, term, params) ->
164 "applyS " ^ term_pp term ^ pp_auto_params ~term_pp params
165 | AutoBatch (_,params) -> "autobatch " ^
166 pp_auto_params ~term_pp params
167 | Assumption _ -> "assumption"
168 | Cases (_, term, pattern, specs) ->
169 Printf.sprintf "cases %s %s%s"
171 (pp_tactic_pattern pattern)
172 (pp_intros_specs "names " specs)
173 | Change (_, where, with_what) ->
174 Printf.sprintf "change %s with %s" (pp_tactic_pattern where) (lazy_term_pp with_what)
175 | Clear (_,ids) -> Printf.sprintf "clear %s" (pp_hyps ids)
176 | ClearBody (_,id) -> Printf.sprintf "clearbody %s" (pp_hyps [id])
177 | Constructor (_,n) -> "constructor " ^ string_of_int n
178 | Compose (_,t1, t2, times, intro_specs) ->
179 Printf.sprintf "compose %s%s %s%s"
180 (if times > 0 then string_of_int times ^ " " else "")
181 (term_pp t1) (match t2 with None -> "" | Some t2 -> "with "^term_pp t2)
182 (pp_intros_specs " as " intro_specs)
183 | Contradiction _ -> "contradiction"
184 | Cut (_, ident, term) ->
185 "cut " ^ term_pp term ^
186 (match ident with None -> "" | Some id -> " as " ^ id)
187 | Decompose (_, names) ->
188 Printf.sprintf "decompose%s"
189 (pp_intros_specs "names " (None, names))
190 | Demodulate (_, params) -> "demodulate " ^ pp_auto_params ~term_pp params
191 | Destruct (_, None) -> "destruct"
192 | Destruct (_, Some terms) -> "destruct " ^ pp_terms terms
193 | Elim (_, what, using, pattern, specs) ->
194 Printf.sprintf "elim %s%s %s%s"
196 (match using with None -> "" | Some term -> " using " ^ term_pp term)
197 (pp_tactic_pattern pattern)
198 (pp_intros_specs "names " specs)
199 | ElimType (_, term, using, specs) ->
200 Printf.sprintf "elim type %s%s%s"
202 (match using with None -> "" | Some term -> " using " ^ term_pp term)
203 (pp_intros_specs "names " specs)
204 | Exact (_, term) -> "exact " ^ term_pp term
205 | Exists _ -> "exists"
206 | Fold (_, kind, term, pattern) ->
207 Printf.sprintf "fold %s %s %s" (pp_reduction_kind kind)
208 (lazy_term_pp term) (pp_tactic_pattern pattern)
209 | FwdSimpl (_, hyp, names) ->
210 Printf.sprintf "fwd %s%s" hyp (pp_intros_specs "names " (None, names))
211 | Generalize (_, pattern, ident) ->
212 Printf.sprintf "generalize %s%s" (pp_tactic_pattern pattern)
213 (match ident with None -> "" | Some id -> " as " ^ id)
215 | Fourier _ -> "fourier"
217 | Intros (_, specs) -> Printf.sprintf "intros%s" (pp_intros_specs "" specs)
218 | Inversion (_, term) -> "inversion " ^ term_pp term
219 | LApply (_, linear, level_opt, terms, term, ident_opt) ->
220 Printf.sprintf "lapply %s%s%s%s%s"
221 (if linear then " linear " else "")
222 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
224 (match terms with [] -> "" | _ -> " to " ^ pp_terms terms)
225 (match ident_opt with None -> "" | Some ident -> " as " ^ ident)
227 | LetIn (_, term, ident) ->
228 Printf.sprintf "letin %s \\def %s" ident (term_pp term)
229 | Reduce (_, kind, pat) ->
230 Printf.sprintf "%s %s" (pp_reduction_kind kind) (pp_tactic_pattern pat)
231 | Reflexivity _ -> "reflexivity"
232 | Replace (_, pattern, t) ->
233 Printf.sprintf "replace %s with %s" (pp_tactic_pattern pattern) (lazy_term_pp t)
234 | Rewrite (_, pos, t, pattern, names) ->
235 Printf.sprintf "rewrite %s %s %s%s"
236 (if pos = `LeftToRight then ">" else "<")
238 (pp_tactic_pattern pattern)
239 (if names = [] then "" else " as " ^ pp_idents names)
243 | Symmetry _ -> "symmetry"
244 | Transitivity (_, term) -> "transitivity " ^ term_pp term
245 (* Tattiche Aggiunte *)
246 | Assume (_, ident , term) -> "assume" ^ ident ^ ":" ^ term_pp term
247 | Suppose (_, term, ident,term1) -> "suppose" ^ term_pp term ^ "(" ^ ident ^ ")" ^ (match term1 with None -> " " | Some term1 -> term_pp term1)
248 | Bydone (_, just) -> pp_just ~term_pp just ^ "done"
249 | 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^ ")") ^
250 (match term2 with None -> " " | Some term2 -> term_pp term2)
251 | 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)
252 | We_proceed_by_cases_on (_, term, term1) -> "we proceed by cases on" ^ term_pp term ^ "to prove" ^ term_pp term1
253 | We_proceed_by_induction_on (_, term, term1) -> "we proceed by induction on" ^ term_pp term ^ "to prove" ^ term_pp term1
254 | Byinduction (_, term, ident) -> "by induction hypothesis we know" ^ term_pp term ^ "(" ^ ident ^ ")"
255 | Thesisbecomes (_, term) -> "the thesis becomes " ^ term_pp term
256 | ExistsElim (_, just, ident, term, ident1, term1) -> pp_just ~term_pp just ^ "let " ^ ident ^ ":" ^ term_pp term ^ "such that " ^ lazy_term_pp term1 ^ "(" ^ ident1 ^ ")"
257 | AndElim (_, just, ident1, term1, ident2, term2) -> pp_just ~term_pp just ^ "we have " ^ term_pp term1 ^ " (" ^ ident1 ^ ") " ^ "and " ^ term_pp term2 ^ " (" ^ ident2 ^ ")"
258 | RewritingStep (_, term, term1, term2, cont) ->
261 | Some (None,term) -> "conclude " ^ term_pp term
262 | Some (Some name,term) ->
263 "obtain (" ^ name ^ ") " ^ term_pp term)
267 | `Auto params -> pp_auto_params ~term_pp params
268 | `Term term2 -> " exact " ^ term_pp term2
270 | `SolveWith term -> " using " ^ term_pp term)
271 ^ (if cont then " done" else "")
272 | Case (_, id, args) ->
275 (List.map (function (id,term) -> "(" ^ id ^ ": " ^ term_pp term ^ ")")
279 and pp_tactics ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~sep tacs =
281 (List.map (pp_tactic ~map_unicode_to_tex ~lazy_term_pp ~term_pp) tacs)
283 let pp_search_kind = function
284 | `Locate -> "locate"
288 | `Instance -> "instance"
290 let pp_arg ~term_pp arg =
291 let s = term_pp arg in
292 if s = "" || (s.[0] = '(' && s.[String.length s - 1] = ')') then
293 (* _nice_ heuristic *)
298 let pp_macro ~term_pp ~lazy_term_pp =
299 let term_pp = pp_arg ~term_pp in
300 let flavour_pp = function
301 | `Definition -> "definition"
304 | `Remark -> "remark"
305 | `Theorem -> "theorem"
306 | `Variant -> "variant"
308 | `MutualDefinition -> assert false
310 let pp_inline_params l =
311 let pp_param = function
312 | IPPrefix prefix -> "prefix = \"" ^ prefix ^ "\""
313 | IPAs flavour -> flavour_pp flavour
314 | IPCoercions -> "coercions"
315 | IPDebug debug -> "debug = " ^ string_of_int debug
316 | IPProcedural -> "procedural"
317 | IPNoDefaults -> "nodefaults"
318 | IPDepth depth -> "depth = " ^ string_of_int depth
319 | IPLevel level -> "level = " ^ string_of_int level
320 | IPComments -> "comments"
323 let s = String.concat " " (List.map pp_param l) in
324 if s = "" then s else " " ^ s
326 let pp_reduction_kind = pp_reduction_kind ~term_pp:lazy_term_pp in
329 | WInstance (_, term) -> "whelp instance " ^ term_pp term
330 | WHint (_, t) -> "whelp hint " ^ term_pp t
331 | WLocate (_, s) -> "whelp locate \"" ^ s ^ "\""
332 | WElim (_, t) -> "whelp elim " ^ term_pp t
333 | WMatch (_, term) -> "whelp match " ^ term_pp term
335 | Eval (_, kind, term) ->
336 Printf.sprintf "eval %s on %s" (pp_reduction_kind kind) (term_pp term)
337 | Check (_, term) -> Printf.sprintf "check %s" (term_pp term)
338 | Hint (_, true) -> "hint rewrite"
339 | Hint (_, false) -> "hint"
340 | AutoInteractive (_,params) -> "auto " ^ pp_auto_params ~term_pp params
341 | Inline (_, suri, params) ->
342 Printf.sprintf "inline \"%s\"%s" suri (pp_inline_params params)
344 let pp_associativity = function
345 | Gramext.LeftA -> "left associative"
346 | Gramext.RightA -> "right associative"
347 | Gramext.NonA -> "non associative"
349 let pp_precedence i = Printf.sprintf "with precedence %d" i
351 let pp_default what uris =
352 Printf.sprintf "default \"%s\" %s" what
353 (String.concat " " (List.map UriManager.string_of_uri uris))
355 let pp_coercion ~term_pp t do_composites arity saturations=
356 Printf.sprintf "coercion %s %d %d %s"
357 (term_pp t) arity saturations
358 (if do_composites then "" else "nocomposites")
360 let pp_ncommand = function
361 | UnificationHint (_,t, n) ->
362 "unification hint " ^ string_of_int n ^ " " ^ CicNotationPp.pp_term t
364 | NUnivConstraint (_) -> "not supported"
365 | NCoercion (_) -> "not supported"
367 | NCopy (_,name,uri,map) ->
368 "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^
369 String.concat " and "
371 (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b)
375 let pp_command ~term_pp ~obj_pp = function
376 | Index (_,_,uri) -> "Indexing " ^ UriManager.string_of_uri uri
377 | Select (_,uri) -> "Selecting " ^ UriManager.string_of_uri uri
378 | Coercion (_, t, do_composites, i, j) ->
379 pp_coercion ~term_pp t do_composites i j
380 | PreferCoercion (_,t) ->
381 "prefer coercion " ^ term_pp t
382 | Inverter (_,n,ty,params) ->
383 "inverter " ^ n ^ " for " ^ term_pp ty ^ " " ^ List.fold_left (fun acc x -> acc ^ (match x with true -> "%" | _ -> "?")) "" params
384 | Default (_,what,uris) -> pp_default what uris
386 | Include (_,true,`OldAndNew,path) -> "include \"" ^ path ^ "\""
387 | Include (_,false,`OldAndNew,path) -> "include source \"" ^ path ^ "\""
388 | Include (_,_,`New,path) -> "RECURSIVELY INCLUDING " ^ path
389 | Obj (_,obj) -> obj_pp obj
391 | Relation (_,id,a,aeq,refl,sym,trans) ->
392 "relation " ^ term_pp aeq ^ " on " ^ term_pp a ^
394 Some r -> " reflexivity proved by " ^ term_pp r
397 Some r -> " symmetry proved by " ^ term_pp r
400 Some r -> " transitivity proved by " ^ term_pp r
402 | Print (_,s) -> "print " ^ s
403 | Set (_, name, value) -> Printf.sprintf "set \"%s\" \"%s\"" name value
404 | Pump (_) -> "not supported"
406 let pp_punctuation_tactical =
412 | Pos (_, i) -> Printf.sprintf "%s:" (String.concat "," (List.map string_of_int i))
416 let pp_non_punctuation_tactical =
418 | Focus (_, goals) ->
419 Printf.sprintf "focus %s" (String.concat " " (List.map string_of_int goals))
420 | Unfocus _ -> "unfocus"
423 let pp_executable ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp =
425 | Macro (_, macro) -> pp_macro ~term_pp ~lazy_term_pp macro ^ "."
426 | Tactic (_, Some tac, punct) ->
427 pp_tactic ~map_unicode_to_tex ~term_pp ~lazy_term_pp tac
428 ^ pp_punctuation_tactical punct
429 | Tactic (_, None, punct) ->
430 pp_punctuation_tactical punct
431 | NTactic (_,tacl) ->
432 String.concat " " (List.map (pp_ntactic ~map_unicode_to_tex) tacl)
433 | NonPunctuationTactical (_, tac, punct) ->
434 pp_non_punctuation_tactical tac
435 ^ pp_punctuation_tactical punct
436 | Command (_, cmd) -> pp_command ~term_pp ~obj_pp cmd ^ "."
437 | NCommand (_, cmd) -> pp_ncommand cmd ^ "."
439 let pp_comment ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp =
441 | Note (_,"") -> Printf.sprintf "\n"
442 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
444 Printf.sprintf "\n(** %s. **)" (pp_executable ~map_unicode_to_tex ~term_pp ~lazy_term_pp ~obj_pp code)
446 let pp_statement ~term_pp ~lazy_term_pp ~obj_pp =
448 | Executable (_, ex) -> pp_executable ~lazy_term_pp ~term_pp ~obj_pp ex
449 | Comment (_, c) -> pp_comment ~term_pp ~lazy_term_pp ~obj_pp c