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 (**************************************************************************)
35 let object_prefix = "obj:";;
36 let declaration_prefix = "decl:";;
37 let definition_prefix = "def:";;
38 let inductive_prefix = "ind:";;
39 let joint_prefix = "joint:";;
40 let proof_prefix = "proof:";;
41 let conclude_prefix = "concl:";;
42 let premise_prefix = "prem:";;
43 let lemma_prefix = "lemma:";;
45 (* e se mettessi la conversione di BY nell'apply_context ? *)
46 (* sarebbe carino avere l'invariante che la proof2pres
47 generasse sempre prove con contesto vuoto *)
49 let gen_id prefix seed =
50 let res = prefix ^ string_of_int !seed in
55 let name_of = function
57 | Cic.Name b -> Some b;;
59 exception Not_a_proof;;
60 exception NotImplemented;;
61 exception NotApplicable;;
63 (* we do not care for positivity, here, that in any case is enforced by
64 well typing. Just a brutal search *)
73 | C.Implicit _ -> assert false
74 | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
75 | C.Cast (te,ty) -> (occur uri te)
76 | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
77 | C.LetIn (_,s,t) -> (occur uri s) or (occur uri t)
82 else (occur uri a)) false l
83 | C.Const (_,_) -> false
84 | C.MutInd (uri1,_,_) -> if uri = uri1 then true else false
85 | C.MutConstruct (_,_,_,_) -> false
86 | C.MutCase _ -> false (* presuming too much?? *)
87 | C.Fix _ -> false (* presuming too much?? *)
88 | C.CoFix (_,_) -> false (* presuming too much?? *)
94 C.ARel (id,_,_,_) -> id
95 | C.AVar (id,_,_) -> id
96 | C.AMeta (id,_,_) -> id
97 | C.ASort (id,_) -> id
98 | C.AImplicit _ -> raise NotImplemented
99 | C.AProd (id,_,_,_) -> id
100 | C.ACast (id,_,_) -> id
101 | C.ALambda (id,_,_,_) -> id
102 | C.ALetIn (id,_,_,_) -> id
103 | C.AAppl (id,_) -> id
104 | C.AConst (id,_,_) -> id
105 | C.AMutInd (id,_,_,_) -> id
106 | C.AMutConstruct (id,_,_,_,_) -> id
107 | C.AMutCase (id,_,_,_,_,_) -> id
108 | C.AFix (id,_,_) -> id
109 | C.ACoFix (id,_,_) -> id
112 let test_for_lifting ~ids_to_inner_types ~ids_to_inner_sorts=
113 let module C = Cic in
114 let module C2A = Cic2acic in
115 (* atomic terms are never lifted, according to my policy *)
117 C.ARel (id,_,_,_) -> false
120 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
122 with Not_found -> false)
123 | C.AMeta (id,_,_) ->
125 Hashtbl.find ids_to_inner_sorts id = `Prop
126 with Not_found -> assert false)
127 | C.ASort (id,_) -> false
128 | C.AImplicit _ -> raise NotImplemented
129 | C.AProd (id,_,_,_) -> false
130 | C.ACast (id,_,_) ->
132 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
134 with Not_found -> false)
135 | C.ALambda (id,_,_,_) ->
137 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
139 with Not_found -> false)
140 | C.ALetIn (id,_,_,_) ->
142 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
144 with Not_found -> false)
147 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
149 with Not_found -> false)
150 | C.AConst (id,_,_) ->
152 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
154 with Not_found -> false)
155 | C.AMutInd (id,_,_,_) -> false
156 | C.AMutConstruct (id,_,_,_,_) ->
158 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
160 with Not_found -> false)
162 | C.AMutCase (id,_,_,_,_,_) ->
164 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
166 with Not_found -> false)
169 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
171 with Not_found -> false)
172 | C.ACoFix (id,_,_) ->
174 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
176 with Not_found -> false)
179 (* transform a proof p into a proof list, concatenating the last
180 conclude element to the apply_context list, in case context is
181 empty. Otherwise, it just returns [p] *)
184 let module K = Content in
185 if (p.K.proof_context = []) then
186 if p.K.proof_apply_context = [] then [p]
190 K.proof_context = [];
191 K.proof_apply_context = []
193 p.K.proof_apply_context@[p1]
198 let rec serialize seed =
201 | a::l -> (flat seed a)@(serialize seed l)
204 (* top_down = true if the term is a LAMBDA or a decl *)
205 let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
206 let module C2A = Cic2acic in
207 let module K = Content in
208 let exp = (try ((Hashtbl.find ids_to_inner_types id).C2A.annexpected)
209 with Not_found -> None)
214 if inner_proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
215 { K.proof_name = inner_proof.K.proof_name;
216 K.proof_id = gen_id proof_prefix seed;
217 K.proof_context = [] ;
218 K.proof_apply_context = [];
220 { K.conclude_id = gen_id conclude_prefix seed;
221 K.conclude_aref = id;
222 K.conclude_method = "TD_Conversion";
224 [K.ArgProof {inner_proof with K.proof_name = None}];
225 K.conclude_conclusion = Some expty
229 { K.proof_name = inner_proof.K.proof_name;
230 K.proof_id = gen_id proof_prefix seed;
231 K.proof_context = [] ;
232 K.proof_apply_context = [{inner_proof with K.proof_name = None}];
234 { K.conclude_id = gen_id conclude_prefix seed;
235 K.conclude_aref = id;
236 K.conclude_method = "BU_Conversion";
239 { K.premise_id = gen_id premise_prefix seed;
240 K.premise_xref = inner_proof.K.proof_id;
241 K.premise_binder = None;
245 K.conclude_conclusion = Some expty
250 let generate_exact seed t id name ~ids_to_inner_types =
251 let module C2A = Cic2acic in
252 let module K = Content in
253 { K.proof_name = name;
254 K.proof_id = gen_id proof_prefix seed ;
255 K.proof_context = [] ;
256 K.proof_apply_context = [];
258 { K.conclude_id = gen_id conclude_prefix seed;
259 K.conclude_aref = id;
260 K.conclude_method = "Exact";
261 K.conclude_args = [K.Term t];
262 K.conclude_conclusion =
263 try Some (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
264 with Not_found -> None
269 let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_types =
270 let module C2A = Cic2acic in
271 let module C = Cic in
272 let module K = Content in
273 { K.proof_name = name;
274 K.proof_id = gen_id proof_prefix seed ;
275 K.proof_context = [] ;
276 K.proof_apply_context = [];
278 { K.conclude_id = gen_id conclude_prefix seed;
279 K.conclude_aref = id;
280 K.conclude_method = "Intros+LetTac";
281 K.conclude_args = [K.ArgProof inner_proof];
282 K.conclude_conclusion =
284 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
286 (match inner_proof.K.proof_conclude.K.conclude_conclusion with
289 if is_intro then Some (C.AProd ("gen"^id,n,s,t))
290 else Some (C.ALetIn ("gen"^id,n,s,t)))
295 let build_decl_item seed id n s ~ids_to_inner_sorts =
296 let module K = Content in
299 Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
300 with Not_found -> None
305 { K.dec_name = name_of n;
306 K.dec_id = gen_id declaration_prefix seed;
307 K.dec_inductive = false;
313 { K.dec_name = name_of n;
314 K.dec_id = gen_id declaration_prefix seed;
315 K.dec_inductive = false;
321 let rec build_subproofs_and_args seed l ~ids_to_inner_types ~ids_to_inner_sorts =
322 let module C = Cic in
323 let module K = Content in
328 let subproofs,args = aux l1 in
329 if (test_for_lifting t ~ids_to_inner_types ~ids_to_inner_sorts) then
332 seed ~name:"H" ~ids_to_inner_types ~ids_to_inner_sorts t in
335 { K.premise_id = gen_id premise_prefix seed;
336 K.premise_xref = new_subproof.K.proof_id;
337 K.premise_binder = new_subproof.K.proof_name;
340 new_subproof::subproofs,new_arg::args
344 C.ARel (idr,idref,n,b) ->
347 Hashtbl.find ids_to_inner_sorts idr
348 with Not_found -> `Type) in
351 { K.premise_id = gen_id premise_prefix seed;
352 K.premise_xref = idr;
353 K.premise_binder = Some b;
357 | C.AConst(id,uri,[]) ->
360 Hashtbl.find ids_to_inner_sorts id
361 with Not_found -> `Type) in
364 { K.lemma_id = gen_id lemma_prefix seed;
365 K.lemma_name = UriManager.name_of_uri uri;
366 K.lemma_uri = UriManager.string_of_uri uri
369 | C.AMutConstruct(id,uri,tyno,consno,[]) ->
372 Hashtbl.find ids_to_inner_sorts id
373 with Not_found -> `Type) in
375 let inductive_types =
377 CicEnvironment.get_obj CicUniv.empty_ugraph uri
380 | Cic.InductiveDefinition (l,_,_,_) -> l
383 let (_,_,_,constructors) =
384 List.nth inductive_types tyno in
385 let name,_ = List.nth constructors (consno - 1) in
387 { K.lemma_id = gen_id lemma_prefix seed;
390 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
391 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^
395 | _ -> (K.Term t)) in
400 [{p with K.proof_name = None}],
403 K.Premise prem when prem.K.premise_xref = p.K.proof_id ->
404 K.Premise {prem with K.premise_binder = None}
410 build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
411 let module K = Content in
413 let sort = Hashtbl.find ids_to_inner_sorts id in
416 (acic2content seed ?name:(name_of n) ~ids_to_inner_sorts ~ids_to_inner_types t)
421 { K.def_name = name_of n;
422 K.def_id = gen_id definition_prefix seed;
427 Not_found -> assert false
429 (* the following function must be called with an object of sort
430 Prop. For debugging purposes this is tested again, possibly raising an
431 Not_a_proof exception *)
433 and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
434 let rec aux ?name t =
435 let module C = Cic in
436 let module K = Content in
437 let module C2A = Cic2acic in
440 C.ARel (id,idref,n,b) as t ->
441 let sort = Hashtbl.find ids_to_inner_sorts id in
443 generate_exact seed t id name ~ids_to_inner_types
444 else raise Not_a_proof
445 | C.AVar (id,uri,exp_named_subst) as t ->
446 let sort = Hashtbl.find ids_to_inner_sorts id in
448 generate_exact seed t id name ~ids_to_inner_types
449 else raise Not_a_proof
450 | C.AMeta (id,n,l) as t ->
451 let sort = Hashtbl.find ids_to_inner_sorts id in
453 generate_exact seed t id name ~ids_to_inner_types
454 else raise Not_a_proof
455 | C.ASort (id,s) -> raise Not_a_proof
456 | C.AImplicit _ -> raise NotImplemented
457 | C.AProd (_,_,_,_) -> raise Not_a_proof
458 | C.ACast (id,v,t) -> aux v
459 | C.ALambda (id,n,s,t) ->
460 let sort = Hashtbl.find ids_to_inner_sorts id in
464 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
465 match proof.K.proof_conclude.K.conclude_args with
473 (build_decl_item seed id n s ids_to_inner_sorts)::
474 proof'.K.proof_context
477 generate_intros_let_tac seed id n s true proof'' name ~ids_to_inner_types
478 else raise Not_a_proof
479 | C.ALetIn (id,n,s,t) ->
480 let sort = Hashtbl.find ids_to_inner_sorts id in
484 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
485 match proof.K.proof_conclude.K.conclude_args with
493 ((build_def_item seed id n s ids_to_inner_sorts
494 ids_to_inner_types):> Cic.annterm K.in_proof_context_element)
495 ::proof'.K.proof_context;
498 generate_intros_let_tac seed id n s false proof'' name ~ids_to_inner_types
499 else raise Not_a_proof
502 seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
503 with NotApplicable ->
505 seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
506 with NotApplicable ->
507 let subproofs, args =
508 build_subproofs_and_args
509 seed li ~ids_to_inner_types ~ids_to_inner_sorts in
512 List.filter (test_for_lifting ~ids_to_inner_types) li in
514 match args_to_lift with
515 [_] -> List.map aux args_to_lift
516 | _ -> List.map (aux ~name:"H") args_to_lift in
517 let args = build_args seed li subproofs
518 ~ids_to_inner_types ~ids_to_inner_sorts in *)
519 { K.proof_name = name;
520 K.proof_id = gen_id proof_prefix seed;
521 K.proof_context = [];
522 K.proof_apply_context = serialize seed subproofs;
524 { K.conclude_id = gen_id conclude_prefix seed;
525 K.conclude_aref = id;
526 K.conclude_method = "Apply";
527 K.conclude_args = args;
528 K.conclude_conclusion =
530 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
531 with Not_found -> None
534 | C.AConst (id,uri,exp_named_subst) as t ->
535 let sort = Hashtbl.find ids_to_inner_sorts id in
537 generate_exact seed t id name ~ids_to_inner_types
538 else raise Not_a_proof
539 | C.AMutInd (id,uri,i,exp_named_subst) -> raise Not_a_proof
540 | C.AMutConstruct (id,uri,i,j,exp_named_subst) as t ->
541 let sort = Hashtbl.find ids_to_inner_sorts id in
543 generate_exact seed t id name ~ids_to_inner_types
544 else raise Not_a_proof
545 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
546 let inductive_types,noparams =
547 (let o, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
549 Cic.Constant _ -> assert false
550 | Cic.Variable _ -> assert false
551 | Cic.CurrentProof _ -> assert false
552 | Cic.InductiveDefinition (l,_,n,_) -> l,n
554 let (_,_,_,constructors) = List.nth inductive_types typeno in
555 let name_and_arities =
556 let rec count_prods =
558 C.Prod (_,_,t) -> 1 + count_prods t
561 (function (n,t) -> Some n,((count_prods t) - noparams)) constructors in
563 let build_proof p (name,arity) =
564 let rec make_context_and_body c p n =
565 if n = 0 then c,(aux p)
568 Cic.ALambda(idl,vname,s1,t1) ->
570 build_decl_item seed idl vname s1 ~ids_to_inner_sorts in
571 make_context_and_body (ce::c) t1 (n-1)
572 | _ -> assert false) in
573 let context,body = make_context_and_body [] p arity in
575 {body with K.proof_name = name; K.proof_context=context} in
576 List.map2 build_proof patterns name_and_arities in
577 let teid = get_id te in
580 build_subproofs_and_args
581 seed ~ids_to_inner_types ~ids_to_inner_sorts [te]
584 | _ -> assert false) in
585 { K.proof_name = name;
586 K.proof_id = gen_id proof_prefix seed;
587 K.proof_context = [];
588 K.proof_apply_context = serialize seed context;
590 { K.conclude_id = gen_id conclude_prefix seed;
591 K.conclude_aref = id;
592 K.conclude_method = "Case";
594 (K.Aux (UriManager.string_of_uri uri))::
595 (K.Aux (string_of_int typeno))::(K.Term ty)::term::pp;
596 K.conclude_conclusion =
598 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
599 with Not_found -> None
602 | C.AFix (id, no, funs) ->
605 (function (_,name,_,_,bo) -> `Proof (aux ~name bo)) funs in
607 List.nth (List.map (fun (_,name,_,_,_) -> name) funs) no
609 let decreasing_args =
610 List.map (function (_,_,n,_,_) -> n) funs in
612 { K.joint_id = gen_id joint_prefix seed;
613 K.joint_kind = `Recursive decreasing_args;
614 K.joint_defs = proofs
617 { K.proof_name = name;
618 K.proof_id = gen_id proof_prefix seed;
619 K.proof_context = [`Joint jo];
620 K.proof_apply_context = [];
622 { K.conclude_id = gen_id conclude_prefix seed;
623 K.conclude_aref = id;
624 K.conclude_method = "Exact";
627 { K.premise_id = gen_id premise_prefix seed;
628 K.premise_xref = jo.K.joint_id;
629 K.premise_binder = Some fun_name;
630 K.premise_n = Some no;
633 K.conclude_conclusion =
635 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
636 with Not_found -> None
639 | C.ACoFix (id,no,funs) ->
642 (function (_,name,_,bo) -> `Proof (aux ~name bo)) funs in
644 { K.joint_id = gen_id joint_prefix seed;
645 K.joint_kind = `CoRecursive;
646 K.joint_defs = proofs
649 { K.proof_name = name;
650 K.proof_id = gen_id proof_prefix seed;
651 K.proof_context = [`Joint jo];
652 K.proof_apply_context = [];
654 { K.conclude_id = gen_id conclude_prefix seed;
655 K.conclude_aref = id;
656 K.conclude_method = "Exact";
659 { K.premise_id = gen_id premise_prefix seed;
660 K.premise_xref = jo.K.joint_id;
661 K.premise_binder = Some "tiralo fuori";
662 K.premise_n = Some no;
665 K.conclude_conclusion =
667 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
668 with Not_found -> None
673 generate_conversion seed false id t1 ~ids_to_inner_types
676 and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
677 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
678 let module C2A = Cic2acic in
679 let module K = Content in
680 let module C = Cic in
682 C.AConst (idc,uri,exp_named_subst)::args ->
683 let uri_str = UriManager.string_of_uri uri in
684 let suffix = Str.regexp_string "_ind.con" in
685 let len = String.length uri_str in
686 let n = (try (Str.search_backward suffix uri_str len)
687 with Not_found -> -1) in
688 if n<0 then raise NotApplicable
691 if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
692 else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
693 else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
694 else "ByInduction" in
695 let prefix = String.sub uri_str 0 n in
696 let ind_str = (prefix ^ ".ind") in
697 let ind_uri = UriManager.uri_of_string ind_str in
698 let inductive_types,noparams =
699 (let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph ind_uri in
701 | Cic.InductiveDefinition (l,_,n,_) -> (l,n)
705 if n = 0 then ([],l) else
706 let p,a = split (n-1) (List.tl l) in
707 ((List.hd l::p),a) in
708 let params_and_IP,tail_args = split (noparams+1) args in
710 (match inductive_types with
712 | _ -> raise NotApplicable) (* don't care for mutual ind *) in
714 let rec clean_up n t =
717 (label,Cic.Prod (_,_,t)) -> clean_up (n-1) (label,t)
718 | _ -> assert false) in
719 List.map (clean_up noparams) constructors in
720 let no_constructors= List.length constructors in
721 let args_for_cases, other_args =
722 split no_constructors tail_args in
723 let subproofs,other_method_args =
724 build_subproofs_and_args seed other_args
725 ~ids_to_inner_types ~ids_to_inner_sorts in
727 let rec build_method_args =
729 [],_-> [] (* extra args are ignored ???? *)
730 | (name,ty)::tlc,arg::tla ->
731 let idarg = get_id arg in
733 (try (Hashtbl.find ids_to_inner_sorts idarg)
734 with Not_found -> `Type) in
736 if sortarg = `Prop then
740 Cic.Prod (_,s,t),Cic.ALambda(idl,n,s1,t1) ->
743 seed idl n s1 ~ids_to_inner_sorts in
744 if (occur ind_uri s) then
746 Cic.ALambda(id2,n2,s2,t2) ->
749 { K.dec_name = name_of n2;
751 gen_id declaration_prefix seed;
752 K.dec_inductive = true;
756 let (context,body) = bc (t,t2) in
757 (ce::inductive_hyp::context,body)
761 let (context,body) = bc (t,t1) in
763 | _ , t -> ([],aux t) in
767 K.proof_name = Some name;
768 K.proof_context = co;
771 hdarg::(build_method_args (tlc,tla))
772 | _ -> assert false in
773 build_method_args (constructors1,args_for_cases) in
774 { K.proof_name = name;
775 K.proof_id = gen_id proof_prefix seed;
776 K.proof_context = [];
777 K.proof_apply_context = serialize seed subproofs;
779 { K.conclude_id = gen_id conclude_prefix seed;
780 K.conclude_aref = id;
781 K.conclude_method = method_name;
783 K.Aux (string_of_int no_constructors)
784 ::K.Term (C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))
785 ::method_args@other_method_args;
786 K.conclude_conclusion =
788 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
789 with Not_found -> None
792 | _ -> raise NotApplicable
794 and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
795 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
796 let module C2A = Cic2acic in
797 let module K = Content in
798 let module C = Cic in
800 C.AConst (sid,uri,exp_named_subst)::args ->
801 if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
802 UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI then
805 build_subproofs_and_args
806 seed ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3]
809 | _,_ -> assert false) in
811 let rec ma_aux n = function
817 let aid = get_id a in
818 let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
819 with Not_found -> `Type) in
820 if asort = `Prop then
823 hd::(ma_aux (n-1) tl) in
825 { K.proof_name = name;
826 K.proof_id = gen_id proof_prefix seed;
827 K.proof_context = [];
828 K.proof_apply_context = serialize seed subproofs;
830 { K.conclude_id = gen_id conclude_prefix seed;
831 K.conclude_aref = id;
832 K.conclude_method = "Rewrite";
834 K.Term (C.AConst (sid,uri,exp_named_subst))::method_args;
835 K.conclude_conclusion =
837 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
838 with Not_found -> None
841 else raise NotApplicable
842 | _ -> raise NotApplicable
846 seed ~ids_to_inner_sorts ~ids_to_inner_types (id,n,context,ty)
848 let module K = Content in
853 | (id,Some (name,Cic.ADecl t)) ->
855 (* We should call build_decl_item, but we have not computed *)
856 (* the inner-types ==> we always produce a declaration *)
858 { K.dec_name = name_of name;
859 K.dec_id = gen_id declaration_prefix seed;
860 K.dec_inductive = false;
861 K.dec_aref = get_id t;
864 | (id,Some (name,Cic.ADef t)) ->
866 (* We should call build_def_item, but we have not computed *)
867 (* the inner-types ==> we always produce a declaration *)
869 { K.def_name = name_of name;
870 K.def_id = gen_id definition_prefix seed;
871 K.def_aref = get_id t;
879 (* map_sequent is similar to map_conjectures, but the for the hid
880 of the hypothesis, which are preserved instead of generating
881 fresh ones. We shall have to adopt a uniform policy, soon or later *)
883 let map_sequent ((id,n,context,ty):Cic.annconjecture) =
884 let module K = Content in
889 | (id,Some (name,Cic.ADecl t)) ->
891 (* We should call build_decl_item, but we have not computed *)
892 (* the inner-types ==> we always produce a declaration *)
894 { K.dec_name = name_of name;
896 K.dec_inductive = false;
897 K.dec_aref = get_id t;
900 | (id,Some (name,Cic.ADef t)) ->
902 (* We should call build_def_item, but we have not computed *)
903 (* the inner-types ==> we always produce a declaration *)
905 { K.def_name = name_of name;
907 K.def_aref = get_id t;
915 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
916 let module C = Cic in
917 let module K = Content in
918 let module C2A = Cic2acic in
921 C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
922 (gen_id object_prefix seed, params,
925 (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
928 build_def_item seed (get_id bo) (C.Name n) bo
929 ~ids_to_inner_sorts ~ids_to_inner_types))
930 | C.AConstant (_,_,n,Some bo,ty,params,_) ->
931 (gen_id object_prefix seed, params, None,
933 build_def_item seed (get_id bo) (C.Name n) bo
934 ~ids_to_inner_sorts ~ids_to_inner_types))
935 | C.AConstant (id,_,n,None,ty,params,_) ->
936 (gen_id object_prefix seed, params, None,
938 build_decl_item seed id (C.Name n) ty
939 ~ids_to_inner_sorts))
940 | C.AVariable (_,n,Some bo,ty,params,_) ->
941 (gen_id object_prefix seed, params, None,
943 build_def_item seed (get_id bo) (C.Name n) bo
944 ~ids_to_inner_sorts ~ids_to_inner_types))
945 | C.AVariable (id,n,None,ty,params,_) ->
946 (gen_id object_prefix seed, params, None,
948 build_decl_item seed id (C.Name n) ty
949 ~ids_to_inner_sorts))
950 | C.AInductiveDefinition (id,l,params,nparams,_) ->
951 (gen_id object_prefix seed, params, None,
953 { K.joint_id = gen_id joint_prefix seed;
954 K.joint_kind = `Inductive nparams;
955 K.joint_defs = List.map (build_inductive seed) l
959 build_inductive seed =
960 let module K = Content in
963 { K.inductive_id = gen_id inductive_prefix seed;
964 K.inductive_name = n;
965 K.inductive_kind = b;
966 K.inductive_type = ty;
967 K.inductive_constructors = build_constructors seed l
971 build_constructors seed l =
972 let module K = Content in
975 { K.dec_name = Some n;
976 K.dec_id = gen_id declaration_prefix seed;
977 K.dec_inductive = false;
984 and 'term cinductiveType =
985 id * string * bool * 'term * (* typename, inductive, arity *)
986 'term cconstructor list (* constructors *)
988 and 'term cconstructor =