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/.
28 type sort_kind = [ `Prop | `Set | `Type of CicUniv.universe | `CProp of CicUniv.universe ]
30 let string_of_sort = function
33 | `Type u -> "Type:" ^ string_of_int (CicUniv.univno u) ^ ":" ^ UriManager.string_of_uri (CicUniv.univuri u)
34 | `CProp u -> "CProp:" ^ string_of_int (CicUniv.univno u) ^ ":" ^ UriManager.string_of_uri (CicUniv.univuri u)
37 let sort_of_sort = function
40 | Cic.Type u -> `Type u
41 | Cic.CProp u -> `CProp u
43 (* let hashtbl_add_time = ref 0.0;; *)
45 let xxx_add_profiler = HExtlib.profile "xxx_add";;
47 xxx_add_profiler.HExtlib.profile (Hashtbl.add h k) v
50 let xxx_type_of_aux' m c t =
53 CicTypeChecker.type_of_aux' m c t CicUniv.oblivion_ugraph
55 | CicTypeChecker.AssertFailure _
56 | CicTypeChecker.TypeCheckerFailure _ ->
57 Cic.Sort Cic.Prop, CicUniv.oblivion_ugraph
62 let xxx_type_of_aux'_profiler = HExtlib.profile "xxx_type_of_aux'";;
63 let xxx_type_of_aux' m c t =
64 xxx_type_of_aux'_profiler.HExtlib.profile (xxx_type_of_aux' m c) t
67 {annsynthesized : Cic.annterm ; annexpected : Cic.annterm option}
71 let res = "i" ^ string_of_int !seed in
76 let fresh_id seed ids_to_terms ids_to_father_ids =
78 let res = gen_id seed in
79 xxx_add ids_to_father_ids res father ;
80 xxx_add ids_to_terms res t ;
84 let source_id_of_id id = "#source#" ^ id;;
86 exception NotEnoughElements of string;;
88 (*CSC: cut&paste da cicPp.ml *)
89 (* get_nth l n returns the nth element of the list l if it exists or *)
90 (* raises NotEnoughElements if l has less than n elements *)
91 let rec get_nth msg l n =
94 | (n, he::tail) when n > 1 -> get_nth msg tail (n-1)
95 | (_,_) -> raise (NotEnoughElements msg)
99 let profiler_for_find = HExtlib.profile "CicHash" ;;
100 let profiler_for_whd = HExtlib.profile "whd" ;;
102 let cic_CicHash_find a b =
103 profiler_for_find.HExtlib.profile (Cic.CicHash.find a) b
106 let cicReduction_whd c t =
107 profiler_for_whd.HExtlib.profile (CicReduction.whd c) t
110 let acic_of_cic_context' ~computeinnertypes:global_computeinnertypes
111 seed ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
112 metasenv context idrefs t expectedty
114 let module D = DoubleTypeInference in
115 let module C = Cic in
116 let fresh_id' = fresh_id seed ids_to_terms ids_to_father_ids in
117 (* let time1 = Sys.time () in *)
120 let time0 = Sys.time () in
121 let prova = CicTypeChecker.type_of_aux' metasenv context t in
122 let time1 = Sys.time () in
123 prerr_endline ("*** Fine type_inference:" ^ (string_of_float (time1 -. time0)));
124 let res = D.double_type_of metasenv context t expectedty in
125 let time2 = Sys.time () in
126 prerr_endline ("*** Fine double_type_inference:" ^ (string_of_float (time2 -. time1)));
129 if global_computeinnertypes then
130 D.double_type_of metasenv context t expectedty
132 Cic.CicHash.create 1 (* empty table *)
135 let time2 = Sys.time () in
137 ("++++++++++++ Tempi della double_type_of: "^ string_of_float (time2 -. time1)) ;
139 let rec aux computeinnertypes father context idrefs tt =
140 let fresh_id'' = fresh_id' father tt in
141 (*CSC: computeinnertypes era true, il che e' proprio sbagliato, no? *)
142 (* First of all we compute the inner type and the inner sort *)
143 (* of the term. They may be useful in what follows. *)
144 (*CSC: This is a very inefficient way of computing inner types *)
145 (*CSC: and inner sorts: very deep terms have their types/sorts *)
146 (*CSC: computed again and again. *)
148 match cicReduction_whd context t with
149 C.Sort C.Prop -> `Prop
150 | C.Sort C.Set -> `Set
151 | C.Sort (C.Type u) -> `Type u
152 | C.Meta _ -> `Type (CicUniv.fresh())
153 | C.Sort (C.CProp u) -> `CProp u
155 prerr_endline ("Cic2acic.sort_of applied to: " ^ CicPp.ppterm t) ;
158 let ainnertypes,innertype,innersort,expected_available =
160 (*CSC: Here we need the algorithm for Coscoy's double type-inference *)
161 (*CSC: (expected type + inferred type). Just for now we use the usual *)
162 (*CSC: type-inference, but the result is very poor. As a very weak *)
163 (*CSC: patch, I apply whd to the computed type. Full beta *)
164 (*CSC: reduction would be a much better option. *)
165 (*CSC: solo per testare i tempi *)
169 let {D.synthesized = synthesized; D.expected = expected} =
170 if computeinnertypes then
171 cic_CicHash_find terms_to_types tt
173 (* We are already in an inner-type and Coscoy's double *)
174 (* type inference algorithm has not been applied. *)
176 (***CSC: patch per provare i tempi
177 CicReduction.whd context (xxx_type_of_aux' metasenv context tt) ; *)
178 (*if global_computeinnertypes then
179 Cic.Sort (Cic.Type (CicUniv.fresh()))
181 cicReduction_whd context (xxx_type_of_aux' metasenv context tt);
184 (* incr number_new_type_of_aux' ; *)
185 let innersort = (*XXXXX *) xxx_type_of_aux' metasenv context synthesized (* Cic.Sort Cic.Prop *) in
186 let ainnertypes,expected_available =
187 if computeinnertypes then
188 let annexpected,expected_available =
191 | Some expectedty' ->
193 (aux false (Some fresh_id'') context idrefs expectedty'),
198 aux false (Some fresh_id'') context idrefs synthesized ;
199 annexpected = annexpected
200 }, expected_available
204 ainnertypes,synthesized, sort_of innersort, expected_available
207 Not_found -> (* l'inner-type non e' nella tabella ==> sort <> Prop *)
208 (* CSC: Type or Set? I can not tell *)
209 let u = CicUniv.fresh() in
210 None,Cic.Sort (Cic.Type u),`Type u,false
211 (* TASSI non dovrebbe fare danni *)
215 if innersort = `Prop then
216 aux computeinnertypes (Some fresh_id'')
218 aux false (Some fresh_id'')
220 let add_inner_type id =
221 match ainnertypes with
223 | Some ainnertypes -> xxx_add ids_to_inner_types id ainnertypes
228 match get_nth "1" context n with
229 (Some (C.Name s,_)) -> s
230 | _ -> "__" ^ string_of_int n
232 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
233 if innersort = `Prop && expected_available then
234 add_inner_type fresh_id'' ;
235 C.ARel (fresh_id'', List.nth idrefs (n-1), n, id)
236 | C.Var (uri,exp_named_subst) ->
237 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
238 if innersort = `Prop && expected_available then
239 add_inner_type fresh_id'' ;
240 let exp_named_subst' =
242 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
244 C.AVar (fresh_id'', uri,exp_named_subst')
246 let (_,canonical_context,_) = CicUtil.lookup_meta n metasenv in
247 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
248 if innersort = `Prop && expected_available then
249 add_inner_type fresh_id'' ;
250 C.AMeta (fresh_id'', n,
255 | _, Some t -> Some (aux' context idrefs t)
256 | Some _, None -> assert false (* due to typing rules *))
257 canonical_context l))
258 | C.Sort s -> C.ASort (fresh_id'', s)
259 | C.Implicit annotation -> C.AImplicit (fresh_id'', annotation)
261 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
262 if innersort = `Prop then
263 add_inner_type fresh_id'' ;
264 C.ACast (fresh_id'', aux' context idrefs v, aux' context idrefs t)
266 xxx_add ids_to_inner_sorts fresh_id''
267 (sort_of innertype) ;
268 let sourcetype = xxx_type_of_aux' metasenv context s in
269 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
270 (sort_of sourcetype) ;
275 if DoubleTypeInference.does_not_occur 1 t then
281 (fresh_id'', n', aux' context idrefs s,
282 aux' ((Some (n, C.Decl s))::context) (fresh_id''::idrefs) t)
283 | C.Lambda (n,s,t) ->
284 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
285 let sourcetype = xxx_type_of_aux' metasenv context s in
286 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
287 (sort_of sourcetype) ;
288 if innersort = `Prop then
290 let father_is_lambda =
294 match Hashtbl.find ids_to_terms father' with
298 if (not father_is_lambda) || expected_available then
299 add_inner_type fresh_id''
302 (fresh_id'',n, aux' context idrefs s,
303 aux' ((Some (n, C.Decl s)::context)) (fresh_id''::idrefs) t)
304 | C.LetIn (n,s,ty,t) ->
305 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
306 if innersort = `Prop then
307 add_inner_type fresh_id'' ;
309 (fresh_id'', n, aux' context idrefs s, aux' context idrefs ty,
310 aux' ((Some (n, C.Def(s,ty)))::context) (fresh_id''::idrefs) t)
312 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
313 if innersort = `Prop then
314 add_inner_type fresh_id'' ;
315 C.AAppl (fresh_id'', List.map (aux' context idrefs) l)
316 | C.Const (uri,exp_named_subst) ->
317 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
318 if innersort = `Prop && expected_available then
319 add_inner_type fresh_id'' ;
320 let exp_named_subst' =
322 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
324 C.AConst (fresh_id'', uri, exp_named_subst')
325 | C.MutInd (uri,tyno,exp_named_subst) ->
326 let exp_named_subst' =
328 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
330 C.AMutInd (fresh_id'', uri, tyno, exp_named_subst')
331 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
332 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
333 if innersort = `Prop && expected_available then
334 add_inner_type fresh_id'' ;
335 let exp_named_subst' =
337 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
339 C.AMutConstruct (fresh_id'', uri, tyno, consno, exp_named_subst')
340 | C.MutCase (uri, tyno, outty, term, patterns) ->
341 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
342 if innersort = `Prop then
343 add_inner_type fresh_id'' ;
344 C.AMutCase (fresh_id'', uri, tyno, aux' context idrefs outty,
345 aux' context idrefs term, List.map (aux' context idrefs) patterns)
346 | C.Fix (funno, funs) ->
348 List.map (function _ -> gen_id seed) funs in
349 let new_idrefs = List.rev fresh_idrefs @ idrefs in
352 (fun (types,len) (n,_,ty,_) ->
353 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
357 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
358 if innersort = `Prop then
359 add_inner_type fresh_id'' ;
360 C.AFix (fresh_id'', funno,
362 (fun id (name, indidx, ty, bo) ->
363 (id, name, indidx, aux' context idrefs ty,
364 aux' (tys@context) new_idrefs bo)
367 | C.CoFix (funno, funs) ->
369 List.map (function _ -> gen_id seed) funs in
370 let new_idrefs = List.rev fresh_idrefs @ idrefs in
373 (fun (types,len) (n,ty,_) ->
374 (Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))::types,
378 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
379 if innersort = `Prop then
380 add_inner_type fresh_id'' ;
381 C.ACoFix (fresh_id'', funno,
383 (fun id (name, ty, bo) ->
384 (id, name, aux' context idrefs ty,
385 aux' (tys@context) new_idrefs bo)
390 let timea = Sys.time () in
391 let res = aux true None context idrefs t in
392 let timeb = Sys.time () in
394 ("+++++++++++++ Tempi della aux dentro alla acic_of_cic: "^ string_of_float (timeb -. timea)) ;
397 aux global_computeinnertypes None context idrefs t
400 let acic_of_cic_context ~computeinnertypes metasenv context idrefs t =
401 let ids_to_terms = Hashtbl.create 503 in
402 let ids_to_father_ids = Hashtbl.create 503 in
403 let ids_to_inner_sorts = Hashtbl.create 503 in
404 let ids_to_inner_types = Hashtbl.create 503 in
406 acic_of_cic_context' ~computeinnertypes seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
407 ids_to_inner_types metasenv context idrefs t,
408 ids_to_terms, ids_to_father_ids, ids_to_inner_sorts, ids_to_inner_types
411 let aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
412 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
413 metasenv (metano,context,goal)
415 let computeinnertypes = false in
416 let acic_of_cic_context =
417 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
418 ids_to_inner_types metasenv in
419 let _, acontext,final_idrefs =
421 (fun binding (context, acontext,idrefs) ->
422 let hid = "h" ^ string_of_int !hypotheses_seed in
423 Hashtbl.add ids_to_hypotheses hid binding ;
424 incr hypotheses_seed ;
426 Some (n,Cic.Def (t,ty)) ->
428 acic_of_cic_context ~computeinnertypes context idrefs t
431 acic_of_cic_context ~computeinnertypes context idrefs ty
434 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
436 Hashtbl.replace ids_to_father_ids
437 (CicUtil.id_of_annterm acic2) (Some hid);
439 ((hid,Some (n,Cic.ADef (acic,acic2)))::acontext),
441 | Some (n,Cic.Decl t) ->
442 let acic = acic_of_cic_context ~computeinnertypes context idrefs t None in
443 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
446 ((hid,Some (n,Cic.ADecl acic))::acontext),(hid::idrefs)
448 (* Invariant: "" is never looked up *)
449 (None::context),((hid,None)::acontext),""::idrefs
453 let agoal = acic_of_cic_context ~computeinnertypes context final_idrefs goal None in
454 (metano,acontext,agoal)
457 let asequent_of_sequent (metasenv:Cic.metasenv) (sequent:Cic.conjecture) =
458 let ids_to_terms = Hashtbl.create 503 in
459 let ids_to_father_ids = Hashtbl.create 503 in
460 let ids_to_inner_sorts = Hashtbl.create 503 in
461 let ids_to_inner_types = Hashtbl.create 503 in
462 let ids_to_hypotheses = Hashtbl.create 23 in
463 let hypotheses_seed = ref 0 in
464 let seed = ref 1 in (* 'i0' is used for the whole sequent *)
466 let i,canonical_context,term = sequent in
467 let canonical_context' =
469 (fun d canonical_context' ->
473 | Some (n, Cic.Decl t)->
474 Some (n, Cic.Decl (Unshare.unshare t))
475 | Some (n,Cic.Def (bo,ty)) ->
476 Some (n, Cic.Def (Unshare.unshare bo,Unshare.unshare ty))
478 d::canonical_context'
479 ) canonical_context []
481 let term' = Unshare.unshare term in
482 (i,canonical_context',term')
484 let (metano,acontext,agoal) =
485 aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
486 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
487 metasenv unsh_sequent in
489 (("i0",metano,acontext,agoal),
490 ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_hypotheses))
493 let acic_term_or_object_of_cic_term_or_object ?(eta_fix=false) () =
494 let module C = Cic in
495 let module E = Eta_fixing in
496 let ids_to_terms = Hashtbl.create 503 in
497 let ids_to_father_ids = Hashtbl.create 503 in
498 let ids_to_inner_sorts = Hashtbl.create 503 in
499 let ids_to_inner_types = Hashtbl.create 503 in
500 let ids_to_conjectures = Hashtbl.create 11 in
501 let ids_to_hypotheses = Hashtbl.create 127 in
502 let hypotheses_seed = ref 0 in
503 let conjectures_seed = ref 0 in
505 let acic_term_of_cic_term_context' =
506 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
507 ids_to_inner_types in
508 let acic_term_of_cic_term' = acic_term_of_cic_term_context' [] [] [] in
509 let aconjecture_of_conjecture' = aconjecture_of_conjecture seed
510 ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
511 ids_to_hypotheses hypotheses_seed in
512 let eta_fix_and_unshare metasenv context t =
513 let t = if eta_fix then E.eta_fix metasenv context t else t in
518 | Some (n, C.Decl ty) -> Some (n, C.Decl (Unshare.unshare ty))
519 | Some (n, C.Def (bo, ty)) ->
520 Some (n, C.Def (Unshare.unshare bo, Unshare.unshare ty))
522 let t = Unshare.unshare t in
523 let context = List.map map context in
524 let idrefs = List.map (function _ -> gen_id seed) context in
525 let t = acic_term_of_cic_term_context' ~computeinnertypes:true [] context idrefs t None in
526 t, ids_to_inner_sorts, ids_to_inner_types
530 C.Constant (id,Some bo,ty,params,attrs) ->
531 let bo' = (*eta_fix_and_unshare[] [] bo*) Unshare.unshare bo in
532 let ty' = eta_fix_and_unshare [] [] ty in
533 let abo = acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty') in
534 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
536 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
537 | C.Constant (id,None,ty,params,attrs) ->
538 let ty' = eta_fix_and_unshare [] [] ty in
539 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
541 ("mettereaposto",None,id,None,aty,params,attrs)
542 | C.Variable (id,bo,ty,params,attrs) ->
543 let ty' = eta_fix_and_unshare [] [] ty in
548 let bo' = eta_fix_and_unshare [] [] bo in
549 Some (acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty'))
551 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
553 ("mettereaposto",id,abo,aty,params,attrs)
554 | C.CurrentProof (id,conjectures,bo,ty,params,attrs) ->
557 (function (i,canonical_context,term) ->
558 let canonical_context' =
560 (fun d canonical_context' ->
564 | Some (n, C.Decl t)->
565 Some (n, C.Decl (eta_fix_and_unshare conjectures canonical_context' t))
566 | Some (n, C.Def (t,ty)) ->
569 (eta_fix_and_unshare conjectures canonical_context' t,
570 eta_fix_and_unshare conjectures canonical_context' ty))
572 d::canonical_context'
573 ) canonical_context []
575 let term' = eta_fix_and_unshare conjectures canonical_context' term in
576 (i,canonical_context',term')
581 (function (i,canonical_context,term) as conjecture ->
582 let cid = "c" ^ string_of_int !conjectures_seed in
583 xxx_add ids_to_conjectures cid conjecture ;
584 incr conjectures_seed ;
585 let (i,acanonical_context,aterm)
586 = aconjecture_of_conjecture' conjectures conjecture in
587 (cid,i,acanonical_context,aterm))
589 (* let bo' = eta_fix conjectures' [] bo in *)
591 let ty' = eta_fix_and_unshare conjectures' [] ty in
593 let time2 = Sys.time () in
595 ("++++++++++ Tempi della eta_fix: "^ string_of_float (time2 -. time1)) ;
596 hashtbl_add_time := 0.0 ;
597 type_of_aux'_add_time := 0.0 ;
598 DoubleTypeInference.syntactic_equality_add_time := 0.0 ;
601 acic_term_of_cic_term_context' ~computeinnertypes:true conjectures' [] [] bo' (Some ty') in
602 let aty = acic_term_of_cic_term_context' ~computeinnertypes:false conjectures' [] [] ty' None in
604 let time3 = Sys.time () in
606 ("++++++++++++ Tempi della hashtbl_add_time: " ^ string_of_float !hashtbl_add_time) ;
608 ("++++++++++++ Tempi della type_of_aux'_add_time(" ^ string_of_int !number_new_type_of_aux' ^ "): " ^ string_of_float !type_of_aux'_add_time) ;
610 ("++++++++++++ Tempi della type_of_aux'_add_time nella double_type_inference(" ^ string_of_int !DoubleTypeInference.number_new_type_of_aux'_double_work ^ ";" ^ string_of_int !DoubleTypeInference.number_new_type_of_aux'_prop ^ "/" ^ string_of_int !DoubleTypeInference.number_new_type_of_aux' ^ "): " ^ string_of_float !DoubleTypeInference.type_of_aux'_add_time) ;
612 ("++++++++++++ Tempi della syntactic_equality_add_time: " ^ string_of_float !DoubleTypeInference.syntactic_equality_add_time) ;
614 ("++++++++++ Tempi della acic_of_cic: " ^ string_of_float (time3 -. time2)) ;
616 ("++++++++++ Numero di iterazioni della acic_of_cic: " ^ string_of_int !seed) ;
619 ("mettereaposto","mettereaposto2",id,aconjectures,abo,aty,params,attrs)
620 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
623 (fun (name,i,arity,cl) ->
624 (name,i,Unshare.unshare arity,
625 List.map (fun (name,ty) -> name,Unshare.unshare ty) cl)) tys in
628 (fun (name,_,arity,_) ->
629 Some (C.Name name, C.Decl (Unshare.unshare arity))) tys in
630 let idrefs = List.map (function _ -> gen_id seed) tys in
633 (fun id (name,inductive,ty,cons) ->
636 (function (name,ty) ->
638 acic_term_of_cic_term_context' ~computeinnertypes:false [] context idrefs ty None)
642 acic_term_of_cic_term' ~computeinnertypes:false ty None,acons)
643 ) (List.rev idrefs) tys
645 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
647 aobj,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_inner_types,
648 ids_to_conjectures,ids_to_hypotheses
651 let acic_object_of_cic_object ?eta_fix =
652 snd (acic_term_or_object_of_cic_term_or_object ?eta_fix ())
654 let plain_acic_term_of_cic_term =
655 let module C = Cic in
658 function () -> incr id; "i" ^ string_of_int !id in
659 let rec aux context t =
660 let fresh_id = mk_fresh_id () in
664 match get_nth "2" context n with
665 idref,(Some (C.Name s,_)) -> idref,s
666 | idref,_ -> idref,"__" ^ string_of_int n
668 C.ARel (fresh_id, idref, n, id)
669 | C.Var (uri,exp_named_subst) ->
670 let exp_named_subst' =
672 (function i,t -> i, (aux context t)) exp_named_subst
674 C.AVar (fresh_id,uri,exp_named_subst')
676 | C.Meta _ -> assert false
677 | C.Sort s -> C.ASort (fresh_id, s)
679 C.ACast (fresh_id, aux context v, aux context t)
682 (fresh_id, n, aux context s,
683 aux ((fresh_id, Some (n, C.Decl s))::context) t)
684 | C.Lambda (n,s,t) ->
686 (fresh_id,n, aux context s,
687 aux ((fresh_id, Some (n, C.Decl s))::context) t)
688 | C.LetIn (n,s,ty,t) ->
690 (fresh_id, n, aux context s, aux context ty,
691 aux ((fresh_id, Some (n, C.Def(s,ty)))::context) t)
693 C.AAppl (fresh_id, List.map (aux context) l)
694 | C.Const (uri,exp_named_subst) ->
695 let exp_named_subst' =
697 (function i,t -> i, (aux context t)) exp_named_subst
699 C.AConst (fresh_id, uri, exp_named_subst')
700 | C.MutInd (uri,tyno,exp_named_subst) ->
701 let exp_named_subst' =
703 (function i,t -> i, (aux context t)) exp_named_subst
705 C.AMutInd (fresh_id, uri, tyno, exp_named_subst')
706 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
707 let exp_named_subst' =
709 (function i,t -> i, (aux context t)) exp_named_subst
711 C.AMutConstruct (fresh_id, uri, tyno, consno, exp_named_subst')
712 | C.MutCase (uri, tyno, outty, term, patterns) ->
713 C.AMutCase (fresh_id, uri, tyno, aux context outty,
714 aux context term, List.map (aux context) patterns)
715 | C.Fix (funno, funs) ->
718 (fun (types,len) (n,_,ty,_) ->
719 (mk_fresh_id (),(Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
723 C.AFix (fresh_id, funno,
725 (fun (id,_) (name, indidx, ty, bo) ->
726 (id, name, indidx, aux context ty, aux (tys@context) bo)
729 | C.CoFix (funno, funs) ->
732 (fun (types,len) (n,ty,_) ->
733 (mk_fresh_id (),(Some (C.Name n,(C.Decl (CicSubstitution.lift len ty)))))::types,
737 C.ACoFix (fresh_id, funno,
739 (fun (id,_) (name, ty, bo) ->
740 (id, name, aux context ty, aux (tys@context) bo)
747 let plain_acic_object_of_cic_object obj =
748 let module C = Cic in
751 function () -> incr id; "it" ^ string_of_int !id
754 C.Constant (id,Some bo,ty,params,attrs) ->
755 let abo = plain_acic_term_of_cic_term [] bo in
756 let aty = plain_acic_term_of_cic_term [] ty in
758 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
759 | C.Constant (id,None,ty,params,attrs) ->
760 let aty = plain_acic_term_of_cic_term [] ty in
762 ("mettereaposto",None,id,None,aty,params,attrs)
763 | C.Variable (id,bo,ty,params,attrs) ->
767 | Some bo -> Some (plain_acic_term_of_cic_term [] bo)
769 let aty = plain_acic_term_of_cic_term [] ty in
771 ("mettereaposto",id,abo,aty,params,attrs)
772 | C.CurrentProof _ -> assert false
773 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
776 (fun (name,_,arity,_) ->
777 mk_fresh_id (), Some (C.Name name, C.Decl arity)) tys in
780 (fun (id,_) (name,inductive,ty,cons) ->
783 (function (name,ty) ->
785 plain_acic_term_of_cic_term context ty)
788 (id,name,inductive,plain_acic_term_of_cic_term [] ty,acons)
791 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
794 let acic_term_of_cic_term ?eta_fix =
795 fst (acic_term_or_object_of_cic_term_or_object ?eta_fix ())