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))
74 match p.Con.proof_conclude.Con.conclude_conclusion with
75 None -> (*Cic.Implicit None*) assert false
76 | Some ty -> deannotate ty
78 (match p.Con.proof_name with
80 C.LetIn (C.Name s, proof2cic premise_env p, ty , target)
82 C.LetIn (C.Anonymous, proof2cic premise_env p, ty, target))
84 (match d.Con.def_name with
86 C.LetIn (C.Name s, proof2cic premise_env p, deannotate d.Con.def_type, target)
88 C.LetIn (C.Anonymous, proof2cic premise_env p, deannotate d.Con.def_type, target))
89 | `Joint {Con.joint_kind = kind; Con.joint_defs = defs} ->
100 bo.Con.proof_conclude.Con.conclude_conclusion,
103 Some ty, Some name ->
104 (name,n,deannotate ty,
105 proof2cic premise_env bo)
106 | _,_ -> assert false)
117 bo.Con.proof_conclude.Con.conclude_conclusion,
120 Some ty, Some name ->
122 proof2cic premise_env bo)
123 | _,_ -> assert false)
127 | _ -> (* no inductive types in local contexts *)
131 and conclude2cic premise_env conclude =
132 let module C = Cic in
133 let module Con = Content in
134 if conclude.Con.conclude_method = "TD_Conversion" then
135 (match conclude.Con.conclude_args with
136 [Con.ArgProof p] -> proof2cic [] p (* empty! *)
137 | _ -> prerr_endline "1"; assert false)
138 else if conclude.Con.conclude_method = "BU_Conversion" then
139 (match conclude.Con.conclude_args with
140 [Con.Premise prem] ->
141 (try List.assoc prem.Con.premise_xref premise_env
144 ("Not_found in BU_Conversion: " ^ prem.Con.premise_xref);
146 | _ -> prerr_endline "2"; assert false)
147 else if conclude.Con.conclude_method = "Exact" then
148 (match conclude.Con.conclude_args with
149 [Con.Term (_,t)] -> deannotate t
150 | [Con.Premise prem] ->
151 (match prem.Con.premise_n with
154 | _ -> prerr_endline "3"; assert false)
155 else if conclude.Con.conclude_method = "Intros+LetTac" then
156 (match conclude.Con.conclude_args with
157 [Con.ArgProof p] -> proof2cic [] p (* empty! *)
158 | _ -> prerr_endline "4"; assert false)
159 else if (conclude.Con.conclude_method = "ByInduction" ||
160 conclude.Con.conclude_method = "AndInd" ||
161 conclude.Con.conclude_method = "Exists" ||
162 conclude.Con.conclude_method = "FalseInd") then
163 (match (List.tl conclude.Con.conclude_args) with
164 Con.Term (_,C.AAppl (
165 id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))::args ->
167 List.map (fun (u,t) -> (u, deannotate t)) exp_named_subst in
168 let cargs = args2cic premise_env args in
169 let cparams_and_IP = List.map deannotate params_and_IP in
170 C.Appl (C.Const(uri,subst)::cparams_and_IP@cargs)
171 | _ -> prerr_endline "5"; assert false)
172 else if (conclude.Con.conclude_method = "Rewrite") then
173 (match conclude.Con.conclude_args with
174 Con.Term (_,C.AConst (sid,uri,exp_named_subst))::args ->
176 List.map (fun (u,t) -> (u, deannotate t)) exp_named_subst in
177 let cargs = args2cic premise_env args in
178 C.Appl (C.Const(uri,subst)::cargs)
179 | _ -> prerr_endline "6"; assert false)
180 else if (conclude.Con.conclude_method = "Case") then
181 (match conclude.Con.conclude_args with
182 Con.Aux(uri)::Con.Aux(notype)::Con.Term(_,ty)::Con.Premise(prem)::patterns ->
184 (UriManager.uri_of_string uri,
185 int_of_string notype, deannotate ty,
186 List.assoc prem.Con.premise_xref premise_env,
189 Con.ArgProof p -> proof2cic [] p
190 | _ -> prerr_endline "7a"; assert false) patterns)
191 | Con.Aux(uri)::Con.Aux(notype)::Con.Term(_,ty)::Con.Term(_,te)::patterns -> C.MutCase
192 (UriManager.uri_of_string uri,
193 int_of_string notype, deannotate ty, deannotate te,
196 (Con.ArgProof p) -> proof2cic [] p
197 | _ -> prerr_endline "7a"; assert false) patterns)
198 | _ -> (prerr_endline "7"; assert false))
199 else if (conclude.Con.conclude_method = "Apply") then
200 let cargs = (args2cic premise_env conclude.Con.conclude_args) in
202 else (prerr_endline "8"; assert false)
204 and args2cic premise_env l =
205 List.map (arg2cic premise_env) l
207 and arg2cic premise_env =
208 let module C = Cic in
209 let module Con = Content in
211 Con.Aux n -> prerr_endline "8"; assert false
212 | Con.Premise prem ->
213 (match prem.Con.premise_n with
216 (try List.assoc prem.Con.premise_xref premise_env
218 prerr_endline ("Not_found in arg2cic: premise " ^ (match prem.Con.premise_binder with None -> "previous" | Some p -> p) ^ ", xref=" ^ prem.Con.premise_xref);
221 CicUtil.term_of_uri (UriManager.uri_of_string lemma.Con.lemma_uri)
222 | Con.Term (_,t) -> deannotate t
223 | Con.ArgProof p -> proof2cic [] p (* empty! *)
224 | Con.ArgMethod s -> raise TO_DO
231 let cobj2obj deannotate (id,params,metasenv,obj) =
232 let module K = Content in
234 `Def (Content.Const,ty,`Proof bo) ->
238 (id, Some (proof2cic deannotate bo), deannotate ty, params, [])
242 (function (_,i,canonical_context,term) ->
243 let canonical_context' =
247 | Some (`Declaration d)
248 | Some (`Hypothesis d) ->
250 {K.dec_name = Some n ; K.dec_type = t} ->
251 Some (Cic.Name n, Cic.Decl (deannotate t))
253 | Some (`Definition d) ->
255 {K.def_name = Some n ; K.def_term = t ; K.def_type = ty} ->
256 Some (Cic.Name n, Cic.Def (deannotate t,deannotate ty))
260 {K.proof_name = Some n } ->
262 Cic.Def ((proof2cic deannotate d),assert false))
266 (i,canonical_context',deannotate term)
270 (id, metasenv'', proof2cic deannotate bo, deannotate ty, params,
275 let cobj2obj = cobj2obj Deannotate.deannotate_term;;