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/
32 let tactical_terminator = ""
33 let tactic_terminator = tactical_terminator
34 let command_terminator = tactical_terminator
36 let pp_idents idents = "[" ^ String.concat "; " idents ^ "]"
38 let pp_reduction_kind ~term_pp = function
39 | `Normalize -> "normalize"
41 | `Simpl -> "simplify"
42 | `Unfold (Some t) -> "unfold " ^ term_pp t
43 | `Unfold None -> "unfold"
46 let pp_tactic_pattern ~term_pp ~lazy_term_pp (what, hyp, goal) =
50 | Some t -> sprintf "in match (%s) " (lazy_term_pp t) in
53 (List.map (fun (name, p) -> sprintf "%s:(%s)" name (term_pp p)) hyp) in
57 | Some t -> sprintf "\\vdash (%s)" (term_pp t) in
58 sprintf "%sin %s%s" what_text hyp_text goal_text
60 let pp_intros_specs = function
62 | Some num, [] -> Printf.sprintf " names %i" num
63 | None, idents -> Printf.sprintf " names %s" (pp_idents idents)
64 | Some num, idents -> Printf.sprintf " names %i %s" num (pp_idents idents)
66 let terms_pp ~term_pp terms = String.concat ", " (List.map term_pp terms)
68 let opt_string_pp = function
70 | Some what -> what ^ " "
72 let rec pp_tactic ~term_pp ~lazy_term_pp =
73 let pp_reduction_kind = pp_reduction_kind ~term_pp in
74 let pp_tactic_pattern = pp_tactic_pattern ~lazy_term_pp ~term_pp in
76 | Absurd (_, term) -> "absurd" ^ term_pp term
77 | Apply (_, term) -> "apply " ^ term_pp term
78 | ApplyS (_, term, params) ->
79 "applyS " ^ term_pp term ^
81 (List.map (fun (k,v) -> if v <> "" then k ^ "=" ^ v else k) params)
82 | Auto (_,params) -> "auto " ^
84 (List.map (fun (k,v) -> if v <> "" then k ^ "=" ^ v else k) params)
85 | Assumption _ -> "assumption"
86 | Change (_, where, with_what) ->
87 sprintf "change %s with %s" (pp_tactic_pattern where) (lazy_term_pp with_what)
88 | Clear (_,ids) -> sprintf "clear %s" (pp_idents ids)
89 | ClearBody (_,id) -> sprintf "clearbody %s" id
90 | Constructor (_,n) -> "constructor " ^ string_of_int n
91 | Contradiction _ -> "contradiction"
92 | Cut (_, ident, term) ->
93 "cut " ^ term_pp term ^
94 (match ident with None -> "" | Some id -> " as " ^ id)
95 | Decompose (_, [], what, names) ->
96 sprintf "decompose %s%s" (opt_string_pp what) (pp_intros_specs (None, names))
97 | Decompose (_, types, what, names) ->
98 let to_ident = function
100 | Type _ -> assert false
102 let types = List.rev_map to_ident types in
103 sprintf "decompose %s %s%s" (pp_idents types) (opt_string_pp what) (pp_intros_specs (None, names))
104 | Demodulate _ -> "demodulate"
105 | Destruct (_, term) -> "destruct " ^ term_pp term
106 | Elim (_, term, using, num, idents) ->
107 sprintf "elim " ^ term_pp term ^
108 (match using with None -> "" | Some term -> " using " ^ term_pp term)
109 ^ pp_intros_specs (num, idents)
110 | ElimType (_, term, using, num, idents) ->
111 sprintf "elim type " ^ term_pp term ^
112 (match using with None -> "" | Some term -> " using " ^ term_pp term)
113 ^ pp_intros_specs (num, idents)
114 | Exact (_, term) -> "exact " ^ term_pp term
115 | Exists _ -> "exists"
116 | Fold (_, kind, term, pattern) ->
117 sprintf "fold %s %s %s" (pp_reduction_kind kind)
118 (lazy_term_pp term) (pp_tactic_pattern pattern)
119 | FwdSimpl (_, hyp, idents) ->
120 sprintf "fwd %s%s" hyp
121 (match idents with [] -> "" | idents -> " as " ^ pp_idents idents)
122 | Generalize (_, pattern, ident) ->
123 sprintf "generalize %s%s" (pp_tactic_pattern pattern)
124 (match ident with None -> "" | Some id -> " as " ^ id)
125 | Goal (_, n) -> "goal " ^ string_of_int n
127 | Fourier _ -> "fourier"
129 | Intros (_, None, []) -> "intros"
130 | Inversion (_, term) -> "inversion " ^ term_pp term
131 | Intros (_, num, idents) ->
133 (match num with None -> "" | Some num -> " " ^ string_of_int num)
134 (match idents with [] -> "" | idents -> " " ^ pp_idents idents)
135 | LApply (_, linear, level_opt, terms, term, ident_opt) ->
136 sprintf "lapply %s%s%s%s%s"
137 (if linear then " linear " else "")
138 (match level_opt with None -> "" | Some i -> " depth = " ^ string_of_int i ^ " ")
140 (match terms with [] -> "" | _ -> " to " ^ terms_pp ~term_pp terms)
141 (match ident_opt with None -> "" | Some ident -> " as " ^ ident)
143 | LetIn (_, term, ident) -> sprintf "let %s in %s" (term_pp term) ident
144 | Reduce (_, kind, pat) ->
145 sprintf "%s %s" (pp_reduction_kind kind) (pp_tactic_pattern pat)
146 | Reflexivity _ -> "reflexivity"
147 | Replace (_, pattern, t) ->
148 sprintf "replace %s with %s" (pp_tactic_pattern pattern) (lazy_term_pp t)
149 | Rewrite (_, pos, t, pattern) ->
150 sprintf "rewrite %s %s %s"
151 (if pos = `LeftToRight then ">" else "<")
153 (pp_tactic_pattern pattern)
158 | Symmetry _ -> "symmetry"
159 | Transitivity (_, term) -> "transitivity " ^ term_pp term
160 (* Tattiche Aggiunte *)
161 | Assume (_, ident , term) -> "assume" ^ ident ^ ":" ^ term_pp term
162 | Suppose (_, term, ident,term1) -> "suppose" ^ term_pp term ^ "(" ^ ident ^ ")" ^ (match term1 with None -> " " | Some term1 -> term_pp term1)
163 | Bydone (_, term) -> "by" ^ (match term with None -> "_" | Some term -> term_pp term) ^ "done"
164 | By_term_we_proved (_, term, term1, ident, term2) -> "by" ^ (match term with None -> "_" | Some term -> term_pp term) ^ "we proved" ^ term_pp term1 ^ (match ident with None -> "" | Some ident -> "(" ^ident^ ")") ^
165 (match term2 with None -> " " | Some term2 -> term_pp term2)
166 | 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)
167 | We_proceed_by_induction_on (_, term, term1) -> "we proceed by induction on" ^ term_pp term ^ "to prove" ^ term_pp term1
168 | Byinduction (_, term, ident) -> "by induction hypothesis we know" ^ term_pp term ^ "(" ^ ident ^ ")"
169 | Thesisbecomes (_, term) -> "the thesis becomes " ^ term_pp term
170 | ExistsElim (_, term0, ident, term, ident1, term1) -> "by " ^ term_pp term0 ^ "let " ^ ident ^ ":" ^ term_pp term ^ "such that " ^ term_pp term1 ^ "(" ^ ident1 ^ ")"
171 | AndElim (_, term, ident1, term1, ident2, term2) -> "by " ^ term_pp term ^ "we have " ^ term_pp term1 ^ " (" ^ ident1 ^ ") " ^ "and " ^ term_pp term2 ^ " (" ^ ident2 ^ ")"
172 | RewritingStep (_, term, term1, term2, cont) -> (match term with None -> " " | Some term -> "obtain " ^ term_pp term) ^ "=" ^ term_pp term1 ^ (match term2 with None -> "_" | Some term2 -> term_pp term2) ^ (match cont with None -> " done" | Some Cic.Anonymous -> "" | Some (Cic.Name id) -> " we proved " ^ id)
173 | Case (_, id, args) ->
176 (List.map (function (id,term) -> "(" ^ id ^ ": " ^ term_pp term ^ ")")
179 let pp_search_kind = function
180 | `Locate -> "locate"
184 | `Instance -> "instance"
186 let pp_arg ~term_pp arg =
187 let s = term_pp arg in
188 if s = "" || (s.[0] = '(' && s.[String.length s - 1] = ')') then
189 (* _nice_ heuristic *)
194 let pp_macro ~term_pp =
195 let term_pp = pp_arg ~term_pp in
198 | WInstance (_, term) -> "whelp instance " ^ term_pp term
199 | WHint (_, t) -> "whelp hint " ^ term_pp t
200 | WLocate (_, s) -> "whelp locate \"" ^ s ^ "\""
201 | WElim (_, t) -> "whelp elim " ^ term_pp t
202 | WMatch (_, term) -> "whelp match " ^ term_pp term
204 | Check (_, term) -> sprintf "check %s" (term_pp term)
206 | Inline (_,suri) -> sprintf "inline \"%s\"" suri
208 let pp_associativity = function
209 | Gramext.LeftA -> "left associative"
210 | Gramext.RightA -> "right associative"
211 | Gramext.NonA -> "non associative"
213 let pp_precedence i = sprintf "with precedence %d" i
215 let pp_dir_opt = function
217 | Some `LeftToRight -> "> "
218 | Some `RightToLeft -> "< "
220 let pp_default what uris =
221 sprintf "default \"%s\" %s" what
222 (String.concat " " (List.map UriManager.string_of_uri uris))
224 let pp_coercion uri do_composites arity =
225 sprintf "coercion %s %d (* %s *)" (UriManager.string_of_uri uri) arity
226 (if do_composites then "compounds" else "no compounds")
228 let pp_command ~term_pp ~obj_pp = function
229 | Index (_,_,uri) -> "Indexing " ^ UriManager.string_of_uri uri
230 | Coercion (_, uri, do_composites, i) -> pp_coercion uri do_composites i
231 | Default (_,what,uris) -> pp_default what uris
233 | Include (_,path) -> "include \"" ^ path ^ "\""
234 | Obj (_,obj) -> obj_pp obj
236 | Relation (_,id,a,aeq,refl,sym,trans) ->
237 "relation " ^ term_pp aeq ^ " on " ^ term_pp a ^
239 Some r -> " reflexivity proved by " ^ term_pp r
242 Some r -> " symmetry proved by " ^ term_pp r
245 Some r -> " transitivity proved by " ^ term_pp r
247 | Print (_,s) -> "print " ^ s
248 | Set (_, name, value) -> sprintf "set \"%s\" \"%s\"" name value
250 let rec pp_tactical ~term_pp ~lazy_term_pp =
251 let pp_tactic = pp_tactic ~lazy_term_pp ~term_pp in
252 let pp_tacticals = pp_tacticals ~lazy_term_pp ~term_pp in
254 | Tactic (_, tac) -> pp_tactic tac
255 | Do (_, count, tac) ->
256 sprintf "do %d %s" count (pp_tactical ~term_pp ~lazy_term_pp tac)
257 | Repeat (_, tac) -> "repeat " ^ pp_tactical ~term_pp ~lazy_term_pp tac
258 | Seq (_, tacs) -> pp_tacticals ~sep:"; " tacs
259 | Then (_, tac, tacs) ->
260 sprintf "%s; [%s]" (pp_tactical ~term_pp ~lazy_term_pp tac)
261 (pp_tacticals ~sep:" | " tacs)
262 | First (_, tacs) -> sprintf "tries [%s]" (pp_tacticals ~sep:" | " tacs)
263 | Try (_, tac) -> "try " ^ pp_tactical ~term_pp ~lazy_term_pp tac
264 | Solve (_, tac) -> sprintf "solve [%s]" (pp_tacticals ~sep:" | " tac)
265 | Progress (_, tac) -> "progress " ^ pp_tactical ~term_pp ~lazy_term_pp tac
271 | Pos (_, i) -> sprintf "%s:" (String.concat "," (List.map string_of_int i))
274 | Focus (_, goals) ->
275 sprintf "focus %s" (String.concat " " (List.map string_of_int goals))
276 | Unfocus _ -> "unfocus"
279 and pp_tacticals ~term_pp ~lazy_term_pp ~sep tacs =
280 String.concat sep (List.map (pp_tactical~lazy_term_pp ~term_pp) tacs)
282 let pp_executable ~term_pp ~lazy_term_pp ~obj_pp =
284 | Macro (_, macro) -> pp_macro ~term_pp macro ^ "."
285 | Tactical (_, tac, Some punct) ->
286 pp_tactical ~lazy_term_pp ~term_pp tac
287 ^ pp_tactical ~lazy_term_pp ~term_pp punct
288 | Tactical (_, tac, None) -> pp_tactical ~lazy_term_pp ~term_pp tac
289 | Command (_, cmd) -> pp_command ~term_pp ~obj_pp cmd ^ "."
291 let pp_comment ~term_pp ~lazy_term_pp ~obj_pp =
293 | Note (_,str) -> sprintf "(* %s *)" str
295 sprintf "(** %s. **)" (pp_executable ~term_pp ~lazy_term_pp ~obj_pp code)
297 let pp_statement ~term_pp ~lazy_term_pp ~obj_pp =
299 | Executable (_, ex) -> pp_executable ~lazy_term_pp ~term_pp ~obj_pp ex
300 | Comment (_, c) -> pp_comment ~term_pp ~lazy_term_pp ~obj_pp c