1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (**************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (**************************************************************************)
37 let object_prefix = "obj:";;
38 let declaration_prefix = "decl:";;
39 let definition_prefix = "def:";;
40 let inductive_prefix = "ind:";;
41 let joint_prefix = "joint:";;
42 let proof_prefix = "proof:";;
43 let conclude_prefix = "concl:";;
44 let premise_prefix = "prem:";;
45 let lemma_prefix = "lemma:";;
47 (* e se mettessi la conversione di BY nell'apply_context ? *)
48 (* sarebbe carino avere l'invariante che la proof2pres
49 generasse sempre prove con contesto vuoto *)
51 let gen_id prefix seed =
52 let res = prefix ^ string_of_int !seed in
57 let name_of = function
59 | Cic.Name b -> Some b;;
61 exception Not_a_proof;;
62 exception NotImplemented;;
63 exception NotApplicable;;
65 (* we do not care for positivity, here, that in any case is enforced by
66 well typing. Just a brutal search *)
75 | C.Implicit _ -> assert false
76 | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
77 | C.Cast (te,ty) -> (occur uri te)
78 | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
79 | C.LetIn (_,s,t) -> (occur uri s) or (occur uri t)
84 else (occur uri a)) false l
85 | C.Const (_,_) -> false
86 | C.MutInd (uri1,_,_) -> if uri = uri1 then true else false
87 | C.MutConstruct (_,_,_,_) -> false
88 | C.MutCase _ -> false (* presuming too much?? *)
89 | C.Fix _ -> false (* presuming too much?? *)
90 | C.CoFix (_,_) -> false (* presuming too much?? *)
96 C.ARel (id,_,_,_) -> id
97 | C.AVar (id,_,_) -> id
98 | C.AMeta (id,_,_) -> id
99 | C.ASort (id,_) -> id
100 | C.AImplicit _ -> raise NotImplemented
101 | C.AProd (id,_,_,_) -> id
102 | C.ACast (id,_,_) -> id
103 | C.ALambda (id,_,_,_) -> id
104 | C.ALetIn (id,_,_,_) -> id
105 | C.AAppl (id,_) -> id
106 | C.AConst (id,_,_) -> id
107 | C.AMutInd (id,_,_,_) -> id
108 | C.AMutConstruct (id,_,_,_,_) -> id
109 | C.AMutCase (id,_,_,_,_,_) -> id
110 | C.AFix (id,_,_) -> id
111 | C.ACoFix (id,_,_) -> id
114 let test_for_lifting ~ids_to_inner_types ~ids_to_inner_sorts=
115 let module C = Cic in
116 let module C2A = Cic2acic in
117 (* atomic terms are never lifted, according to my policy *)
119 C.ARel (id,_,_,_) -> false
122 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
124 with Not_found -> false)
125 | C.AMeta (id,_,_) ->
127 Hashtbl.find ids_to_inner_sorts id = `Prop
128 with Not_found -> assert false)
129 | C.ASort (id,_) -> false
130 | C.AImplicit _ -> raise NotImplemented
131 | C.AProd (id,_,_,_) -> false
132 | C.ACast (id,_,_) ->
134 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
136 with Not_found -> false)
137 | C.ALambda (id,_,_,_) ->
139 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
141 with Not_found -> false)
142 | C.ALetIn (id,_,_,_) ->
144 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
146 with Not_found -> false)
149 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
151 with Not_found -> false)
152 | C.AConst (id,_,_) ->
154 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
156 with Not_found -> false)
157 | C.AMutInd (id,_,_,_) -> false
158 | C.AMutConstruct (id,_,_,_,_) ->
160 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
162 with Not_found -> false)
164 | C.AMutCase (id,_,_,_,_,_) ->
166 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
168 with Not_found -> false)
171 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
173 with Not_found -> false)
174 | C.ACoFix (id,_,_) ->
176 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
178 with Not_found -> false)
181 (* transform a proof p into a proof list, concatenating the last
182 conclude element to the apply_context list, in case context is
183 empty. Otherwise, it just returns [p] *)
186 let module K = Content in
187 if (p.K.proof_context = []) then
188 if p.K.proof_apply_context = [] then [p]
192 K.proof_context = [];
193 K.proof_apply_context = []
195 p.K.proof_apply_context@[p1]
200 let rec serialize seed =
203 | a::l -> (flat seed a)@(serialize seed l)
206 (* top_down = true if the term is a LAMBDA or a decl *)
207 let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
208 let module C2A = Cic2acic in
209 let module K = Content in
210 let exp = (try ((Hashtbl.find ids_to_inner_types id).C2A.annexpected)
211 with Not_found -> None)
216 if inner_proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
217 { K.proof_name = inner_proof.K.proof_name;
218 K.proof_id = gen_id proof_prefix seed;
219 K.proof_context = [] ;
220 K.proof_apply_context = [];
222 { K.conclude_id = gen_id conclude_prefix seed;
223 K.conclude_aref = id;
224 K.conclude_method = "TD_Conversion";
226 [K.ArgProof {inner_proof with K.proof_name = None}];
227 K.conclude_conclusion = Some expty
231 { K.proof_name = inner_proof.K.proof_name;
232 K.proof_id = gen_id proof_prefix seed;
233 K.proof_context = [] ;
234 K.proof_apply_context = [{inner_proof with K.proof_name = None}];
236 { K.conclude_id = gen_id conclude_prefix seed;
237 K.conclude_aref = id;
238 K.conclude_method = "BU_Conversion";
241 { K.premise_id = gen_id premise_prefix seed;
242 K.premise_xref = inner_proof.K.proof_id;
243 K.premise_binder = None;
247 K.conclude_conclusion = Some expty
252 let generate_exact seed t id name ~ids_to_inner_types =
253 let module C2A = Cic2acic in
254 let module K = Content in
255 { K.proof_name = name;
256 K.proof_id = gen_id proof_prefix seed ;
257 K.proof_context = [] ;
258 K.proof_apply_context = [];
260 { K.conclude_id = gen_id conclude_prefix seed;
261 K.conclude_aref = id;
262 K.conclude_method = "Exact";
263 K.conclude_args = [K.Term t];
264 K.conclude_conclusion =
265 try Some (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
266 with Not_found -> None
271 let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_types =
272 let module C2A = Cic2acic in
273 let module C = Cic in
274 let module K = Content in
275 { K.proof_name = name;
276 K.proof_id = gen_id proof_prefix seed ;
277 K.proof_context = [] ;
278 K.proof_apply_context = [];
280 { K.conclude_id = gen_id conclude_prefix seed;
281 K.conclude_aref = id;
282 K.conclude_method = "Intros+LetTac";
283 K.conclude_args = [K.ArgProof inner_proof];
284 K.conclude_conclusion =
286 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
288 (match inner_proof.K.proof_conclude.K.conclude_conclusion with
291 if is_intro then Some (C.AProd ("gen"^id,n,s,t))
292 else Some (C.ALetIn ("gen"^id,n,s,t)))
297 let build_decl_item seed id n s ~ids_to_inner_sorts =
298 let module K = Content in
301 Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
302 with Not_found -> None
307 { K.dec_name = name_of n;
308 K.dec_id = gen_id declaration_prefix seed;
309 K.dec_inductive = false;
315 { K.dec_name = name_of n;
316 K.dec_id = gen_id declaration_prefix seed;
317 K.dec_inductive = false;
323 let rec build_subproofs_and_args seed l ~ids_to_inner_types ~ids_to_inner_sorts =
324 let module C = Cic in
325 let module K = Content in
330 let subproofs,args = aux l1 in
331 if (test_for_lifting t ~ids_to_inner_types ~ids_to_inner_sorts) then
334 seed ~name:"H" ~ids_to_inner_types ~ids_to_inner_sorts t in
337 { K.premise_id = gen_id premise_prefix seed;
338 K.premise_xref = new_subproof.K.proof_id;
339 K.premise_binder = new_subproof.K.proof_name;
342 new_subproof::subproofs,new_arg::args
346 C.ARel (idr,idref,n,b) ->
349 Hashtbl.find ids_to_inner_sorts idr
350 with Not_found -> `Type (CicUniv.fresh())) in
353 { K.premise_id = gen_id premise_prefix seed;
354 K.premise_xref = idr;
355 K.premise_binder = Some b;
359 | C.AConst(id,uri,[]) ->
362 Hashtbl.find ids_to_inner_sorts id
363 with Not_found -> `Type (CicUniv.fresh())) in
366 { K.lemma_id = gen_id lemma_prefix seed;
367 K.lemma_name = UriManager.name_of_uri uri;
368 K.lemma_uri = UriManager.string_of_uri uri
371 | C.AMutConstruct(id,uri,tyno,consno,[]) ->
374 Hashtbl.find ids_to_inner_sorts id
375 with Not_found -> `Type (CicUniv.fresh())) in
377 let inductive_types =
379 CicEnvironment.get_obj CicUniv.empty_ugraph uri
382 | Cic.InductiveDefinition (l,_,_,_) -> l
385 let (_,_,_,constructors) =
386 List.nth inductive_types tyno in
387 let name,_ = List.nth constructors (consno - 1) in
389 { K.lemma_id = gen_id lemma_prefix seed;
392 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
393 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^
397 | _ -> (K.Term t)) in
402 [{p with K.proof_name = None}],
405 K.Premise prem when prem.K.premise_xref = p.K.proof_id ->
406 K.Premise {prem with K.premise_binder = None}
412 build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
413 let module K = Content in
415 let sort = Hashtbl.find ids_to_inner_sorts id in
418 (acic2content seed ?name:(name_of n) ~ids_to_inner_sorts ~ids_to_inner_types t)
423 { K.def_name = name_of n;
424 K.def_id = gen_id definition_prefix seed;
429 Not_found -> assert false
431 (* the following function must be called with an object of sort
432 Prop. For debugging purposes this is tested again, possibly raising an
433 Not_a_proof exception *)
435 and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
436 let rec aux ?name t =
437 let module C = Cic in
438 let module K = Content in
439 let module C2A = Cic2acic in
442 C.ARel (id,idref,n,b) as t ->
443 let sort = Hashtbl.find ids_to_inner_sorts id in
445 generate_exact seed t id name ~ids_to_inner_types
446 else raise Not_a_proof
447 | C.AVar (id,uri,exp_named_subst) as t ->
448 let sort = Hashtbl.find ids_to_inner_sorts id in
450 generate_exact seed t id name ~ids_to_inner_types
451 else raise Not_a_proof
452 | C.AMeta (id,n,l) as t ->
453 let sort = Hashtbl.find ids_to_inner_sorts id in
455 generate_exact seed t id name ~ids_to_inner_types
456 else raise Not_a_proof
457 | C.ASort (id,s) -> raise Not_a_proof
458 | C.AImplicit _ -> raise NotImplemented
459 | C.AProd (_,_,_,_) -> raise Not_a_proof
460 | C.ACast (id,v,t) -> aux v
461 | C.ALambda (id,n,s,t) ->
462 let sort = Hashtbl.find ids_to_inner_sorts id in
466 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
467 match proof.K.proof_conclude.K.conclude_args with
475 (build_decl_item seed id n s ids_to_inner_sorts)::
476 proof'.K.proof_context
479 generate_intros_let_tac seed id n s true proof'' name ~ids_to_inner_types
480 else raise Not_a_proof
481 | C.ALetIn (id,n,s,t) ->
482 let sort = Hashtbl.find ids_to_inner_sorts id in
486 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
487 match proof.K.proof_conclude.K.conclude_args with
495 ((build_def_item seed id n s ids_to_inner_sorts
496 ids_to_inner_types):> Cic.annterm K.in_proof_context_element)
497 ::proof'.K.proof_context;
500 generate_intros_let_tac seed id n s false proof'' name ~ids_to_inner_types
501 else raise Not_a_proof
504 seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
505 with NotApplicable ->
507 seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
508 with NotApplicable ->
509 let subproofs, args =
510 build_subproofs_and_args
511 seed li ~ids_to_inner_types ~ids_to_inner_sorts in
514 List.filter (test_for_lifting ~ids_to_inner_types) li in
516 match args_to_lift with
517 [_] -> List.map aux args_to_lift
518 | _ -> List.map (aux ~name:"H") args_to_lift in
519 let args = build_args seed li subproofs
520 ~ids_to_inner_types ~ids_to_inner_sorts in *)
521 { K.proof_name = name;
522 K.proof_id = gen_id proof_prefix seed;
523 K.proof_context = [];
524 K.proof_apply_context = serialize seed subproofs;
526 { K.conclude_id = gen_id conclude_prefix seed;
527 K.conclude_aref = id;
528 K.conclude_method = "Apply";
529 K.conclude_args = args;
530 K.conclude_conclusion =
532 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
533 with Not_found -> None
536 | C.AConst (id,uri,exp_named_subst) as t ->
537 let sort = Hashtbl.find ids_to_inner_sorts id in
539 generate_exact seed t id name ~ids_to_inner_types
540 else raise Not_a_proof
541 | C.AMutInd (id,uri,i,exp_named_subst) -> raise Not_a_proof
542 | C.AMutConstruct (id,uri,i,j,exp_named_subst) as t ->
543 let sort = Hashtbl.find ids_to_inner_sorts id in
545 generate_exact seed t id name ~ids_to_inner_types
546 else raise Not_a_proof
547 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
548 let inductive_types,noparams =
549 (let o, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
551 Cic.Constant _ -> assert false
552 | Cic.Variable _ -> assert false
553 | Cic.CurrentProof _ -> assert false
554 | Cic.InductiveDefinition (l,_,n,_) -> l,n
556 let (_,_,_,constructors) = List.nth inductive_types typeno in
557 let name_and_arities =
558 let rec count_prods =
560 C.Prod (_,_,t) -> 1 + count_prods t
563 (function (n,t) -> Some n,((count_prods t) - noparams)) constructors in
565 let build_proof p (name,arity) =
566 let rec make_context_and_body c p n =
567 if n = 0 then c,(aux p)
570 Cic.ALambda(idl,vname,s1,t1) ->
572 build_decl_item seed idl vname s1 ~ids_to_inner_sorts in
573 make_context_and_body (ce::c) t1 (n-1)
574 | _ -> assert false) in
575 let context,body = make_context_and_body [] p arity in
577 {body with K.proof_name = name; K.proof_context=context} in
578 List.map2 build_proof patterns name_and_arities in
579 let teid = get_id te in
582 build_subproofs_and_args
583 seed ~ids_to_inner_types ~ids_to_inner_sorts [te]
586 | _ -> assert false) in
587 { K.proof_name = name;
588 K.proof_id = gen_id proof_prefix seed;
589 K.proof_context = [];
590 K.proof_apply_context = serialize seed context;
592 { K.conclude_id = gen_id conclude_prefix seed;
593 K.conclude_aref = id;
594 K.conclude_method = "Case";
596 (K.Aux (UriManager.string_of_uri uri))::
597 (K.Aux (string_of_int typeno))::(K.Term ty)::term::pp;
598 K.conclude_conclusion =
600 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
601 with Not_found -> None
604 | C.AFix (id, no, funs) ->
607 (function (_,name,_,_,bo) -> `Proof (aux ~name bo)) funs in
609 List.nth (List.map (fun (_,name,_,_,_) -> name) funs) no
611 let decreasing_args =
612 List.map (function (_,_,n,_,_) -> n) funs in
614 { K.joint_id = gen_id joint_prefix seed;
615 K.joint_kind = `Recursive decreasing_args;
616 K.joint_defs = proofs
619 { K.proof_name = name;
620 K.proof_id = gen_id proof_prefix seed;
621 K.proof_context = [`Joint jo];
622 K.proof_apply_context = [];
624 { K.conclude_id = gen_id conclude_prefix seed;
625 K.conclude_aref = id;
626 K.conclude_method = "Exact";
629 { K.premise_id = gen_id premise_prefix seed;
630 K.premise_xref = jo.K.joint_id;
631 K.premise_binder = Some fun_name;
632 K.premise_n = Some no;
635 K.conclude_conclusion =
637 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
638 with Not_found -> None
641 | C.ACoFix (id,no,funs) ->
644 (function (_,name,_,bo) -> `Proof (aux ~name bo)) funs in
646 { K.joint_id = gen_id joint_prefix seed;
647 K.joint_kind = `CoRecursive;
648 K.joint_defs = proofs
651 { K.proof_name = name;
652 K.proof_id = gen_id proof_prefix seed;
653 K.proof_context = [`Joint jo];
654 K.proof_apply_context = [];
656 { K.conclude_id = gen_id conclude_prefix seed;
657 K.conclude_aref = id;
658 K.conclude_method = "Exact";
661 { K.premise_id = gen_id premise_prefix seed;
662 K.premise_xref = jo.K.joint_id;
663 K.premise_binder = Some "tiralo fuori";
664 K.premise_n = Some no;
667 K.conclude_conclusion =
669 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
670 with Not_found -> None
675 generate_conversion seed false id t1 ~ids_to_inner_types
678 and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
679 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
680 let module C2A = Cic2acic in
681 let module K = Content in
682 let module C = Cic in
684 C.AConst (idc,uri,exp_named_subst)::args ->
685 let uri_str = UriManager.string_of_uri uri in
686 let suffix = Str.regexp_string "_ind.con" in
687 let len = String.length uri_str in
688 let n = (try (Str.search_backward suffix uri_str len)
689 with Not_found -> -1) in
690 if n<0 then raise NotApplicable
693 if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
694 else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
695 else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
696 else "ByInduction" in
697 let prefix = String.sub uri_str 0 n in
698 let ind_str = (prefix ^ ".ind") in
699 let ind_uri = UriManager.uri_of_string ind_str in
700 let inductive_types,noparams =
701 (let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph ind_uri in
703 | Cic.InductiveDefinition (l,_,n,_) -> (l,n)
707 if n = 0 then ([],l) else
708 let p,a = split (n-1) (List.tl l) in
709 ((List.hd l::p),a) in
710 let params_and_IP,tail_args = split (noparams+1) args in
712 (match inductive_types with
714 | _ -> raise NotApplicable) (* don't care for mutual ind *) in
716 let rec clean_up n t =
719 (label,Cic.Prod (_,_,t)) -> clean_up (n-1) (label,t)
720 | _ -> assert false) in
721 List.map (clean_up noparams) constructors in
722 let no_constructors= List.length constructors in
723 let args_for_cases, other_args =
724 split no_constructors tail_args in
725 let subproofs,other_method_args =
726 build_subproofs_and_args seed other_args
727 ~ids_to_inner_types ~ids_to_inner_sorts in
729 let rec build_method_args =
731 [],_-> [] (* extra args are ignored ???? *)
732 | (name,ty)::tlc,arg::tla ->
733 let idarg = get_id arg in
735 (try (Hashtbl.find ids_to_inner_sorts idarg)
736 with Not_found -> `Type (CicUniv.fresh())) in
738 if sortarg = `Prop then
742 Cic.Prod (_,s,t),Cic.ALambda(idl,n,s1,t1) ->
745 seed idl n s1 ~ids_to_inner_sorts in
746 if (occur ind_uri s) then
748 Cic.ALambda(id2,n2,s2,t2) ->
751 { K.dec_name = name_of n2;
753 gen_id declaration_prefix seed;
754 K.dec_inductive = true;
758 let (context,body) = bc (t,t2) in
759 (ce::inductive_hyp::context,body)
763 let (context,body) = bc (t,t1) in
765 | _ , t -> ([],aux t) in
769 K.proof_name = Some name;
770 K.proof_context = co;
773 hdarg::(build_method_args (tlc,tla))
774 | _ -> assert false in
775 build_method_args (constructors1,args_for_cases) in
776 { K.proof_name = name;
777 K.proof_id = gen_id proof_prefix seed;
778 K.proof_context = [];
779 K.proof_apply_context = serialize seed subproofs;
781 { K.conclude_id = gen_id conclude_prefix seed;
782 K.conclude_aref = id;
783 K.conclude_method = method_name;
785 K.Aux (string_of_int no_constructors)
786 ::K.Term (C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))
787 ::method_args@other_method_args;
788 K.conclude_conclusion =
790 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
791 with Not_found -> None
794 | _ -> raise NotApplicable
796 and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
797 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
798 let module C2A = Cic2acic in
799 let module K = Content in
800 let module C = Cic in
802 C.AConst (sid,uri,exp_named_subst)::args ->
803 if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
804 UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI then
807 build_subproofs_and_args
808 seed ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3]
811 | _,_ -> assert false) in
813 let rec ma_aux n = function
819 let aid = get_id a in
820 let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
821 with Not_found -> `Type (CicUniv.fresh())) in
822 if asort = `Prop then
825 hd::(ma_aux (n-1) tl) in
827 { K.proof_name = name;
828 K.proof_id = gen_id proof_prefix seed;
829 K.proof_context = [];
830 K.proof_apply_context = serialize seed subproofs;
832 { K.conclude_id = gen_id conclude_prefix seed;
833 K.conclude_aref = id;
834 K.conclude_method = "Rewrite";
836 K.Term (C.AConst (sid,uri,exp_named_subst))::method_args;
837 K.conclude_conclusion =
839 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
840 with Not_found -> None
843 else raise NotApplicable
844 | _ -> raise NotApplicable
848 seed ~ids_to_inner_sorts ~ids_to_inner_types (id,n,context,ty)
850 let module K = Content in
855 | (id,Some (name,Cic.ADecl t)) ->
857 (* We should call build_decl_item, but we have not computed *)
858 (* the inner-types ==> we always produce a declaration *)
860 { K.dec_name = name_of name;
861 K.dec_id = gen_id declaration_prefix seed;
862 K.dec_inductive = false;
863 K.dec_aref = get_id t;
866 | (id,Some (name,Cic.ADef t)) ->
868 (* We should call build_def_item, but we have not computed *)
869 (* the inner-types ==> we always produce a declaration *)
871 { K.def_name = name_of name;
872 K.def_id = gen_id definition_prefix seed;
873 K.def_aref = get_id t;
881 (* map_sequent is similar to map_conjectures, but the for the hid
882 of the hypothesis, which are preserved instead of generating
883 fresh ones. We shall have to adopt a uniform policy, soon or later *)
885 let map_sequent ((id,n,context,ty):Cic.annconjecture) =
886 let module K = Content in
891 | (id,Some (name,Cic.ADecl t)) ->
893 (* We should call build_decl_item, but we have not computed *)
894 (* the inner-types ==> we always produce a declaration *)
896 { K.dec_name = name_of name;
898 K.dec_inductive = false;
899 K.dec_aref = get_id t;
902 | (id,Some (name,Cic.ADef t)) ->
904 (* We should call build_def_item, but we have not computed *)
905 (* the inner-types ==> we always produce a declaration *)
907 { K.def_name = name_of name;
909 K.def_aref = get_id t;
917 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
918 let module C = Cic in
919 let module K = Content in
920 let module C2A = Cic2acic in
923 C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
924 (gen_id object_prefix seed, params,
927 (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
930 build_def_item seed (get_id bo) (C.Name n) bo
931 ~ids_to_inner_sorts ~ids_to_inner_types))
932 | C.AConstant (_,_,n,Some bo,ty,params,_) ->
933 (gen_id object_prefix seed, params, None,
935 build_def_item seed (get_id bo) (C.Name n) bo
936 ~ids_to_inner_sorts ~ids_to_inner_types))
937 | C.AConstant (id,_,n,None,ty,params,_) ->
938 (gen_id object_prefix seed, params, None,
940 build_decl_item seed id (C.Name n) ty
941 ~ids_to_inner_sorts))
942 | C.AVariable (_,n,Some bo,ty,params,_) ->
943 (gen_id object_prefix seed, params, None,
945 build_def_item seed (get_id bo) (C.Name n) bo
946 ~ids_to_inner_sorts ~ids_to_inner_types))
947 | C.AVariable (id,n,None,ty,params,_) ->
948 (gen_id object_prefix seed, params, None,
950 build_decl_item seed id (C.Name n) ty
951 ~ids_to_inner_sorts))
952 | C.AInductiveDefinition (id,l,params,nparams,_) ->
953 (gen_id object_prefix seed, params, None,
955 { K.joint_id = gen_id joint_prefix seed;
956 K.joint_kind = `Inductive nparams;
957 K.joint_defs = List.map (build_inductive seed) l
961 build_inductive seed =
962 let module K = Content in
965 { K.inductive_id = gen_id inductive_prefix seed;
966 K.inductive_name = n;
967 K.inductive_kind = b;
968 K.inductive_type = ty;
969 K.inductive_constructors = build_constructors seed l
973 build_constructors seed l =
974 let module K = Content in
977 { K.dec_name = Some n;
978 K.dec_id = gen_id declaration_prefix seed;
979 K.dec_inductive = false;
986 and 'term cinductiveType =
987 id * string * bool * 'term * (* typename, inductive, arity *)
988 'term cconstructor list (* constructors *)
990 and 'term cconstructor =