]> matita.cs.unibo.it Git - helm.git/blob - components/cic_acic/cic2acic.ml
6cb2ad9a21fbbf4afaa16c3704c97a979daecf47
[helm.git] / components / cic_acic / cic2acic.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (* $Id$ *)
27
28 type sort_kind = [ `Prop | `Set | `Type of CicUniv.universe | `CProp ]
29
30 let string_of_sort = function
31   | `Prop -> "Prop"
32   | `Set -> "Set"
33   | `Type u -> "Type:" ^ string_of_int (CicUniv.univno u)
34   | `CProp -> "CProp"
35
36 let sort_of_sort = function
37   | Cic.Prop  -> `Prop
38   | Cic.Set   -> `Set
39   | Cic.Type u -> `Type u
40   | Cic.CProp -> `CProp
41
42 (* let hashtbl_add_time = ref 0.0;; *)
43
44 let xxx_add_profiler = HExtlib.profile "xxx_add";;
45 let xxx_add h k v =
46  xxx_add_profiler.HExtlib.profile (Hashtbl.add h k) v
47 ;;
48
49 let xxx_type_of_aux' m c t =
50  let res,_ =
51    try
52     CicTypeChecker.type_of_aux' m c t CicUniv.empty_ugraph
53    with
54    | CicTypeChecker.AssertFailure _
55    | CicTypeChecker.TypeCheckerFailure _ ->
56        Cic.Sort Cic.Prop, CicUniv.empty_ugraph
57   in
58  res
59 ;;
60
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
64
65 type anntypes =
66  {annsynthesized : Cic.annterm ; annexpected : Cic.annterm option}
67 ;;
68
69 let gen_id seed =
70  let res = "i" ^ string_of_int !seed in
71   incr seed ;
72   res
73 ;;
74
75 let fresh_id seed ids_to_terms ids_to_father_ids =
76  fun father t ->
77   let res = gen_id seed in
78    xxx_add ids_to_father_ids res father ;
79    xxx_add ids_to_terms res t ;
80    res
81 ;;
82
83 let source_id_of_id id = "#source#" ^ id;;
84
85 exception NotEnoughElements;;
86
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             *)
90 let rec get_nth l n =
91  match (n,l) with
92     (1, he::_) -> he
93   | (n, he::tail) when n > 1 -> get_nth tail (n-1)
94   | (_,_) -> raise NotEnoughElements
95 ;;
96
97
98 let profiler_for_find = HExtlib.profile "CicHash" ;;
99 let profiler_for_whd = HExtlib.profile "whd" ;;
100
101 let cic_CicHash_find a b =  
102   profiler_for_find.HExtlib.profile (Cic.CicHash.find a) b
103 ;;
104
105 let cicReduction_whd c t = 
106  profiler_for_whd.HExtlib.profile (CicReduction.whd c) t
107 ;;
108
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
112 =
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 *)
117    let terms_to_types =
118 (*
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)));
126      res 
127 *)
128     if global_computeinnertypes then
129      D.double_type_of metasenv context t expectedty
130     else
131      Cic.CicHash.create 1 (* empty table *)
132    in
133 (*
134    let time2 = Sys.time () in
135    prerr_endline
136     ("++++++++++++ Tempi della double_type_of: "^ string_of_float (time2 -. time1)) ;
137 *)
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.                               *)
146       let sort_of t =
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
153         | t              ->
154             prerr_endline ("Cic2acic.sort_of applied to: " ^ CicPp.ppterm t) ;
155             assert false
156       in
157        let ainnertypes,innertype,innersort,expected_available =
158
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 *)
165 (*XXXXXXX *)
166         try
167 (* *)
168         let {D.synthesized = synthesized; D.expected = expected} =
169          if computeinnertypes then
170           cic_CicHash_find terms_to_types tt
171          else
172           (* We are already in an inner-type and Coscoy's double *)
173           (* type inference algorithm has not been applied.      *)
174           { D.synthesized =
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()))
179             else*)
180               cicReduction_whd context (xxx_type_of_aux' metasenv context tt);
181           D.expected = None}
182         in
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 =
188                match expected with
189                   None -> None,false
190                 | Some expectedty' ->
191                    Some
192                     (aux false (Some fresh_id'') context idrefs expectedty'),
193                     true
194             in
195              Some
196               {annsynthesized =
197                 aux false (Some fresh_id'') context idrefs synthesized ;
198                annexpected = annexpected
199               }, expected_available
200            else
201             None,false
202           in
203            ainnertypes,synthesized, sort_of innersort, expected_available
204 (*XXXXXXXX *)
205         with
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 *)
211 (* *)
212        in
213         let aux' =
214          if innersort = `Prop then
215           aux computeinnertypes (Some fresh_id'')
216          else
217           aux false (Some fresh_id'')
218         in
219         let add_inner_type id =
220          match ainnertypes with
221             None -> ()
222           | Some ainnertypes -> xxx_add ids_to_inner_types id ainnertypes
223         in
224          match tt with
225             C.Rel n ->
226              let id =
227               match get_nth context n with
228                  (Some (C.Name s,_)) -> s
229                | _ -> "__" ^ string_of_int n
230              in
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' =
240               List.map
241                (function i,t -> i, (aux' context idrefs t)) exp_named_subst
242              in
243               C.AVar (fresh_id'', uri,exp_named_subst')
244           | C.Meta (n,l) ->
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,
250               (List.map2
251                 (fun ct t ->
252                   match (ct, t) with
253                   | None, _ -> None
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)
259           | C.Cast (v,t) ->
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)
264           | C.Prod (n,s,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) ;
270               let n' =
271                match n with
272                   C.Anonymous -> n
273                 | C.Name n' ->
274                    if DoubleTypeInference.does_not_occur 1 t then
275                     C.Anonymous
276                    else
277                     C.Name n'
278               in
279                C.AProd
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
288                begin
289                 let father_is_lambda =
290                  match father with
291                     None -> false
292                   | Some father' ->
293                      match Hashtbl.find ids_to_terms father' with
294                         C.Lambda _ -> true
295                       | _ -> false
296                 in
297                  if (not father_is_lambda) || expected_available then
298                   add_inner_type fresh_id''
299                end ;
300               C.ALambda
301                (fresh_id'',n, aux' context idrefs s,
302                 aux' ((Some (n, C.Decl s)::context)) (fresh_id''::idrefs) t)
303           | C.LetIn (n,s,t) ->
304              xxx_add ids_to_inner_sorts fresh_id'' innersort ;
305              if innersort = `Prop then
306               add_inner_type fresh_id'' ;
307              C.ALetIn
308               (fresh_id'', n, aux' context idrefs s,
309                aux' ((Some (n, C.Def(s,None)))::context) (fresh_id''::idrefs) t)
310           | C.Appl l ->
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' =
320               List.map
321                (function i,t -> i, (aux' context idrefs t)) exp_named_subst
322              in
323               C.AConst (fresh_id'', uri, exp_named_subst')
324           | C.MutInd (uri,tyno,exp_named_subst) ->
325              let exp_named_subst' =
326               List.map
327                (function i,t -> i, (aux' context idrefs t)) exp_named_subst
328              in
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' =
335               List.map
336                (function i,t -> i, (aux' context idrefs t)) exp_named_subst
337              in
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) ->
346              let fresh_idrefs =
347               List.map (function _ -> gen_id seed) funs in
348              let new_idrefs = List.rev fresh_idrefs @ idrefs in
349              let tys =
350               List.map (fun (name,_,ty,_) -> Some (C.Name name, C.Decl ty)) funs
351              in
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,
356                List.map2
357                 (fun id (name, indidx, ty, bo) ->
358                   (id, name, indidx, aux' context idrefs ty,
359                     aux' (tys@context) new_idrefs bo)
360                 ) fresh_idrefs funs
361              )
362           | C.CoFix (funno, funs) ->
363              let fresh_idrefs =
364               List.map (function _ -> gen_id seed) funs in
365              let new_idrefs = List.rev fresh_idrefs @ idrefs in
366              let tys =
367               List.map (fun (name,ty,_) -> Some (C.Name name, C.Decl ty)) funs
368              in
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,
373                List.map2
374                 (fun id (name, ty, bo) ->
375                   (id, name, aux' context idrefs ty,
376                     aux' (tys@context) new_idrefs bo)
377                 ) fresh_idrefs funs
378               )
379         in
380 (*
381          let timea = Sys.time () in
382          let res = aux true None context idrefs t in
383          let timeb = Sys.time () in
384           prerr_endline
385            ("+++++++++++++ Tempi della aux dentro alla acic_of_cic: "^ string_of_float (timeb -. timea)) ;
386           res
387 *)
388   aux global_computeinnertypes None context idrefs t
389 ;;
390
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
396  let seed = ref 0 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
400 ;;
401
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)
405
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 =
411     (List.fold_right
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 ;
416            match binding with
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)
420                   (Some hid);
421                  (binding::context),
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)
426                   (Some hid);
427                  (binding::context),
428                    ((hid,Some (n,Cic.ADecl acic))::acontext),(hid::idrefs)
429              | None ->
430                  (* Invariant: "" is never looked up *)
431                   (None::context),((hid,None)::acontext),""::idrefs
432          ) context ([],[],[])
433        )
434   in 
435   let agoal = acic_of_cic_context ~computeinnertypes context final_idrefs goal None in
436   (metano,acontext,agoal)
437 ;;
438
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 *)
447     let unsh_sequent =
448      let i,canonical_context,term = sequent in
449       let canonical_context' =
450        List.fold_right
451         (fun d canonical_context' ->
452           let d =
453            match d with
454               None -> None
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)))
461           in
462            d::canonical_context'
463         ) canonical_context []
464       in
465       let term' = Unshare.unshare term in
466        (i,canonical_context',term')
467     in
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
472     (unsh_sequent,
473      (("i0",metano,acontext,agoal), 
474       ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_hypotheses))
475 ;;
476
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
488   let 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
498      Unshare.unshare t in
499    let aobj =
500     match obj with
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
506         C.AConstant
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
511         C.AConstant
512          ("mettereaposto",None,id,None,aty,params,attrs)
513     | C.Variable (id,bo,ty,params,attrs) ->
514        let ty' = eta_fix [] [] ty in
515        let abo =
516         match bo with
517            None -> None
518          | Some bo ->
519             let bo' = eta_fix [] [] bo in
520              Some (acic_term_of_cic_term' ~computeinnertypes:true bo' (Some ty'))
521        in
522        let aty = acic_term_of_cic_term' ~computeinnertypes:false ty' None in
523         C.AVariable
524          ("mettereaposto",id,abo,aty,params,attrs)
525     | C.CurrentProof (id,conjectures,bo,ty,params,attrs) ->
526        let conjectures' =
527         List.map
528          (function (i,canonical_context,term) ->
529            let canonical_context' =
530             List.fold_right
531              (fun d canonical_context' ->
532                let d =
533                 match d with
534                    None -> None
535                  | Some (n, C.Decl t)->
536                     Some (n, C.Decl (eta_fix conjectures canonical_context' t))
537                  | Some (n, C.Def (t,None)) ->
538                     Some (n,
539                      C.Def ((eta_fix conjectures canonical_context' t),None))
540                  | Some (_,C.Def (_,Some _)) -> assert false
541                in
542                 d::canonical_context'
543              ) canonical_context []
544            in
545            let term' = eta_fix conjectures canonical_context' term in
546             (i,canonical_context',term')
547          ) conjectures
548        in
549        let aconjectures = 
550         List.map
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))
558           conjectures' in 
559 (*        let time1 = Sys.time () in *)
560        let bo' = (*eta_fix conjectures' []*) bo in
561        let ty' = eta_fix conjectures' [] ty in
562 (*
563        let time2 = Sys.time () in
564        prerr_endline
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 ;
569 *)
570        let abo =
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
573 (*
574        let time3 = Sys.time () in
575        prerr_endline
576         ("++++++++++++ Tempi della hashtbl_add_time: " ^ string_of_float !hashtbl_add_time) ;
577        prerr_endline
578         ("++++++++++++ Tempi della type_of_aux'_add_time(" ^ string_of_int !number_new_type_of_aux' ^ "): " ^ string_of_float !type_of_aux'_add_time) ;
579        prerr_endline
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) ;
581        prerr_endline
582         ("++++++++++++ Tempi della syntactic_equality_add_time: " ^ string_of_float !DoubleTypeInference.syntactic_equality_add_time) ;
583        prerr_endline
584         ("++++++++++ Tempi della acic_of_cic: " ^ string_of_float (time3 -. time2)) ;
585        prerr_endline
586         ("++++++++++ Numero di iterazioni della acic_of_cic: " ^ string_of_int !seed) ;
587 *)
588         C.ACurrentProof
589          ("mettereaposto","mettereaposto2",id,aconjectures,abo,aty,params,attrs)
590     | C.InductiveDefinition (tys,params,paramsno,attrs) ->
591        let tys =
592         List.map
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
596        let context =
597         List.map
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
601        let atys =
602         List.map2
603          (fun id (name,inductive,ty,cons) ->
604            let acons =
605             List.map
606              (function (name,ty) ->
607                (name,
608                  acic_term_of_cic_term_context' ~computeinnertypes:false [] context idrefs ty None)
609              ) cons
610            in
611             (id,name,inductive,
612              acic_term_of_cic_term' ~computeinnertypes:false ty None,acons)
613          ) (List.rev idrefs) tys
614        in
615         C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
616    in
617     aobj,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,ids_to_inner_types,
618      ids_to_conjectures,ids_to_hypotheses
619 ;;
620
621 let plain_acic_term_of_cic_term =
622  let module C = Cic in
623  let mk_fresh_id =
624   let id = ref 0 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
628   match t with
629      C.Rel n ->
630       let idref,id =
631        match get_nth context n with
632           idref,(Some (C.Name s,_)) -> idref,s
633         | idref,_ -> idref,"__" ^ string_of_int n
634       in
635        C.ARel (fresh_id, idref, n, id)
636    | C.Var (uri,exp_named_subst) ->
637       let exp_named_subst' =
638        List.map
639         (function i,t -> i, (aux context t)) exp_named_subst
640       in
641        C.AVar (fresh_id,uri,exp_named_subst')
642    | C.Implicit _
643    | C.Meta _ -> assert false
644    | C.Sort s -> C.ASort (fresh_id, s)
645    | C.Cast (v,t) ->
646       C.ACast (fresh_id, aux context v, aux context t)
647    | C.Prod (n,s,t) ->
648         C.AProd
649          (fresh_id, n, aux context s,
650           aux ((fresh_id, Some (n, C.Decl s))::context) t)
651    | C.Lambda (n,s,t) ->
652        C.ALambda
653         (fresh_id,n, aux context s,
654          aux ((fresh_id, Some (n, C.Decl s))::context) t)
655    | C.LetIn (n,s,t) ->
656       C.ALetIn
657        (fresh_id, n, aux context s,
658         aux ((fresh_id, Some (n, C.Def(s,None)))::context) t)
659    | C.Appl l ->
660       C.AAppl (fresh_id, List.map (aux context) l)
661    | C.Const (uri,exp_named_subst) ->
662       let exp_named_subst' =
663        List.map
664         (function i,t -> i, (aux context t)) exp_named_subst
665       in
666        C.AConst (fresh_id, uri, exp_named_subst')
667    | C.MutInd (uri,tyno,exp_named_subst) ->
668       let exp_named_subst' =
669        List.map
670         (function i,t -> i, (aux context t)) exp_named_subst
671       in
672        C.AMutInd (fresh_id, uri, tyno, exp_named_subst')
673    | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
674       let exp_named_subst' =
675        List.map
676         (function i,t -> i, (aux context t)) exp_named_subst
677       in
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) ->
683       let tys =
684        List.map
685         (fun (name,_,ty,_) -> mk_fresh_id (), Some (C.Name name, C.Decl ty)) funs
686       in
687        C.AFix (fresh_id, funno,
688         List.map2
689          (fun (id,_) (name, indidx, ty, bo) ->
690            (id, name, indidx, aux context ty, aux (tys@context) bo)
691          ) tys funs
692       )
693    | C.CoFix (funno, funs) ->
694       let tys =
695        List.map (fun (name,ty,_) ->
696         mk_fresh_id (),Some (C.Name name, C.Decl ty)) funs
697       in
698        C.ACoFix (fresh_id, funno,
699         List.map2
700          (fun (id,_) (name, ty, bo) ->
701            (id, name, aux context ty, aux (tys@context) bo)
702          ) tys funs
703        )
704  in
705   aux
706 ;;
707
708 let plain_acic_object_of_cic_object obj =
709  let module C = Cic in
710  let mk_fresh_id =
711   let id = ref 0 in
712    function () -> incr id; "it" ^ string_of_int !id
713  in
714   match obj with
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
718       C.AConstant
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
722       C.AConstant
723        ("mettereaposto",None,id,None,aty,params,attrs)
724   | C.Variable (id,bo,ty,params,attrs) ->
725      let abo =
726       match bo with
727          None -> None
728        | Some bo -> Some (plain_acic_term_of_cic_term [] bo)
729      in
730      let aty = plain_acic_term_of_cic_term [] ty in
731       C.AVariable
732        ("mettereaposto",id,abo,aty,params,attrs)
733   | C.CurrentProof _ -> assert false
734   | C.InductiveDefinition (tys,params,paramsno,attrs) ->
735      let context =
736       List.map
737        (fun (name,_,arity,_) ->
738          mk_fresh_id (), Some (C.Name name, C.Decl arity)) tys in
739      let atys =
740       List.map2
741        (fun (id,_) (name,inductive,ty,cons) ->
742          let acons =
743           List.map
744            (function (name,ty) ->
745              (name,
746                plain_acic_term_of_cic_term context ty)
747            ) cons
748          in
749           (id,name,inductive,plain_acic_term_of_cic_term [] ty,acons)
750        ) context tys
751      in
752       C.AInductiveDefinition ("mettereaposto",atys,params,paramsno,attrs)
753 ;;