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/
31 let tactical_terminator = ""
32 let tactic_terminator = tactical_terminator
33 let command_terminator = tactical_terminator
35 let pp_tactic_pattern status ~map_unicode_to_tex (what, hyp, goal) =
36 if what = None && hyp = [] && goal = None then "" else
40 | Some t -> Printf.sprintf "in match (%s) " (NotationPp.pp_term status t) in
43 (List.map (fun (name, p) -> Printf.sprintf "%s:(%s)" name
44 (NotationPp.pp_term status p)) hyp) in
49 let vdash = if map_unicode_to_tex then "\\vdash" else "⊢" in
50 Printf.sprintf "%s (%s)" vdash (NotationPp.pp_term status t)
52 Printf.sprintf "%sin %s%s" what_text hyp_text goal_text
54 let pp_auto_params params status =
56 | (None,flags) -> String.concat " " (List.map (fun (a,b) -> a ^ "=" ^ b) flags)
57 | (Some l,flags) -> (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
58 String.concat " " (List.map (fun (a,b) -> a ^ "=" ^ b) flags)
61 let pp_just status just =
63 `Term term -> "using (" ^ NotationPp.pp_term status term ^ ") "
67 | params -> "by " ^ pp_auto_params params status ^ " "
70 let rec pp_ntactic status ~map_unicode_to_tex =
71 let pp_tactic_pattern = pp_tactic_pattern ~map_unicode_to_tex in
73 | NApply (_,t) -> "@" ^ NotationPp.pp_term status t
74 | NSmartApply (_,_t) -> "fixme"
75 | NAuto (_,(None,flgs)) ->
77 String.concat " " (List.map (fun (a,b) -> a ^ "=" ^ b) flgs)
78 | NAuto (_,(Some l,flgs)) ->
79 "nautobatch" ^ " by " ^
80 (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
81 String.concat " " (List.map (fun (a,b) -> a ^ "=" ^ b) flgs)
82 | NCases (_,what,_where) -> "ncases " ^ NotationPp.pp_term status what ^
83 "...to be implemented..." ^ " " ^ "...to be implemented..."
84 | NConstructor (_,None,l) -> "@ " ^
85 String.concat " " (List.map (NotationPp.pp_term status) l)
86 | NConstructor (_,Some x,l) -> "@" ^ string_of_int x ^ " " ^
87 String.concat " " (List.map (NotationPp.pp_term status) l)
88 | NCase1 (_,n) -> "*" ^ n ^ ":"
89 | NChange (_,_what,wwhat) -> "nchange " ^ "...to be implemented..." ^
90 " with " ^ NotationPp.pp_term status wwhat
91 | NCut (_,t) -> "ncut " ^ NotationPp.pp_term status t
92 (*| NDiscriminate (_,t) -> "ndiscriminate " ^ NotationPp.pp_term status t
93 | NSubst (_,t) -> "nsubst " ^ NotationPp.pp_term status t *)
94 | NClear (_,l) -> "nclear " ^ String.concat " " l
95 | NDestruct (_,_dom,_skip) -> "ndestruct ..."
96 | NElim (_,what,_where) -> "nelim " ^ NotationPp.pp_term status what ^
97 "...to be implemented..." ^ " " ^ "...to be implemented..."
99 | NIntro (_,n) -> "#" ^ n
100 | NIntros (_,l) -> "#" ^ String.concat " " l
101 | NInversion (_,what,_where) -> "ninversion " ^ NotationPp.pp_term status what ^
102 "...to be implemented..." ^ " " ^ "...to be implemented..."
103 | NLApply (_,t) -> "lapply " ^ NotationPp.pp_term status t
104 | NRewrite (_,dir,n,where) -> "nrewrite " ^
105 (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
106 " " ^ NotationPp.pp_term status n ^ " " ^ pp_tactic_pattern status where
107 | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
109 | NSemicolon _ -> ";"
112 | NPos (_, l) -> String.concat "," (List.map string_of_int l)^ ":"
113 | NPosbyname (_, s) -> s ^ ":"
114 | NWildcard _ -> "*:"
117 Printf.sprintf "focus %s"
118 (String.concat " " (List.map string_of_int l))
119 | NUnfocus _ -> "unfocus"
121 | NTry (_,tac) -> "ntry " ^ pp_ntactic status ~map_unicode_to_tex tac
122 | NAssumption _ -> "nassumption"
124 "(" ^ String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) l)^ ")"
125 | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic status ~map_unicode_to_tex t
126 | Assume (_, ident, term) -> "assume " ^ ident ^ ":(" ^ (NotationPp.pp_term status term) ^ ")"
127 | Suppose (_,term,ident) -> "suppose (" ^ (NotationPp.pp_term status term) ^ ") (" ^ ident ^ ") "
128 | By_just_we_proved (_, just, term1, ident) -> pp_just status just ^ " we proved (" ^
129 (NotationPp.pp_term status term1) ^ ")" ^ (match ident with
130 None -> "" | Some ident -> "(" ^ident^ ")")
131 | We_need_to_prove (_,term,ident) -> "we need to prove (" ^ (NotationPp.pp_term status term) ^ ") " ^
132 (match ident with None -> "" | Some id -> "(" ^ id ^ ")")
133 | BetaRewritingStep (_,t) -> "that is equivalent to (" ^ (NotationPp.pp_term status t) ^ ")"
134 | Bydone (_, just) -> pp_just status just ^ "done"
135 | ExistsElim (_, just, ident, term, term1, ident1) -> pp_just status just ^ "let " ^ ident ^ ": ("
136 ^ (NotationPp.pp_term status term) ^ ") such that (" ^ (NotationPp.pp_term status term1) ^ ") (" ^ ident1 ^ ")"
137 | AndElim (_, just, term1, ident1, term2, ident2) -> pp_just status just ^ " we have (" ^
138 (NotationPp.pp_term status term1) ^ ") (" ^ ident1 ^ ") " ^ "and (" ^ (NotationPp.pp_term status
140 ^ ") (" ^ ident2 ^ ")"
141 | Thesisbecomes (_, t) -> "the thesis becomes (" ^ (NotationPp.pp_term status t) ^ ")"
142 | RewritingStep (_, rhs, just, cont) ->
144 (NotationPp.pp_term status rhs) ^ ")" ^
146 | `Auto params -> let s = pp_auto_params params status in
147 if s <> "" then " by " ^ s
149 | `Term t -> " exact (" ^ (NotationPp.pp_term status t) ^ ")"
151 | `SolveWith t -> " using (" ^ (NotationPp.pp_term status t) ^ ")"
153 ^ (if cont then " done" else "")
154 | Obtain (_,id,t1) -> "obtain (" ^ id ^ ")" ^ " (" ^ (NotationPp.pp_term status t1) ^ ")"
155 | Conclude (_,t1) -> "conclude (" ^ (NotationPp.pp_term status t1) ^ ")"
156 | We_proceed_by_cases_on (_, term, term1) -> "we proceed by cases on (" ^ NotationPp.pp_term
157 status term ^ ") to prove (" ^ NotationPp.pp_term status term1 ^ ")"
158 | We_proceed_by_induction_on (_, term, term1) -> "we proceed by induction on (" ^
159 NotationPp.pp_term status term ^ ") to prove (" ^ NotationPp.pp_term status term1 ^ ")"
160 | Byinduction (_, term, ident) -> "by induction hypothesis we know (" ^ NotationPp.pp_term status
161 term ^ ") (" ^ ident ^ ")"
162 | Case (_, id, args) ->
165 (List.map (function (id,term) -> "(" ^ id ^ ": (" ^ NotationPp.pp_term status term ^ "))")
167 | PrintStack _ -> "print_stack"
170 let pp_nmacro status = function
171 | NCheck (_, term) -> Printf.sprintf "ncheck %s" (NotationPp.pp_term status term)
172 | Screenshot (_, name) -> Printf.sprintf "screenshot \"%s\"" name
174 | NIntroGuess _ -> assert false (* TODO *)
177 let pp_l1_pattern = NotationPp.pp_term
178 let pp_l2_pattern = NotationPp.pp_term
180 let pp_alias = function
181 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"." id uri
182 | Symbol_alias (symb, instance, desc) ->
183 sprintf "alias symbol \"%s\" %s= \"%s\"."
185 (if instance=0 then "" else "(instance "^ string_of_int instance ^ ") ")
187 | Number_alias (instance,desc) ->
188 sprintf "alias num (instance %d) = \"%s\"." instance desc
190 let pp_associativity = function
191 | Gramext.LeftA -> "left associative"
192 | Gramext.RightA -> "right associative"
193 | Gramext.NonA -> "non associative"
195 let pp_precedence i = sprintf "with precedence %d" i
197 let pp_argument_pattern = function
198 | NotationPt.IdentArg (eta_depth, name) ->
199 let eta_buf = Buffer.create 5 in
200 for _i = 1 to eta_depth do
201 Buffer.add_string eta_buf "\\eta."
203 sprintf "%s%s" (Buffer.contents eta_buf) name
205 let pp_interpretation dsc symbol arg_patterns cic_appl_pattern =
206 sprintf "interpretation \"%s\" '%s %s = %s."
208 (String.concat " " (List.map pp_argument_pattern arg_patterns))
209 (NotationPp.pp_cic_appl_pattern cic_appl_pattern)
211 let pp_dir_opt = function
213 | Some `LeftToRight -> "> "
214 | Some `RightToLeft -> "< "
216 let pp_notation status dir_opt l1_pattern assoc prec l2_pattern =
217 sprintf "notation %s\"%s\" %s %s for %s."
219 (pp_l1_pattern status l1_pattern)
220 (pp_associativity assoc)
222 (pp_l2_pattern status l2_pattern)
224 let pp_ncommand status = function
225 | UnificationHint (_,t, n) ->
226 "unification hint " ^ string_of_int n ^ " " ^ NotationPp.pp_term status t
227 | NDiscriminator (_,_)
228 | NInverter (_,_,_,_,_)
229 | NUnivConstraint (_) -> "not supported"
230 | NCoercion (_) -> "not supported"
231 | NObj (_,obj,index) ->
232 (if not index then "-" else "") ^
233 NotationPp.pp_obj (NotationPp.pp_term status) obj
234 | NQed (_,true) -> "qed"
235 | NQed (_,false) -> "qed-"
236 | NCopy (_,name,uri,map) ->
237 "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^
238 String.concat " and "
240 (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b)
242 | Include (_,mode,path) -> (* not precise, since path is absolute *)
243 if mode = WithPreferences then
244 "include \"" ^ path ^ "\""
246 "include' \"" ^ path ^ "\""
247 | Alias (_,s) -> pp_alias s
248 | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
249 pp_interpretation dsc symbol arg_patterns cic_appl_pattern
250 | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
251 pp_notation status dir_opt l1_pattern assoc prec l2_pattern
254 let pp_executable status ~map_unicode_to_tex =
256 | NMacro (_, macro) -> pp_nmacro status macro ^ "."
257 | NTactic (_,tacl) ->
258 String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) tacl)
259 | NCommand (_, cmd) -> pp_ncommand status cmd ^ "."
261 let pp_comment status ~map_unicode_to_tex =
263 | Note (_,"") -> Printf.sprintf "\n"
264 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
266 Printf.sprintf "\n(** %s. **)" (pp_executable status ~map_unicode_to_tex code)
268 let pp_statement status =
270 | Executable (_, ex) -> pp_executable status ex
271 | Comment (_, c) -> pp_comment status c