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;; *)
45 (* let t1 = Sys.time () in *)
47 (* let t2 = Sys.time () in
48 hashtbl_add_time := !hashtbl_add_time +. t2 -. t1 *)
51 (* let number_new_type_of_aux' = ref 0;;
52 let type_of_aux'_add_time = ref 0.0;; *)
54 let xxx_type_of_aux' m c t =
55 (* let t1 = Sys.time () in *)
58 CicTypeChecker.type_of_aux' m c t CicUniv.empty_ugraph
60 | CicTypeChecker.AssertFailure _
61 | CicTypeChecker.TypeCheckerFailure _ ->
62 Cic.Sort Cic.Prop, CicUniv.empty_ugraph
64 (* let t2 = Sys.time () in
65 type_of_aux'_add_time := !type_of_aux'_add_time +. t2 -. t1 ; *)
70 {annsynthesized : Cic.annterm ; annexpected : Cic.annterm option}
74 let res = "i" ^ string_of_int !seed in
79 let fresh_id seed ids_to_terms ids_to_father_ids =
81 let res = gen_id seed in
82 xxx_add ids_to_father_ids res father ;
83 xxx_add ids_to_terms res t ;
87 let source_id_of_id id = "#source#" ^ id;;
89 exception NotEnoughElements;;
91 (*CSC: cut&paste da cicPp.ml *)
92 (* get_nth l n returns the nth element of the list l if it exists or *)
93 (* raises NotEnoughElements if l has less than n elements *)
97 | (n, he::tail) when n > 1 -> get_nth tail (n-1)
98 | (_,_) -> raise NotEnoughElements
101 let acic_of_cic_context' ~computeinnertypes:global_computeinnertypes
102 seed ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
103 metasenv context idrefs t expectedty
105 let module D = DoubleTypeInference in
106 let module C = Cic in
107 let fresh_id' = fresh_id seed ids_to_terms ids_to_father_ids in
108 (* let time1 = Sys.time () in *)
111 let time0 = Sys.time () in
112 let prova = CicTypeChecker.type_of_aux' metasenv context t in
113 let time1 = Sys.time () in
114 prerr_endline ("*** Fine type_inference:" ^ (string_of_float (time1 -. time0)));
115 let res = D.double_type_of metasenv context t expectedty in
116 let time2 = Sys.time () in
117 prerr_endline ("*** Fine double_type_inference:" ^ (string_of_float (time2 -. time1)));
120 if global_computeinnertypes then
121 D.double_type_of metasenv context t expectedty
123 Cic.CicHash.create 1 (* empty table *)
126 let time2 = Sys.time () in
128 ("++++++++++++ Tempi della double_type_of: "^ string_of_float (time2 -. time1)) ;
130 let rec aux computeinnertypes father context idrefs tt =
131 let fresh_id'' = fresh_id' father tt in
132 (*CSC: computeinnertypes era true, il che e' proprio sbagliato, no? *)
133 let aux' = aux computeinnertypes (Some fresh_id'') in
134 (* First of all we compute the inner type and the inner sort *)
135 (* of the term. They may be useful in what follows. *)
136 (*CSC: This is a very inefficient way of computing inner types *)
137 (*CSC: and inner sorts: very deep terms have their types/sorts *)
138 (*CSC: computed again and again. *)
140 match CicReduction.whd context t with
141 C.Sort C.Prop -> `Prop
142 | C.Sort C.Set -> `Set
143 | C.Sort (C.Type u) -> `Type u
144 | C.Meta _ -> `Type (CicUniv.fresh())
145 | C.Sort C.CProp -> `CProp
147 prerr_endline ("Cic2acic.sort_of applied to: " ^ CicPp.ppterm t) ;
150 let ainnertypes,innertype,innersort,expected_available =
151 (*CSC: Here we need the algorithm for Coscoy's double type-inference *)
152 (*CSC: (expected type + inferred type). Just for now we use the usual *)
153 (*CSC: type-inference, but the result is very poor. As a very weak *)
154 (*CSC: patch, I apply whd to the computed type. Full beta *)
155 (*CSC: reduction would be a much better option. *)
156 (*CSC: solo per testare i tempi *)
160 let {D.synthesized = synthesized; D.expected = expected} =
161 if computeinnertypes then
162 Cic.CicHash.find terms_to_types tt
164 (* We are already in an inner-type and Coscoy's double *)
165 (* type inference algorithm has not been applied. *)
167 (***CSC: patch per provare i tempi
168 CicReduction.whd context (xxx_type_of_aux' metasenv context tt) ; *)
169 (*if global_computeinnertypes then
170 Cic.Sort (Cic.Type (CicUniv.fresh()))
172 CicReduction.whd context (xxx_type_of_aux' metasenv context tt);
175 (* incr number_new_type_of_aux' ; *)
176 let innersort = (*XXXXX *) xxx_type_of_aux' metasenv context synthesized (* Cic.Sort Cic.Prop *) in
177 let ainnertypes,expected_available =
178 if computeinnertypes then
179 let annexpected,expected_available =
182 | Some expectedty' ->
184 (aux false (Some fresh_id'') context idrefs expectedty'),
189 aux false (Some fresh_id'') context idrefs synthesized ;
190 annexpected = annexpected
191 }, expected_available
195 ainnertypes,synthesized, sort_of innersort, expected_available
198 Not_found -> (* l'inner-type non e' nella tabella ==> sort <> Prop *)
199 (* CSC: Type or Set? I can not tell *)
200 let u = CicUniv.fresh() in
201 None,Cic.Sort (Cic.Type u),`Type u,false
202 (* TASSI non dovrebbe fare danni *)
205 let add_inner_type id =
206 match ainnertypes with
208 | Some ainnertypes -> xxx_add ids_to_inner_types id ainnertypes
213 match get_nth context n with
214 (Some (C.Name s,_)) -> s
215 | _ -> "__" ^ string_of_int n
217 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
218 if innersort = `Prop && expected_available then
219 add_inner_type fresh_id'' ;
220 C.ARel (fresh_id'', List.nth idrefs (n-1), n, id)
221 | C.Var (uri,exp_named_subst) ->
222 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
223 if innersort = `Prop && expected_available then
224 add_inner_type fresh_id'' ;
225 let exp_named_subst' =
227 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
229 C.AVar (fresh_id'', uri,exp_named_subst')
231 let (_,canonical_context,_) = CicUtil.lookup_meta n metasenv in
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.AMeta (fresh_id'', n,
240 | _, Some t -> Some (aux' context idrefs t)
241 | Some _, None -> assert false (* due to typing rules *))
242 canonical_context l))
243 | C.Sort s -> C.ASort (fresh_id'', s)
244 | C.Implicit annotation -> C.AImplicit (fresh_id'', annotation)
246 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
247 if innersort = `Prop then
248 add_inner_type fresh_id'' ;
249 C.ACast (fresh_id'', aux' context idrefs v, aux' context idrefs t)
251 xxx_add ids_to_inner_sorts fresh_id''
252 (sort_of innertype) ;
253 let sourcetype = xxx_type_of_aux' metasenv context s in
254 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
255 (sort_of sourcetype) ;
260 if DoubleTypeInference.does_not_occur 1 t then
266 (fresh_id'', n', aux' context idrefs s,
267 aux' ((Some (n, C.Decl s))::context) (fresh_id''::idrefs) t)
268 | C.Lambda (n,s,t) ->
269 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
270 let sourcetype = xxx_type_of_aux' metasenv context s in
271 xxx_add ids_to_inner_sorts (source_id_of_id fresh_id'')
272 (sort_of sourcetype) ;
273 if innersort = `Prop then
275 let father_is_lambda =
279 match Hashtbl.find ids_to_terms father' with
283 if (not father_is_lambda) || expected_available then
284 add_inner_type fresh_id''
287 (fresh_id'',n, aux' context idrefs s,
288 aux' ((Some (n, C.Decl s)::context)) (fresh_id''::idrefs) t)
290 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
291 if innersort = `Prop then
292 add_inner_type fresh_id'' ;
294 (fresh_id'', n, aux' context idrefs s,
295 aux' ((Some (n, C.Def(s,None)))::context) (fresh_id''::idrefs) t)
297 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
298 if innersort = `Prop then
299 add_inner_type fresh_id'' ;
300 C.AAppl (fresh_id'', List.map (aux' context idrefs) l)
301 | C.Const (uri,exp_named_subst) ->
302 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
303 if innersort = `Prop && expected_available then
304 add_inner_type fresh_id'' ;
305 let exp_named_subst' =
307 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
309 C.AConst (fresh_id'', uri, exp_named_subst')
310 | C.MutInd (uri,tyno,exp_named_subst) ->
311 let exp_named_subst' =
313 (function i,t -> i, (aux' context idrefs t)) exp_named_subst
315 C.AMutInd (fresh_id'', uri, tyno, exp_named_subst')
316 | C.MutConstruct (uri,tyno,consno,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.AMutConstruct (fresh_id'', uri, tyno, consno, exp_named_subst')
325 | C.MutCase (uri, tyno, outty, term, patterns) ->
326 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
327 if innersort = `Prop then
328 add_inner_type fresh_id'' ;
329 C.AMutCase (fresh_id'', uri, tyno, aux' context idrefs outty,
330 aux' context idrefs term, List.map (aux' context idrefs) patterns)
331 | C.Fix (funno, funs) ->
333 List.map (function _ -> gen_id seed) funs in
334 let new_idrefs = List.rev fresh_idrefs @ idrefs in
336 List.map (fun (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) funs
338 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
339 if innersort = `Prop then
340 add_inner_type fresh_id'' ;
341 C.AFix (fresh_id'', funno,
343 (fun id (name, indidx, ty, bo) ->
344 (id, name, indidx, aux' context idrefs ty,
345 aux' (tys@context) new_idrefs bo)
348 | C.CoFix (funno, funs) ->
350 List.map (function _ -> gen_id seed) funs in
351 let new_idrefs = List.rev fresh_idrefs @ idrefs in
353 List.map (fun (name,ty,_) -> Some (C.Name name, C.Decl ty)) funs
355 xxx_add ids_to_inner_sorts fresh_id'' innersort ;
356 if innersort = `Prop then
357 add_inner_type fresh_id'' ;
358 C.ACoFix (fresh_id'', funno,
360 (fun id (name, ty, bo) ->
361 (id, name, aux' context idrefs ty,
362 aux' (tys@context) new_idrefs bo)
367 let timea = Sys.time () in
368 let res = aux true None context idrefs t in
369 let timeb = Sys.time () in
371 ("+++++++++++++ Tempi della aux dentro alla acic_of_cic: "^ string_of_float (timeb -. timea)) ;
374 aux global_computeinnertypes None context idrefs t
377 let acic_of_cic_context ~computeinnertypes metasenv context idrefs t =
378 let ids_to_terms = Hashtbl.create 503 in
379 let ids_to_father_ids = Hashtbl.create 503 in
380 let ids_to_inner_sorts = Hashtbl.create 503 in
381 let ids_to_inner_types = Hashtbl.create 503 in
383 acic_of_cic_context' ~computeinnertypes seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
384 ids_to_inner_types metasenv context idrefs t,
385 ids_to_terms, ids_to_father_ids, ids_to_inner_sorts, ids_to_inner_types
388 let aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
389 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
390 metasenv (metano,context,goal)
392 let computeinnertypes = false in
393 let acic_of_cic_context =
394 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
395 ids_to_inner_types metasenv in
396 let _, acontext,final_idrefs =
398 (fun binding (context, acontext,idrefs) ->
399 let hid = "h" ^ string_of_int !hypotheses_seed in
400 Hashtbl.add ids_to_hypotheses hid binding ;
401 incr hypotheses_seed ;
403 Some (n,Cic.Def (t,_)) ->
404 let acic = acic_of_cic_context ~computeinnertypes context idrefs t None in
405 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
408 ((hid,Some (n,Cic.ADef acic))::acontext),(hid::idrefs)
409 | Some (n,Cic.Decl t) ->
410 let acic = acic_of_cic_context ~computeinnertypes context idrefs t None in
411 Hashtbl.replace ids_to_father_ids (CicUtil.id_of_annterm acic)
414 ((hid,Some (n,Cic.ADecl acic))::acontext),(hid::idrefs)
416 (* Invariant: "" is never looked up *)
417 (None::context),((hid,None)::acontext),""::idrefs
421 let agoal = acic_of_cic_context ~computeinnertypes context final_idrefs goal None in
422 (metano,acontext,agoal)
425 let asequent_of_sequent (metasenv:Cic.metasenv) (sequent:Cic.conjecture) =
426 let ids_to_terms = Hashtbl.create 503 in
427 let ids_to_father_ids = Hashtbl.create 503 in
428 let ids_to_inner_sorts = Hashtbl.create 503 in
429 let ids_to_inner_types = Hashtbl.create 503 in
430 let ids_to_hypotheses = Hashtbl.create 23 in
431 let hypotheses_seed = ref 0 in
432 let seed = ref 1 in (* 'i0' is used for the whole sequent *)
434 let i,canonical_context,term = sequent in
435 let canonical_context' =
437 (fun d canonical_context' ->
441 | Some (n, Cic.Decl t)->
442 Some (n, Cic.Decl (Unshare.unshare t))
443 | Some (n, Cic.Def (t,None)) ->
444 Some (n, Cic.Def ((Unshare.unshare t),None))
445 | Some (n,Cic.Def (bo,Some ty)) ->
446 Some (n, Cic.Def (Unshare.unshare bo,Some (Unshare.unshare ty)))
448 d::canonical_context'
449 ) canonical_context []
451 let term' = Unshare.unshare term in
452 (i,canonical_context',term')
454 let (metano,acontext,agoal) =
455 aconjecture_of_conjecture seed ids_to_terms ids_to_father_ids
456 ids_to_inner_sorts ids_to_inner_types ids_to_hypotheses hypotheses_seed
457 metasenv unsh_sequent in
459 (("i0",metano,acontext,agoal),
460 ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_hypotheses))
463 let acic_object_of_cic_object ?(eta_fix=true) obj =
464 let module C = Cic in
465 let module E = Eta_fixing in
466 let ids_to_terms = Hashtbl.create 503 in
467 let ids_to_father_ids = Hashtbl.create 503 in
468 let ids_to_inner_sorts = Hashtbl.create 503 in
469 let ids_to_inner_types = Hashtbl.create 503 in
470 let ids_to_conjectures = Hashtbl.create 11 in
471 let ids_to_hypotheses = Hashtbl.create 127 in
472 let hypotheses_seed = ref 0 in
473 let conjectures_seed = ref 0 in
475 let acic_term_of_cic_term_context' =
476 acic_of_cic_context' seed ids_to_terms ids_to_father_ids ids_to_inner_sorts
477 ids_to_inner_types in
478 let acic_term_of_cic_term' = acic_term_of_cic_term_context' [] [] [] in
479 let aconjecture_of_conjecture' = aconjecture_of_conjecture seed
480 ids_to_terms ids_to_father_ids ids_to_inner_sorts ids_to_inner_types
481 ids_to_hypotheses hypotheses_seed in
482 let eta_fix metasenv context t =
483 let t = if eta_fix then E.eta_fix metasenv context t else t in
487 C.Constant (id,Some bo,ty,params,attrs) ->
488 let bo' = eta_fix [] [] bo in
489 let ty' = eta_fix [] [] ty in
490 let abo = acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty') in
491 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
493 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
494 | C.Constant (id,None,ty,params,attrs) ->
495 let ty' = eta_fix [] [] ty in
496 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
498 ("mettereaposto",None,id,None,aty,params,attrs)
499 | C.Variable (id,bo,ty,params,attrs) ->
500 let ty' = eta_fix [] [] ty in
505 let bo' = eta_fix [] [] bo in
506 Some (acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty'))
508 let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
510 ("mettereaposto",id,abo,aty,params,attrs)
511 | C.CurrentProof (id,conjectures,bo,ty,params,attrs) ->
514 (function (i,canonical_context,term) ->
515 let canonical_context' =
517 (fun d canonical_context' ->
521 | Some (n, C.Decl t)->
522 Some (n, C.Decl (eta_fix conjectures canonical_context' t))
523 | Some (n, C.Def (t,None)) ->
525 C.Def ((eta_fix conjectures canonical_context' t),None))
526 | Some (_,C.Def (_,Some _)) -> assert false
528 d::canonical_context'
529 ) canonical_context []
531 let term' = eta_fix conjectures canonical_context' term in
532 (i,canonical_context',term')
537 (function (i,canonical_context,term) as conjecture ->
538 let cid = "c" ^ string_of_int !conjectures_seed in
539 xxx_add ids_to_conjectures cid conjecture ;
540 incr conjectures_seed ;
541 let (i,acanonical_context,aterm)
542 = aconjecture_of_conjecture' conjectures conjecture in
543 (cid,i,acanonical_context,aterm))
545 (* let time1 = Sys.time () in *)
546 let bo' = eta_fix conjectures' [] bo in
547 let ty' = eta_fix conjectures' [] ty in
549 let time2 = Sys.time () in
551 ("++++++++++ Tempi della eta_fix: "^ string_of_float (time2 -. time1)) ;
552 hashtbl_add_time := 0.0 ;
553 type_of_aux'_add_time := 0.0 ;
554 DoubleTypeInference.syntactic_equality_add_time := 0.0 ;
557 acic_term_of_cic_term_context' ~computeinnertypes:true conjectures' [] [] bo' (Some ty') in
558 let aty = acic_term_of_cic_term_context' ~computeinnertypes:false conjectures' [] [] ty' None in
560 let time3 = Sys.time () in
562 ("++++++++++++ Tempi della hashtbl_add_time: " ^ string_of_float !hashtbl_add_time) ;
564 ("++++++++++++ Tempi della type_of_aux'_add_time(" ^ string_of_int !number_new_type_of_aux' ^ "): " ^ string_of_float !type_of_aux'_add_time) ;
566 ("++++++++++++ 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) ;
568 ("++++++++++++ Tempi della syntactic_equality_add_time: " ^ string_of_float !DoubleTypeInference.syntactic_equality_add_time) ;
570 ("++++++++++ Tempi della acic_of_cic: " ^ string_of_float (time3 -. time2)) ;
572 ("++++++++++ Numero di iterazioni della acic_of_cic: " ^ string_of_int !seed) ;
575 ("mettereaposto","mettereaposto2",id,aconjectures,abo,aty,params,attrs)
576 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
579 (fun (name,i,arity,cl) ->
580 (name,i,Unshare.unshare arity,
581 List.map (fun (name,ty) -> name,Unshare.unshare ty) cl)) tys in
584 (fun (name,_,arity,_) ->
585 Some (C.Name name, C.Decl (Unshare.unshare arity))) tys in
586 let idrefs = List.map (function _ -> gen_id seed) tys in
589 (fun id (name,inductive,ty,cons) ->
592 (function (name,ty) ->
594 acic_term_of_cic_term_context' ~computeinnertypes:false [] context idrefs ty None)
598 acic_term_of_cic_term' ~computeinnertypes:false ty None,acons)
599 ) (List.rev idrefs) tys
601 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
603 aobj,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_inner_types,
604 ids_to_conjectures,ids_to_hypotheses
607 let plain_acic_term_of_cic_term =
608 let module C = Cic in
611 function () -> incr id; "i" ^ string_of_int !id in
612 let rec aux context t =
613 let fresh_id = mk_fresh_id () in
617 match get_nth context n with
618 idref,(Some (C.Name s,_)) -> idref,s
619 | idref,_ -> idref,"__" ^ string_of_int n
621 C.ARel (fresh_id, idref, n, id)
622 | C.Var (uri,exp_named_subst) ->
623 let exp_named_subst' =
625 (function i,t -> i, (aux context t)) exp_named_subst
627 C.AVar (fresh_id,uri,exp_named_subst')
629 | C.Meta _ -> assert false
630 | C.Sort s -> C.ASort (fresh_id, s)
632 C.ACast (fresh_id, aux context v, aux context t)
635 (fresh_id, n, aux context s,
636 aux ((fresh_id, Some (n, C.Decl s))::context) t)
637 | C.Lambda (n,s,t) ->
639 (fresh_id,n, aux context s,
640 aux ((fresh_id, Some (n, C.Decl s))::context) t)
643 (fresh_id, n, aux context s,
644 aux ((fresh_id, Some (n, C.Def(s,None)))::context) t)
646 C.AAppl (fresh_id, List.map (aux context) l)
647 | C.Const (uri,exp_named_subst) ->
648 let exp_named_subst' =
650 (function i,t -> i, (aux context t)) exp_named_subst
652 C.AConst (fresh_id, uri, exp_named_subst')
653 | C.MutInd (uri,tyno,exp_named_subst) ->
654 let exp_named_subst' =
656 (function i,t -> i, (aux context t)) exp_named_subst
658 C.AMutInd (fresh_id, uri, tyno, exp_named_subst')
659 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
660 let exp_named_subst' =
662 (function i,t -> i, (aux context t)) exp_named_subst
664 C.AMutConstruct (fresh_id, uri, tyno, consno, exp_named_subst')
665 | C.MutCase (uri, tyno, outty, term, patterns) ->
666 C.AMutCase (fresh_id, uri, tyno, aux context outty,
667 aux context term, List.map (aux context) patterns)
668 | C.Fix (funno, funs) ->
671 (fun (name,_,ty,_) -> mk_fresh_id (), Some (C.Name name, C.Decl ty)) funs
673 C.AFix (fresh_id, funno,
675 (fun (id,_) (name, indidx, ty, bo) ->
676 (id, name, indidx, aux context ty, aux (tys@context) bo)
679 | C.CoFix (funno, funs) ->
681 List.map (fun (name,ty,_) ->
682 mk_fresh_id (),Some (C.Name name, C.Decl ty)) funs
684 C.ACoFix (fresh_id, funno,
686 (fun (id,_) (name, ty, bo) ->
687 (id, name, aux context ty, aux (tys@context) bo)
694 let plain_acic_object_of_cic_object obj =
695 let module C = Cic in
698 function () -> incr id; "it" ^ string_of_int !id
701 C.Constant (id,Some bo,ty,params,attrs) ->
702 let abo = plain_acic_term_of_cic_term [] bo in
703 let aty = plain_acic_term_of_cic_term [] ty in
705 ("mettereaposto",Some "mettereaposto2",id,Some abo,aty,params,attrs)
706 | C.Constant (id,None,ty,params,attrs) ->
707 let aty = plain_acic_term_of_cic_term [] ty in
709 ("mettereaposto",None,id,None,aty,params,attrs)
710 | C.Variable (id,bo,ty,params,attrs) ->
714 | Some bo -> Some (plain_acic_term_of_cic_term [] bo)
716 let aty = plain_acic_term_of_cic_term [] ty in
718 ("mettereaposto",id,abo,aty,params,attrs)
719 | C.CurrentProof _ -> assert false
720 | C.InductiveDefinition (tys,params,paramsno,attrs) ->
723 (fun (name,_,arity,_) ->
724 mk_fresh_id (), Some (C.Name name, C.Decl arity)) tys in
727 (fun (id,_) (name,inductive,ty,cons) ->
730 (function (name,ty) ->
732 plain_acic_term_of_cic_term context ty)
735 (id,name,inductive,plain_acic_term_of_cic_term [] ty,acons)
738 C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)