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 -> "exact " ^ NotationPp.pp_term status term
64 | `Auto params -> pp_auto_params params status
67 let rec pp_ntactic status ~map_unicode_to_tex =
68 let pp_tactic_pattern = pp_tactic_pattern ~map_unicode_to_tex in
70 | NApply (_,t) -> "@" ^ NotationPp.pp_term status t
71 | NSmartApply (_,t) -> "fixme"
72 | NAuto (_,(None,flgs)) ->
74 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
75 | NAuto (_,(Some l,flgs)) ->
76 "nautobatch" ^ " by " ^
77 (String.concat "," (List.map (NotationPp.pp_term status) l)) ^
78 String.concat " " (List.map (fun a,b -> a ^ "=" ^ b) flgs)
79 | NCases (_,what,where) -> "ncases " ^ NotationPp.pp_term status what ^
80 "...to be implemented..." ^ " " ^ "...to be implemented..."
81 | NConstructor (_,None,l) -> "@ " ^
82 String.concat " " (List.map (NotationPp.pp_term status) l)
83 | NConstructor (_,Some x,l) -> "@" ^ string_of_int x ^ " " ^
84 String.concat " " (List.map (NotationPp.pp_term status) l)
85 | NCase1 (_,n) -> "*" ^ n ^ ":"
86 | NChange (_,what,wwhat) -> "nchange " ^ "...to be implemented..." ^
87 " with " ^ NotationPp.pp_term status wwhat
88 | NCut (_,t) -> "ncut " ^ NotationPp.pp_term status t
89 (*| NDiscriminate (_,t) -> "ndiscriminate " ^ NotationPp.pp_term status t
90 | NSubst (_,t) -> "nsubst " ^ NotationPp.pp_term status t *)
91 | NClear (_,l) -> "nclear " ^ String.concat " " l
92 | NDestruct (_,dom,skip) -> "ndestruct ..."
93 | NElim (_,what,where) -> "nelim " ^ NotationPp.pp_term status what ^
94 "...to be implemented..." ^ " " ^ "...to be implemented..."
96 | NIntro (_,n) -> "#" ^ n
97 | NIntros (_,l) -> "#" ^ String.concat " " l
98 | NInversion (_,what,where) -> "ninversion " ^ NotationPp.pp_term status what ^
99 "...to be implemented..." ^ " " ^ "...to be implemented..."
100 | NLApply (_,t) -> "lapply " ^ NotationPp.pp_term status t
101 | NRewrite (_,dir,n,where) -> "nrewrite " ^
102 (match dir with `LeftToRight -> ">" | `RightToLeft -> "<") ^
103 " " ^ NotationPp.pp_term status n ^ " " ^ pp_tactic_pattern status where
104 | NReduce _ | NGeneralize _ | NLetIn _ | NAssert _ -> "TO BE IMPLEMENTED"
106 | NSemicolon _ -> ";"
109 | NPos (_, l) -> String.concat "," (List.map string_of_int l)^ ":"
110 | NPosbyname (_, s) -> s ^ ":"
111 | NWildcard _ -> "*:"
114 Printf.sprintf "focus %s"
115 (String.concat " " (List.map string_of_int l))
116 | NUnfocus _ -> "unfocus"
118 | NTry (_,tac) -> "ntry " ^ pp_ntactic status ~map_unicode_to_tex tac
119 | NAssumption _ -> "nassumption"
121 "(" ^ String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) l)^ ")"
122 | NRepeat (_,t) -> "nrepeat " ^ pp_ntactic status ~map_unicode_to_tex t
123 | Assume (_, ident, term, term1) -> "assume" ^ ident ^ ":" ^ NotationPp.pp_term status term ^
124 (match term1 with None -> " " | Some t1 -> " that is eqivalent to " ^ NotationPp.pp_term status t1)
125 | Suppose (_,term,ident,term1) -> "suppose" ^ NotationPp.pp_term status term ^ "(" ^ ident ^ ")" ^ (match
126 term1 with None -> " " | Some t -> " that is equivalent to " ^ NotationPp.pp_term status t)
127 | By_just_we_proved (_, just, term1, ident, term2) -> pp_just status just ^ "we proved" ^
128 NotationPp.pp_term status term1 ^ (match ident with None -> "" | Some ident -> "(" ^ident^ ")") ^ (match
129 term2 with None -> " " | Some term2 -> " that is equivalent to " ^ NotationPp.pp_term status term2)
130 | We_need_to_prove (_,term,ident,t) -> "we need to prove" ^ NotationPp.pp_term status term ^
131 (match ident with None -> " " | Some id -> "(" ^ id ^ ")") ^ (match t with None -> "" | Some t ->
132 " or equivalently " ^ (NotationPp.pp_term status t))
133 | BetaRewritingStep (_,t) -> "or equivalently " ^ (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 term2
139 ^ " (" ^ ident2 ^ ")"
140 | Thesisbecomes (_, t, t1) -> "the thesis becomes " ^ NotationPp.pp_term status t ^
141 (match t1 with None -> "" | Some t1 -> " or equivalently " ^
142 NotationPp.pp_term status
144 | RewritingStep (_, rhs, just, cont) ->
146 NotationPp.pp_term status rhs ^
148 | `Auto params -> pp_auto_params params status
149 | `Term t -> " exact " ^ NotationPp.pp_term status t
151 | `SolveWith t -> " using " ^ NotationPp.pp_term status t)
152 ^ (if cont then " done" else "")
153 | Obtain (_,id,t1) -> "obtain (" ^ id ^ ")" ^ NotationPp.pp_term status t1
154 | Conclude (_,t1) -> "conclude " ^ NotationPp.pp_term status t1
155 | We_proceed_by_cases_on (_, term, term1) -> "we proceed by cases on" ^ NotationPp.pp_term status term ^ "to prove" ^ NotationPp.pp_term status term1
156 | We_proceed_by_induction_on (_, term, term1) -> "we proceed by induction on" ^ NotationPp.pp_term status term ^ "to prove" ^ NotationPp.pp_term status term1
157 | Byinduction (_, term, ident) -> "by induction hypothesis we know" ^ NotationPp.pp_term status term ^ "(" ^ ident ^ ")"
158 | Case (_, id, args) ->
161 (List.map (function (id,term) -> "(" ^ id ^ ": " ^ NotationPp.pp_term status term ^ ")")
165 let pp_nmacro status = function
166 | NCheck (_, term) -> Printf.sprintf "ncheck %s" (NotationPp.pp_term status term)
167 | Screenshot (_, name) -> Printf.sprintf "screenshot \"%s\"" name
170 let pp_l1_pattern = NotationPp.pp_term
171 let pp_l2_pattern = NotationPp.pp_term
173 let pp_alias = function
174 | Ident_alias (id, uri) -> sprintf "alias id \"%s\" = \"%s\"." id uri
175 | Symbol_alias (symb, instance, desc) ->
176 sprintf "alias symbol \"%s\" %s= \"%s\"."
178 (if instance=0 then "" else "(instance "^ string_of_int instance ^ ") ")
180 | Number_alias (instance,desc) ->
181 sprintf "alias num (instance %d) = \"%s\"." instance desc
183 let pp_associativity = function
184 | Gramext.LeftA -> "left associative"
185 | Gramext.RightA -> "right associative"
186 | Gramext.NonA -> "non associative"
188 let pp_precedence i = sprintf "with precedence %d" i
190 let pp_argument_pattern = function
191 | NotationPt.IdentArg (eta_depth, name) ->
192 let eta_buf = Buffer.create 5 in
193 for i = 1 to eta_depth do
194 Buffer.add_string eta_buf "\\eta."
196 sprintf "%s%s" (Buffer.contents eta_buf) name
198 let pp_interpretation dsc symbol arg_patterns cic_appl_pattern =
199 sprintf "interpretation \"%s\" '%s %s = %s."
201 (String.concat " " (List.map pp_argument_pattern arg_patterns))
202 (NotationPp.pp_cic_appl_pattern cic_appl_pattern)
204 let pp_dir_opt = function
206 | Some `LeftToRight -> "> "
207 | Some `RightToLeft -> "< "
209 let pp_notation status dir_opt l1_pattern assoc prec l2_pattern =
210 sprintf "notation %s\"%s\" %s %s for %s."
212 (pp_l1_pattern status l1_pattern)
213 (pp_associativity assoc)
215 (pp_l2_pattern status l2_pattern)
217 let pp_ncommand status = function
218 | UnificationHint (_,t, n) ->
219 "unification hint " ^ string_of_int n ^ " " ^ NotationPp.pp_term status t
220 | NDiscriminator (_,_)
221 | NInverter (_,_,_,_,_)
222 | NUnivConstraint (_) -> "not supported"
223 | NCoercion (_) -> "not supported"
224 | NObj (_,obj,index) ->
225 (if not index then "-" else "") ^
226 NotationPp.pp_obj (NotationPp.pp_term status) obj
227 | NQed (_,true) -> "qed"
228 | NQed (_,false) -> "qed-"
229 | NCopy (_,name,uri,map) ->
230 "copy " ^ name ^ " from " ^ NUri.string_of_uri uri ^ " with " ^
231 String.concat " and "
233 (fun (a,b) -> NUri.string_of_uri a ^ " ↦ " ^ NUri.string_of_uri b)
235 | Include (_,mode,path) -> (* not precise, since path is absolute *)
236 if mode = WithPreferences then
237 "include \"" ^ path ^ "\""
239 "include' \"" ^ path ^ "\""
240 | Alias (_,s) -> pp_alias s
241 | Interpretation (_, dsc, (symbol, arg_patterns), cic_appl_pattern) ->
242 pp_interpretation dsc symbol arg_patterns cic_appl_pattern
243 | Notation (_, dir_opt, l1_pattern, assoc, prec, l2_pattern) ->
244 pp_notation status dir_opt l1_pattern assoc prec l2_pattern
247 let pp_executable status ~map_unicode_to_tex =
249 | NMacro (_, macro) -> pp_nmacro status macro ^ "."
250 | NTactic (_,tacl) ->
251 String.concat " " (List.map (pp_ntactic status ~map_unicode_to_tex) tacl)
252 | NCommand (_, cmd) -> pp_ncommand status cmd ^ "."
254 let pp_comment status ~map_unicode_to_tex =
256 | Note (_,"") -> Printf.sprintf "\n"
257 | Note (_,str) -> Printf.sprintf "\n(* %s *)" str
259 Printf.sprintf "\n(** %s. **)" (pp_executable status ~map_unicode_to_tex code)
261 let pp_statement status =
263 | Executable (_, ex) -> pp_executable status ex
264 | Comment (_, c) -> pp_comment status c