1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
26 (***************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (***************************************************************************)
39 let proof2cic deannotate p =
40 let rec proof2cic premise_env p =
42 let module Con = Content in
43 let rec extend_premise_env current_env =
48 ((p.Con.proof_id,(proof2cic current_env p))::current_env) atl in
49 let new_premise_env = extend_premise_env premise_env p.Con.proof_apply_context in
50 let body = conclude2cic new_premise_env p.Con.proof_conclude in
51 context2cic premise_env p.Con.proof_context body
53 and context2cic premise_env context body =
54 List.fold_right (ce2cic premise_env) context body
56 and ce2cic premise_env ce target =
58 let module Con = Content in
61 (match d.Con.dec_name with
63 C.Lambda (C.Name s, deannotate d.Con.dec_type, target)
65 C.Lambda (C.Anonymous, deannotate d.Con.dec_type, target))
67 (match h.Con.dec_name with
69 C.Lambda (C.Name s, deannotate h.Con.dec_type, target)
71 C.Lambda (C.Anonymous, deannotate h.Con.dec_type, target))
73 (match p.Con.proof_name with
75 C.LetIn (C.Name s, proof2cic premise_env p, target)
77 C.LetIn (C.Anonymous, proof2cic premise_env p, target))
79 (match d.Con.def_name with
81 C.LetIn (C.Name s, proof2cic premise_env p, target)
83 C.LetIn (C.Anonymous, proof2cic premise_env p, target))
84 | `Joint {Con.joint_kind = kind; Con.joint_defs = defs} ->
95 bo.Con.proof_conclude.Con.conclude_conclusion,
99 (name,n,deannotate ty,
100 proof2cic premise_env bo)
101 | _,_ -> assert false)
112 bo.Con.proof_conclude.Con.conclude_conclusion,
115 Some ty, Some name ->
117 proof2cic premise_env bo)
118 | _,_ -> assert false)
122 | _ -> (* no inductive types in local contexts *)
126 and conclude2cic premise_env conclude =
127 let module C = Cic in
128 let module Con = Content in
129 if conclude.Con.conclude_method = "TD_Conversion" then
130 (match conclude.Con.conclude_args with
131 [Con.ArgProof p] -> proof2cic [] p (* empty! *)
132 | _ -> prerr_endline "1"; assert false)
133 else if conclude.Con.conclude_method = "BU_Conversion" then
134 (match conclude.Con.conclude_args with
135 [Con.Premise prem] ->
136 (try List.assoc prem.Con.premise_xref premise_env
139 ("Not_found in BU_Conversion: " ^ prem.Con.premise_xref);
141 | _ -> prerr_endline "2"; assert false)
142 else if conclude.Con.conclude_method = "Exact" then
143 (match conclude.Con.conclude_args with
144 [Con.Term t] -> deannotate t
145 | [Con.Premise prem] ->
146 (match prem.Con.premise_n with
149 | _ -> prerr_endline "3"; assert false)
150 else if conclude.Con.conclude_method = "Intros+LetTac" then
151 (match conclude.Con.conclude_args with
152 [Con.ArgProof p] -> proof2cic [] p (* empty! *)
153 | _ -> prerr_endline "4"; assert false)
154 else if (conclude.Con.conclude_method = "ByInduction" ||
155 conclude.Con.conclude_method = "AndInd" ||
156 conclude.Con.conclude_method = "Exists" ||
157 conclude.Con.conclude_method = "FalseInd") then
158 (match (List.tl conclude.Con.conclude_args) with
160 id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))::args ->
162 List.map (fun (u,t) -> (u, deannotate t)) exp_named_subst in
163 let cargs = args2cic premise_env args in
164 let cparams_and_IP = List.map deannotate params_and_IP in
165 C.Appl (C.Const(uri,subst)::cparams_and_IP@cargs)
166 | _ -> prerr_endline "5"; assert false)
167 else if (conclude.Con.conclude_method = "Rewrite") then
168 (match conclude.Con.conclude_args with
169 Con.Term (C.AConst (sid,uri,exp_named_subst))::args ->
171 List.map (fun (u,t) -> (u, deannotate t)) exp_named_subst in
172 let cargs = args2cic premise_env args in
173 C.Appl (C.Const(uri,subst)::cargs)
174 | _ -> prerr_endline "6"; assert false)
175 else if (conclude.Con.conclude_method = "Case") then
176 (match conclude.Con.conclude_args with
177 Con.Aux(uri)::Con.Aux(notype)::Con.Term(ty)::Con.Premise(prem)::patterns ->
179 (UriManager.uri_of_string uri,
180 int_of_string notype, deannotate ty,
181 List.assoc prem.Con.premise_xref premise_env,
184 Con.ArgProof p -> proof2cic [] p
185 | _ -> prerr_endline "7a"; assert false) patterns)
186 | Con.Aux(uri)::Con.Aux(notype)::Con.Term(ty)::Con.Term(te)::patterns -> C.MutCase
187 (UriManager.uri_of_string uri,
188 int_of_string notype, deannotate ty, deannotate te,
191 (Con.ArgProof p) -> proof2cic [] p
192 | _ -> prerr_endline "7a"; assert false) patterns)
193 | _ -> (prerr_endline "7"; assert false))
194 else if (conclude.Con.conclude_method = "Apply") then
195 let cargs = (args2cic premise_env conclude.Con.conclude_args) in
197 else (prerr_endline "8"; assert false)
199 and args2cic premise_env l =
200 List.map (arg2cic premise_env) l
202 and arg2cic premise_env =
203 let module C = Cic in
204 let module Con = Content in
206 Con.Aux n -> prerr_endline "8"; assert false
207 | Con.Premise prem ->
208 (match prem.Con.premise_n with
211 (try List.assoc prem.Con.premise_xref premise_env
213 prerr_endline ("Not_found in arg2cic: premise " ^ (match prem.Con.premise_binder with None -> "previous" | Some p -> p) ^ ", xref=" ^ prem.Con.premise_xref);
216 CicUtil.term_of_uri (UriManager.uri_of_string lemma.Con.lemma_uri)
217 | Con.Term t -> deannotate t
218 | Con.ArgProof p -> proof2cic [] p (* empty! *)
219 | Con.ArgMethod s -> raise TO_DO
226 let cobj2obj deannotate (id,params,metasenv,obj) =
227 let module K = Content in
229 `Def (Content.Const,ty,`Proof bo) ->
233 (id, Some (proof2cic deannotate bo), deannotate ty, params, [])
237 (function (_,i,canonical_context,term) ->
238 let canonical_context' =
242 | Some (`Declaration d)
243 | Some (`Hypothesis d) ->
245 {K.dec_name = Some n ; K.dec_type = t} ->
246 Some (Cic.Name n, Cic.Decl (deannotate t))
248 | Some (`Definition d) ->
250 {K.def_name = Some n ; K.def_term = t} ->
251 Some (Cic.Name n, Cic.Def ((deannotate t),None))
255 {K.proof_name = Some n } ->
257 Cic.Def ((proof2cic deannotate d),None))
261 (i,canonical_context',deannotate term)
265 (id, metasenv'', proof2cic deannotate bo, deannotate ty, params,
270 let cobj2obj = cobj2obj Deannotate.deannotate_term;;