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 ]
30 let string_of_sort = function
33 | `Type u -> "Type:" ^ string_of_int (CicUniv.univno u)
36 let sort_of_sort = function
39 | Cic.Type u -> `Type u
42 (* let hashtbl_add_time = ref 0.0;; *)
44 let xxx_add_profiler = HExtlib.profile "xxx_add";;
46 xxx_add_profiler.HExtlib.profile (Hashtbl.add h k) v
49 let xxx_type_of_aux' m c t =
52 CicTypeChecker.type_of_aux' m c t CicUniv.empty_ugraph
54 | CicTypeChecker.AssertFailure _
55 | CicTypeChecker.TypeCheckerFailure _ ->
56 Cic.Sort Cic.Prop, CicUniv.empty_ugraph
61 let xxx_type_of_aux'_profiler = HExtlib.profile "xxx_type_of_aux'";;
62 let xxx_type_of_aux' m c t =
63 xxx_type_of_aux'_profiler.HExtlib.profile (xxx_type_of_aux' m c) t
66 {annsynthesized : Cic.annterm ; annexpected : Cic.annterm option}
70 let res = "i" ^ string_of_int !seed in
75 let fresh_id seed ids_to_terms ids_to_father_ids =
77 let res = gen_id seed in
78 xxx_add ids_to_father_ids res father ;
79 xxx_add ids_to_terms res t ;
83 let source_id_of_id id = "#source#" ^ id;;
85 exception NotEnoughElements;;
87 (*CSC: cut&paste da cicPp.ml *)
88 (* get_nth l n returns the nth element of the list l if it exists or *)
89 (* raises NotEnoughElements if l has less than n elements *)
93 | (n, he::tail) when n > 1 -> get_nth tail (n-1)
94 | (_,_) -> raise NotEnoughElements
98 let profiler_for_find = HExtlib.profile "CicHash" ;;
99 let profiler_for_whd = HExtlib.profile "whd" ;;
101 let cic_CicHash_find a b =
102 profiler_for_find.HExtlib.profile (Cic.CicHash.find a) b
105 let cicReduction_whd c t =
106 profiler_for_whd.HExtlib.profile (CicReduction.whd c) t
109 let acic_of_cic_context' ~computeinnertypes:global_computeinnertypes
110 seed ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
111 metasenv context idrefs t expectedty
113 let module D = DoubleTypeInference in
114 let module C = Cic in
115 let fresh_id' = fresh_id seed ids_to_terms ids_to_father_ids in
116 (* let time1 = Sys.time () in *)
119 let time0 = Sys.time () in
120 let prova = CicTypeChecker.type_of_aux' metasenv context t in
121 let time1 = Sys.time () in
122 prerr_endline ("*** Fine type_inference:" ^ (string_of_float (time1 -. time0)));
123 let res = D.double_type_of metasenv context t expectedty in
124 let time2 = Sys.time () in
125 prerr_endline ("*** Fine double_type_inference:" ^ (string_of_float (time2 -. time1)));
128 if global_computeinnertypes then
129 D.double_type_of metasenv context t expectedty
131 Cic.CicHash.create 1 (* empty table *)
134 let time2 = Sys.time () in
136 ("++++++++++++ Tempi della double_type_of: "^ string_of_float (time2 -. time1)) ;
138 let rec aux computeinnertypes father context idrefs tt =
139 let fresh_id'' = fresh_id' father tt in
140 (*CSC: computeinnertypes era true, il che e' proprio sbagliato, no? *)
141 (* First of all we compute the inner type and the inner sort *)
142 (* of the term. They may be useful in what follows. *)
143 (*CSC: This is a very inefficient way of computing inner types *)
144 (*CSC: and inner sorts: very deep terms have their types/sorts *)
145 (*CSC: computed again and again. *)
147 match cicReduction_whd context t with
148 C.Sort C.Prop -> `Prop
149 | C.Sort C.Set -> `Set
150 | C.Sort (C.Type u) -> `Type u
151 | C.Meta _ -> `Type (CicUniv.fresh())
152 | C.Sort C.CProp -> `CProp
154 prerr_endline ("Cic2acic.sort_of applied to: " ^ CicPp.ppterm t) ;
157 let ainnertypes,innertype,innersort,expected_available =
159 (*CSC: Here we need the algorithm for Coscoy's double type-inference *)
160 (*CSC: (expected type + inferred type). Just for now we use the usual *)
161 (*CSC: type-inference, but the result is very poor. As a very weak *)
162 (*CSC: patch, I apply whd to the computed type. Full beta *)
163 (*CSC: reduction would be a much better option. *)
164 (*CSC: solo per testare i tempi *)
168 let {D.synthesized = synthesized; D.expected = expected} =
169 if computeinnertypes then
170 cic_CicHash_find terms_to_types tt
172 (* We are already in an inner-type and Coscoy's double *)
173 (* type inference algorithm has not been applied. *)
175 (***CSC: patch per provare i tempi
176 CicReduction.whd context (xxx_type_of_aux' metasenv context tt) ; *)
177 (*if global_computeinnertypes then
178 Cic.Sort (Cic.Type (CicUniv.fresh()))
180 cicReduction_whd context (xxx_type_of_aux' metasenv context tt);
183 (* incr number_new_type_of_aux' ; *)
184 let innersort = (*XXXXX *) xxx_type_of_aux' metasenv context synthesized (* Cic.Sort Cic.Prop *) in
185 let ainnertypes,expected_available =
186 if computeinnertypes then
187 let annexpected,expected_available =
190 | Some expectedty' ->
192 (aux false (Some fresh_id'') context idrefs expectedty'),
197 aux false (Some fresh_id'') context idrefs synthesized ;
198 annexpected = annexpected
199 }, expected_available
203 ainnertypes,synthesized, sort_of innersort, expected_available
206 Not_found -> (* l'inner-type non e' nella tabella ==> sort <> Prop *)
207 (* CSC: Type or Set? I can not tell *)
208 let u = CicUniv.fresh() in
209 None,Cic.Sort (Cic.Type u),`Type u,false
210 (* TASSI non dovrebbe fare danni *)
214 if innersort = `Prop then
215 aux computeinnertypes (Some fresh_id'')
217 aux false (Some fresh_id'')
219 let add_inner_type id =
220 match ainnertypes with
222 | Some ainnertypes -> xxx_add ids_to_inner_types id ainnertypes
227 match get_nth context n with
228 (Some (C.Name s,_)) -> s
229 | _ -> "__" ^ string_of_int n
231 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
232 if innersort = `Prop && expected_available then
233 add_inner_type fresh_id'' ;
234 C.ARel (fresh_id'', List.nth idrefs (n-1), n, id)
235 | C.Var (uri,exp_named_subst) ->
236 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
237 if innersort = `Prop && expected_available then
238 add_inner_type fresh_id'' ;
239 let exp_named_subst' =
241 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
243 C.AVar (fresh_id'', uri,exp_named_subst')
245 let (_,canonical_context,_) = CicUtil.lookup_meta n metasenv in
246 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
247 if innersort = `Prop && expected_available then
248 add_inner_type fresh_id'' ;
249 C.AMeta (fresh_id'', n,
254 | _, Some t -> Some (aux' context idrefs t)
255 | Some _, None -> assert false (* due to typing rules *))
256 canonical_context l))
257 | C.Sort s -> C.ASort (fresh_id'', s)
258 | C.Implicit annotation -> C.AImplicit (fresh_id'', annotation)
260 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
261 if innersort = `Prop then
262 add_inner_type fresh_id'' ;
263 C.ACast (fresh_id'', aux' context idrefs v, aux' context idrefs t)
265 xxx_add ids_to_inner_sorts fresh_id''
266 (sort_of innertype) ;
267 let sourcetype = xxx_type_of_aux' metasenv context s in
268 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
269 (sort_of sourcetype) ;
274 if DoubleTypeInference.does_not_occur 1 t then
280 (fresh_id'', n', aux' context idrefs s,
281 aux' ((Some (n, C.Decl s))::context) (fresh_id''::idrefs) t)
282 | C.Lambda (n,s,t) ->
283 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
284 let sourcetype = xxx_type_of_aux' metasenv context s in
285 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
286 (sort_of sourcetype) ;
287 if innersort = `Prop then
289 let father_is_lambda =
293 match Hashtbl.find ids_to_terms father' with
297 if (not father_is_lambda) || expected_available then
298 add_inner_type fresh_id''
301 (fresh_id'',n, aux' context idrefs s,
302 aux' ((Some (n, C.Decl s)::context)) (fresh_id''::idrefs) t)
304 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
305 if innersort = `Prop then
306 add_inner_type fresh_id'' ;
308 (fresh_id'', n, aux' context idrefs s,
309 aux' ((Some (n, C.Def(s,None)))::context) (fresh_id''::idrefs) t)
311 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
312 if innersort = `Prop then
313 add_inner_type fresh_id'' ;
314 C.AAppl (fresh_id'', List.map (aux' context idrefs) l)
315 | C.Const (uri,exp_named_subst) ->
316 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
317 if innersort = `Prop && expected_available then
318 add_inner_type fresh_id'' ;
319 let exp_named_subst' =
321 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
323 C.AConst (fresh_id'', uri, exp_named_subst')
324 | C.MutInd (uri,tyno,exp_named_subst) ->
325 let exp_named_subst' =
327 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
329 C.AMutInd (fresh_id'', uri, tyno, exp_named_subst')
330 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
331 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
332 if innersort = `Prop && expected_available then
333 add_inner_type fresh_id'' ;
334 let exp_named_subst' =
336 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
338 C.AMutConstruct (fresh_id'', uri, tyno, consno, exp_named_subst')
339 | C.MutCase (uri, tyno, outty, term, patterns) ->
340 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
341 if innersort = `Prop then
342 add_inner_type fresh_id'' ;
343 C.AMutCase (fresh_id'', uri, tyno, aux' context idrefs outty,
344 aux' context idrefs term, List.map (aux' context idrefs) patterns)
345 | C.Fix (funno, funs) ->
347 List.map (function _ -> gen_id seed) funs in
348 let new_idrefs = List.rev fresh_idrefs @ idrefs in
350 List.map (fun (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) funs
352 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
353 if innersort = `Prop then
354 add_inner_type fresh_id'' ;
355 C.AFix (fresh_id'', funno,
357 (fun id (name, indidx, ty, bo) ->
358 (id, name, indidx, aux' context idrefs ty,
359 aux' (tys@context) new_idrefs bo)
362 | C.CoFix (funno, funs) ->
364 List.map (function _ -> gen_id seed) funs in
365 let new_idrefs = List.rev fresh_idrefs @ idrefs in
367 List.map (fun (name,ty,_) -> Some (C.Name name, C.Decl ty)) funs
369 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
370 if innersort = `Prop then
371 add_inner_type fresh_id'' ;
372 C.ACoFix (fresh_id'', funno,
374 (fun id (name, ty, bo) ->
375 (id, name, aux' context idrefs ty,
376 aux' (tys@context) new_idrefs bo)
381 let timea = Sys.time () in
382 let res = aux true None context idrefs t in
383 let timeb = Sys.time () in
385 ("+++++++++++++ Tempi della aux dentro alla acic_of_cic: "^ string_of_float (timeb -. timea)) ;
388 aux global_computeinnertypes None context idrefs t
391 let acic_of_cic_context ~computeinnertypes metasenv context idrefs t =
392 let ids_to_terms = Hashtbl.create 503 in
393 let ids_to_father_ids = Hashtbl.create 503 in
394 let ids_to_inner_sorts = Hashtbl.create 503 in
395 let ids_to_inner_types = Hashtbl.create 503 in
397 acic_of_cic_context' ~computeinnertypes seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
398 ids_to_inner_types metasenv context idrefs t,
399 ids_to_terms, ids_to_father_ids, ids_to_inner_sorts, ids_to_inner_types
402 let aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
403 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
404 metasenv (metano,context,goal)
406 let computeinnertypes = false in
407 let acic_of_cic_context =
408 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
409 ids_to_inner_types metasenv in
410 let _, acontext,final_idrefs =
412 (fun binding (context, acontext,idrefs) ->
413 let hid = "h" ^ string_of_int !hypotheses_seed in
414 Hashtbl.add ids_to_hypotheses hid binding ;
415 incr hypotheses_seed ;
417 Some (n,Cic.Def (t,_)) ->
418 let acic = acic_of_cic_context ~computeinnertypes context idrefs t None in
419 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
422 ((hid,Some (n,Cic.ADef acic))::acontext),(hid::idrefs)
423 | Some (n,Cic.Decl t) ->
424 let acic = acic_of_cic_context ~computeinnertypes context idrefs t None in
425 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
428 ((hid,Some (n,Cic.ADecl acic))::acontext),(hid::idrefs)
430 (* Invariant: "" is never looked up *)
431 (None::context),((hid,None)::acontext),""::idrefs
435 let agoal = acic_of_cic_context ~computeinnertypes context final_idrefs goal None in
436 (metano,acontext,agoal)
439 let asequent_of_sequent (metasenv:Cic.metasenv) (sequent:Cic.conjecture) =
440 let ids_to_terms = Hashtbl.create 503 in
441 let ids_to_father_ids = Hashtbl.create 503 in
442 let ids_to_inner_sorts = Hashtbl.create 503 in
443 let ids_to_inner_types = Hashtbl.create 503 in
444 let ids_to_hypotheses = Hashtbl.create 23 in
445 let hypotheses_seed = ref 0 in
446 let seed = ref 1 in (* 'i0' is used for the whole sequent *)
448 let i,canonical_context,term = sequent in
449 let canonical_context' =
451 (fun d canonical_context' ->
455 | Some (n, Cic.Decl t)->
456 Some (n, Cic.Decl (Unshare.unshare t))
457 | Some (n, Cic.Def (t,None)) ->
458 Some (n, Cic.Def ((Unshare.unshare t),None))
459 | Some (n,Cic.Def (bo,Some ty)) ->
460 Some (n, Cic.Def (Unshare.unshare bo,Some (Unshare.unshare ty)))
462 d::canonical_context'
463 ) canonical_context []
465 let term' = Unshare.unshare term in
466 (i,canonical_context',term')
468 let (metano,acontext,agoal) =
469 aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
470 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
471 metasenv unsh_sequent in
473 (("i0",metano,acontext,agoal),
474 ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_hypotheses))
477 let acic_object_of_cic_object ?(eta_fix=false) obj =
478 let module C = Cic in
479 let module E = Eta_fixing in
480 let ids_to_terms = Hashtbl.create 503 in
481 let ids_to_father_ids = Hashtbl.create 503 in
482 let ids_to_inner_sorts = Hashtbl.create 503 in
483 let ids_to_inner_types = Hashtbl.create 503 in
484 let ids_to_conjectures = Hashtbl.create 11 in
485 let ids_to_hypotheses = Hashtbl.create 127 in
486 let hypotheses_seed = ref 0 in
487 let conjectures_seed = ref 0 in
489 let acic_term_of_cic_term_context' =
490 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
491 ids_to_inner_types in
492 let acic_term_of_cic_term' = acic_term_of_cic_term_context' [] [] [] in
493 let aconjecture_of_conjecture' = aconjecture_of_conjecture seed
494 ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
495 ids_to_hypotheses hypotheses_seed in
496 let eta_fix metasenv context t =
497 let t = if eta_fix then E.eta_fix metasenv context t else t in
501 C.Constant (id,Some bo,ty,params,attrs) ->
502 let bo' = eta_fix [] [] bo in
503 let ty' = eta_fix [] [] ty in
504 let abo = acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty') in
505 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
507 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
508 | C.Constant (id,None,ty,params,attrs) ->
509 let ty' = eta_fix [] [] ty in
510 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
512 ("mettereaposto",None,id,None,aty,params,attrs)
513 | C.Variable (id,bo,ty,params,attrs) ->
514 let ty' = eta_fix [] [] ty in
519 let bo' = eta_fix [] [] bo in
520 Some (acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty'))
522 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
524 ("mettereaposto",id,abo,aty,params,attrs)
525 | C.CurrentProof (id,conjectures,bo,ty,params,attrs) ->
528 (function (i,canonical_context,term) ->
529 let canonical_context' =
531 (fun d canonical_context' ->
535 | Some (n, C.Decl t)->
536 Some (n, C.Decl (eta_fix conjectures canonical_context' t))
537 | Some (n, C.Def (t,None)) ->
539 C.Def ((eta_fix conjectures canonical_context' t),None))
540 | Some (_,C.Def (_,Some _)) -> assert false
542 d::canonical_context'
543 ) canonical_context []
545 let term' = eta_fix conjectures canonical_context' term in
546 (i,canonical_context',term')
551 (function (i,canonical_context,term) as conjecture ->
552 let cid = "c" ^ string_of_int !conjectures_seed in
553 xxx_add ids_to_conjectures cid conjecture ;
554 incr conjectures_seed ;
555 let (i,acanonical_context,aterm)
556 = aconjecture_of_conjecture' conjectures conjecture in
557 (cid,i,acanonical_context,aterm))
559 (* let time1 = Sys.time () in *)
560 let bo' = eta_fix conjectures' [] bo in
561 let ty' = eta_fix conjectures' [] ty in
563 let time2 = Sys.time () in
565 ("++++++++++ Tempi della eta_fix: "^ string_of_float (time2 -. time1)) ;
566 hashtbl_add_time := 0.0 ;
567 type_of_aux'_add_time := 0.0 ;
568 DoubleTypeInference.syntactic_equality_add_time := 0.0 ;
571 acic_term_of_cic_term_context' ~computeinnertypes:true conjectures' [] [] bo' (Some ty') in
572 let aty = acic_term_of_cic_term_context' ~computeinnertypes:false conjectures' [] [] ty' None in
574 let time3 = Sys.time () in
576 ("++++++++++++ Tempi della hashtbl_add_time: " ^ string_of_float !hashtbl_add_time) ;
578 ("++++++++++++ Tempi della type_of_aux'_add_time(" ^ string_of_int !number_new_type_of_aux' ^ "): " ^ string_of_float !type_of_aux'_add_time) ;
580 ("++++++++++++ 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) ;
582 ("++++++++++++ Tempi della syntactic_equality_add_time: " ^ string_of_float !DoubleTypeInference.syntactic_equality_add_time) ;
584 ("++++++++++ Tempi della acic_of_cic: " ^ string_of_float (time3 -. time2)) ;
586 ("++++++++++ Numero di iterazioni della acic_of_cic: " ^ string_of_int !seed) ;
589 ("mettereaposto","mettereaposto2",id,aconjectures,abo,aty,params,attrs)
590 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
593 (fun (name,i,arity,cl) ->
594 (name,i,Unshare.unshare arity,
595 List.map (fun (name,ty) -> name,Unshare.unshare ty) cl)) tys in
598 (fun (name,_,arity,_) ->
599 Some (C.Name name, C.Decl (Unshare.unshare arity))) tys in
600 let idrefs = List.map (function _ -> gen_id seed) tys in
603 (fun id (name,inductive,ty,cons) ->
606 (function (name,ty) ->
608 acic_term_of_cic_term_context' ~computeinnertypes:false [] context idrefs ty None)
612 acic_term_of_cic_term' ~computeinnertypes:false ty None,acons)
613 ) (List.rev idrefs) tys
615 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
617 aobj,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_inner_types,
618 ids_to_conjectures,ids_to_hypotheses
621 let plain_acic_term_of_cic_term =
622 let module C = Cic in
625 function () -> incr id; "i" ^ string_of_int !id in
626 let rec aux context t =
627 let fresh_id = mk_fresh_id () in
631 match get_nth context n with
632 idref,(Some (C.Name s,_)) -> idref,s
633 | idref,_ -> idref,"__" ^ string_of_int n
635 C.ARel (fresh_id, idref, n, id)
636 | C.Var (uri,exp_named_subst) ->
637 let exp_named_subst' =
639 (function i,t -> i, (aux context t)) exp_named_subst
641 C.AVar (fresh_id,uri,exp_named_subst')
643 | C.Meta _ -> assert false
644 | C.Sort s -> C.ASort (fresh_id, s)
646 C.ACast (fresh_id, aux context v, aux context t)
649 (fresh_id, n, aux context s,
650 aux ((fresh_id, Some (n, C.Decl s))::context) t)
651 | C.Lambda (n,s,t) ->
653 (fresh_id,n, aux context s,
654 aux ((fresh_id, Some (n, C.Decl s))::context) t)
657 (fresh_id, n, aux context s,
658 aux ((fresh_id, Some (n, C.Def(s,None)))::context) t)
660 C.AAppl (fresh_id, List.map (aux context) l)
661 | C.Const (uri,exp_named_subst) ->
662 let exp_named_subst' =
664 (function i,t -> i, (aux context t)) exp_named_subst
666 C.AConst (fresh_id, uri, exp_named_subst')
667 | C.MutInd (uri,tyno,exp_named_subst) ->
668 let exp_named_subst' =
670 (function i,t -> i, (aux context t)) exp_named_subst
672 C.AMutInd (fresh_id, uri, tyno, exp_named_subst')
673 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
674 let exp_named_subst' =
676 (function i,t -> i, (aux context t)) exp_named_subst
678 C.AMutConstruct (fresh_id, uri, tyno, consno, exp_named_subst')
679 | C.MutCase (uri, tyno, outty, term, patterns) ->
680 C.AMutCase (fresh_id, uri, tyno, aux context outty,
681 aux context term, List.map (aux context) patterns)
682 | C.Fix (funno, funs) ->
685 (fun (name,_,ty,_) -> mk_fresh_id (), Some (C.Name name, C.Decl ty)) funs
687 C.AFix (fresh_id, funno,
689 (fun (id,_) (name, indidx, ty, bo) ->
690 (id, name, indidx, aux context ty, aux (tys@context) bo)
693 | C.CoFix (funno, funs) ->
695 List.map (fun (name,ty,_) ->
696 mk_fresh_id (),Some (C.Name name, C.Decl ty)) funs
698 C.ACoFix (fresh_id, funno,
700 (fun (id,_) (name, ty, bo) ->
701 (id, name, aux context ty, aux (tys@context) bo)
708 let plain_acic_object_of_cic_object obj =
709 let module C = Cic in
712 function () -> incr id; "it" ^ string_of_int !id
715 C.Constant (id,Some bo,ty,params,attrs) ->
716 let abo = plain_acic_term_of_cic_term [] bo in
717 let aty = plain_acic_term_of_cic_term [] ty in
719 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
720 | C.Constant (id,None,ty,params,attrs) ->
721 let aty = plain_acic_term_of_cic_term [] ty in
723 ("mettereaposto",None,id,None,aty,params,attrs)
724 | C.Variable (id,bo,ty,params,attrs) ->
728 | Some bo -> Some (plain_acic_term_of_cic_term [] bo)
730 let aty = plain_acic_term_of_cic_term [] ty in
732 ("mettereaposto",id,abo,aty,params,attrs)
733 | C.CurrentProof _ -> assert false
734 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
737 (fun (name,_,arity,_) ->
738 mk_fresh_id (), Some (C.Name name, C.Decl arity)) tys in
741 (fun (id,_) (name,inductive,ty,cons) ->
744 (function (name,ty) ->
746 plain_acic_term_of_cic_term context ty)
749 (id,name,inductive,plain_acic_term_of_cic_term [] ty,acons)
752 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)