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
581 build_subproofs_and_args
582 seed ~ids_to_inner_types ~ids_to_inner_sorts [te]
585 | _ -> assert false) in
586 { K.proof_name = name;
587 K.proof_id = gen_id proof_prefix seed;
588 K.proof_context = [];
589 K.proof_apply_context = serialize seed context;
591 { K.conclude_id = gen_id conclude_prefix seed;
592 K.conclude_aref = id;
593 K.conclude_method = "Case";
595 (K.Aux (UriManager.string_of_uri uri))::
596 (K.Aux (string_of_int typeno))::(K.Term ty)::term::pp;
597 K.conclude_conclusion =
599 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
600 with Not_found -> None
603 | C.AFix (id, no, funs) ->
606 (function (_,name,_,_,bo) -> `Proof (aux ~name bo)) funs in
608 List.nth (List.map (fun (_,name,_,_,_) -> name) funs) no
610 let decreasing_args =
611 List.map (function (_,_,n,_,_) -> n) funs in
613 { K.joint_id = gen_id joint_prefix seed;
614 K.joint_kind = `Recursive decreasing_args;
615 K.joint_defs = proofs
618 { K.proof_name = name;
619 K.proof_id = gen_id proof_prefix seed;
620 K.proof_context = [`Joint jo];
621 K.proof_apply_context = [];
623 { K.conclude_id = gen_id conclude_prefix seed;
624 K.conclude_aref = id;
625 K.conclude_method = "Exact";
628 { K.premise_id = gen_id premise_prefix seed;
629 K.premise_xref = jo.K.joint_id;
630 K.premise_binder = Some fun_name;
631 K.premise_n = Some no;
634 K.conclude_conclusion =
636 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
637 with Not_found -> None
640 | C.ACoFix (id,no,funs) ->
643 (function (_,name,_,bo) -> `Proof (aux ~name bo)) funs in
645 { K.joint_id = gen_id joint_prefix seed;
646 K.joint_kind = `CoRecursive;
647 K.joint_defs = proofs
650 { K.proof_name = name;
651 K.proof_id = gen_id proof_prefix seed;
652 K.proof_context = [`Joint jo];
653 K.proof_apply_context = [];
655 { K.conclude_id = gen_id conclude_prefix seed;
656 K.conclude_aref = id;
657 K.conclude_method = "Exact";
660 { K.premise_id = gen_id premise_prefix seed;
661 K.premise_xref = jo.K.joint_id;
662 K.premise_binder = Some "tiralo fuori";
663 K.premise_n = Some no;
666 K.conclude_conclusion =
668 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
669 with Not_found -> None
674 generate_conversion seed false id t1 ~ids_to_inner_types
677 and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
678 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
679 let module C2A = Cic2acic in
680 let module K = Content in
681 let module C = Cic in
683 C.AConst (idc,uri,exp_named_subst)::args ->
684 let uri_str = UriManager.string_of_uri uri in
685 let suffix = Str.regexp_string "_ind.con" in
686 let len = String.length uri_str in
687 let n = (try (Str.search_backward suffix uri_str len)
688 with Not_found -> -1) in
689 if n<0 then raise NotApplicable
692 if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
693 else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
694 else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
695 else "ByInduction" in
696 let prefix = String.sub uri_str 0 n in
697 let ind_str = (prefix ^ ".ind") in
698 let ind_uri = UriManager.uri_of_string ind_str in
699 let inductive_types,noparams =
700 (let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph ind_uri in
702 | Cic.InductiveDefinition (l,_,n,_) -> (l,n)
706 if n = 0 then ([],l) else
707 let p,a = split (n-1) (List.tl l) in
708 ((List.hd l::p),a) in
709 let params_and_IP,tail_args = split (noparams+1) args in
711 (match inductive_types with
713 | _ -> raise NotApplicable) (* don't care for mutual ind *) in
715 let rec clean_up n t =
718 (label,Cic.Prod (_,_,t)) -> clean_up (n-1) (label,t)
719 | _ -> assert false) in
720 List.map (clean_up noparams) constructors in
721 let no_constructors= List.length constructors in
722 let args_for_cases, other_args =
723 split no_constructors tail_args in
724 let subproofs,other_method_args =
725 build_subproofs_and_args seed other_args
726 ~ids_to_inner_types ~ids_to_inner_sorts in
728 let rec build_method_args =
730 [],_-> [] (* extra args are ignored ???? *)
731 | (name,ty)::tlc,arg::tla ->
732 let idarg = get_id arg in
734 (try (Hashtbl.find ids_to_inner_sorts idarg)
735 with Not_found -> `Type (CicUniv.fresh())) in
737 if sortarg = `Prop then
741 Cic.Prod (_,s,t),Cic.ALambda(idl,n,s1,t1) ->
744 seed idl n s1 ~ids_to_inner_sorts in
745 if (occur ind_uri s) then
747 Cic.ALambda(id2,n2,s2,t2) ->
750 { K.dec_name = name_of n2;
752 gen_id declaration_prefix seed;
753 K.dec_inductive = true;
757 let (context,body) = bc (t,t2) in
758 (ce::inductive_hyp::context,body)
762 let (context,body) = bc (t,t1) in
764 | _ , t -> ([],aux t) in
768 K.proof_name = Some name;
769 K.proof_context = co;
772 hdarg::(build_method_args (tlc,tla))
773 | _ -> assert false in
774 build_method_args (constructors1,args_for_cases) in
775 { K.proof_name = name;
776 K.proof_id = gen_id proof_prefix seed;
777 K.proof_context = [];
778 K.proof_apply_context = serialize seed subproofs;
780 { K.conclude_id = gen_id conclude_prefix seed;
781 K.conclude_aref = id;
782 K.conclude_method = method_name;
784 K.Aux (string_of_int no_constructors)
785 ::K.Term (C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))
786 ::method_args@other_method_args;
787 K.conclude_conclusion =
789 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
790 with Not_found -> None
793 | _ -> raise NotApplicable
795 and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
796 let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
797 let module C2A = Cic2acic in
798 let module K = Content in
799 let module C = Cic in
801 C.AConst (sid,uri,exp_named_subst)::args ->
802 if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
803 UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI or
804 LibraryObjects.is_eq_ind_URI uri or
805 LibraryObjects.is_eq_ind_r_URI uri then
808 build_subproofs_and_args
809 seed ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3]
812 | _,_ -> assert false) in
814 let rec ma_aux n = function
820 let aid = get_id a in
821 let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
822 with Not_found -> `Type (CicUniv.fresh())) in
823 if asort = `Prop then
826 hd::(ma_aux (n-1) tl) in
828 { K.proof_name = name;
829 K.proof_id = gen_id proof_prefix seed;
830 K.proof_context = [];
831 K.proof_apply_context = serialize seed subproofs;
833 { K.conclude_id = gen_id conclude_prefix seed;
834 K.conclude_aref = id;
835 K.conclude_method = "Rewrite";
837 K.Term (C.AConst (sid,uri,exp_named_subst))::method_args;
838 K.conclude_conclusion =
840 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
841 with Not_found -> None
844 else raise NotApplicable
845 | _ -> raise NotApplicable
849 seed ~ids_to_inner_sorts ~ids_to_inner_types (id,n,context,ty)
851 let module K = Content in
856 | (id,Some (name,Cic.ADecl t)) ->
858 (* We should call build_decl_item, but we have not computed *)
859 (* the inner-types ==> we always produce a declaration *)
861 { K.dec_name = name_of name;
862 K.dec_id = gen_id declaration_prefix seed;
863 K.dec_inductive = false;
864 K.dec_aref = get_id t;
867 | (id,Some (name,Cic.ADef t)) ->
869 (* We should call build_def_item, but we have not computed *)
870 (* the inner-types ==> we always produce a declaration *)
872 { K.def_name = name_of name;
873 K.def_id = gen_id definition_prefix seed;
874 K.def_aref = get_id t;
882 (* map_sequent is similar to map_conjectures, but the for the hid
883 of the hypothesis, which are preserved instead of generating
884 fresh ones. We shall have to adopt a uniform policy, soon or later *)
886 let map_sequent ((id,n,context,ty):Cic.annconjecture) =
887 let module K = Content in
892 | (id,Some (name,Cic.ADecl t)) ->
894 (* We should call build_decl_item, but we have not computed *)
895 (* the inner-types ==> we always produce a declaration *)
897 { K.dec_name = name_of name;
899 K.dec_inductive = false;
900 K.dec_aref = get_id t;
903 | (id,Some (name,Cic.ADef t)) ->
905 (* We should call build_def_item, but we have not computed *)
906 (* the inner-types ==> we always produce a declaration *)
908 { K.def_name = name_of name;
910 K.def_aref = get_id t;
918 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
919 let module C = Cic in
920 let module K = Content in
921 let module C2A = Cic2acic in
924 C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
925 (gen_id object_prefix seed, params,
928 (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
931 build_def_item seed (get_id bo) (C.Name n) bo
932 ~ids_to_inner_sorts ~ids_to_inner_types))
933 | C.AConstant (_,_,n,Some bo,ty,params,_) ->
934 (gen_id object_prefix seed, params, None,
936 build_def_item seed (get_id bo) (C.Name n) bo
937 ~ids_to_inner_sorts ~ids_to_inner_types))
938 | C.AConstant (id,_,n,None,ty,params,_) ->
939 (gen_id object_prefix seed, params, None,
941 build_decl_item seed id (C.Name n) ty
942 ~ids_to_inner_sorts))
943 | C.AVariable (_,n,Some bo,ty,params,_) ->
944 (gen_id object_prefix seed, params, None,
946 build_def_item seed (get_id bo) (C.Name n) bo
947 ~ids_to_inner_sorts ~ids_to_inner_types))
948 | C.AVariable (id,n,None,ty,params,_) ->
949 (gen_id object_prefix seed, params, None,
951 build_decl_item seed id (C.Name n) ty
952 ~ids_to_inner_sorts))
953 | C.AInductiveDefinition (id,l,params,nparams,_) ->
954 (gen_id object_prefix seed, params, None,
956 { K.joint_id = gen_id joint_prefix seed;
957 K.joint_kind = `Inductive nparams;
958 K.joint_defs = List.map (build_inductive seed) l
962 build_inductive seed =
963 let module K = Content in
966 { K.inductive_id = gen_id inductive_prefix seed;
967 K.inductive_name = n;
968 K.inductive_kind = b;
969 K.inductive_type = ty;
970 K.inductive_constructors = build_constructors seed l
974 build_constructors seed l =
975 let module K = Content in
978 { K.dec_name = Some n;
979 K.dec_id = gen_id declaration_prefix seed;
980 K.dec_inductive = false;
987 and 'term cinductiveType =
988 id * string * bool * 'term * (* typename, inductive, arity *)
989 'term cconstructor list (* constructors *)
991 and 'term cconstructor =