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 let hide_coercions = ref true;;
49 (* e se mettessi la conversione di BY nell'apply_context ? *)
50 (* sarebbe carino avere l'invariante che la proof2pres
51 generasse sempre prove con contesto vuoto *)
53 let gen_id prefix seed =
54 let res = prefix ^ string_of_int !seed in
59 let name_of = function
61 | Cic.Name b -> Some b;;
63 exception Not_a_proof;;
64 exception NotImplemented;;
65 exception NotApplicable;;
67 (* we do not care for positivity, here, that in any case is enforced by
68 well typing. Just a brutal search *)
77 | C.Implicit _ -> assert false
78 | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
79 | C.Cast (te,ty) -> (occur uri te)
80 | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
81 | C.LetIn (_,s,t) -> (occur uri s) or (occur uri t)
86 else (occur uri a)) false l
87 | C.Const (_,_) -> false
88 | C.MutInd (uri1,_,_) -> if uri = uri1 then true else false
89 | C.MutConstruct (_,_,_,_) -> false
90 | C.MutCase _ -> false (* presuming too much?? *)
91 | C.Fix _ -> false (* presuming too much?? *)
92 | C.CoFix (_,_) -> false (* presuming too much?? *)
98 C.ARel (id,_,_,_) -> id
99 | C.AVar (id,_,_) -> id
100 | C.AMeta (id,_,_) -> id
101 | C.ASort (id,_) -> id
102 | C.AImplicit _ -> raise NotImplemented
103 | C.AProd (id,_,_,_) -> id
104 | C.ACast (id,_,_) -> id
105 | C.ALambda (id,_,_,_) -> id
106 | C.ALetIn (id,_,_,_) -> id
107 | C.AAppl (id,_) -> id
108 | C.AConst (id,_,_) -> id
109 | C.AMutInd (id,_,_,_) -> id
110 | C.AMutConstruct (id,_,_,_,_) -> id
111 | C.AMutCase (id,_,_,_,_,_) -> id
112 | C.AFix (id,_,_) -> id
113 | C.ACoFix (id,_,_) -> id
116 let test_for_lifting ~ids_to_inner_types ~ids_to_inner_sorts=
117 let module C = Cic in
118 let module C2A = Cic2acic in
119 (* atomic terms are never lifted, according to my policy *)
123 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
125 with Not_found -> false)
128 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
130 with Not_found -> false)
131 | C.AMeta (id,_,_) ->
133 Hashtbl.find ids_to_inner_sorts id = `Prop
134 with Not_found -> assert false)
135 | C.ASort (id,_) -> false
136 | C.AImplicit _ -> raise NotImplemented
137 | C.AProd (id,_,_,_) -> false
138 | C.ACast (id,_,_) ->
140 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
142 with Not_found -> false)
143 | C.ALambda (id,_,_,_) ->
145 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
147 with Not_found -> false)
148 | C.ALetIn (id,_,_,_) ->
150 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
152 with Not_found -> false)
155 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
157 with Not_found -> false)
158 | C.AConst (id,_,_) ->
160 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
162 with Not_found -> false)
163 | C.AMutInd (id,_,_,_) -> false
164 | C.AMutConstruct (id,_,_,_,_) ->
166 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
168 with Not_found -> false)
170 | C.AMutCase (id,_,_,_,_,_) ->
172 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
174 with Not_found -> false)
177 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
179 with Not_found -> false)
180 | C.ACoFix (id,_,_) ->
182 ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
184 with Not_found -> false)
187 (* transform a proof p into a proof list, concatenating the last
188 conclude element to the apply_context list, in case context is
189 empty. Otherwise, it just returns [p] *)
192 let module K = Content in
193 if (p.K.proof_context = []) then
194 if p.K.proof_apply_context = [] then [p]
198 K.proof_context = [];
199 K.proof_apply_context = []
201 p.K.proof_apply_context@[p1]
206 let rec serialize seed =
209 | a::l -> (flat seed a)@(serialize seed l)
212 (* top_down = true if the term is a LAMBDA or a decl *)
213 let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
214 let module C2A = Cic2acic in
215 let module K = Content in
216 let exp = (try ((Hashtbl.find ids_to_inner_types id).C2A.annexpected)
217 with Not_found -> None)
222 if inner_proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
223 { K.proof_name = inner_proof.K.proof_name;
224 K.proof_id = gen_id proof_prefix seed;
225 K.proof_context = [] ;
226 K.proof_apply_context = [];
228 { K.conclude_id = gen_id conclude_prefix seed;
229 K.conclude_aref = id;
230 K.conclude_method = "TD_Conversion";
232 [K.ArgProof {inner_proof with K.proof_name = None}];
233 K.conclude_conclusion = Some expty
237 { K.proof_name = inner_proof.K.proof_name;
238 K.proof_id = gen_id proof_prefix seed;
239 K.proof_context = [] ;
240 K.proof_apply_context = [{inner_proof with K.proof_name = None}];
242 { K.conclude_id = gen_id conclude_prefix seed;
243 K.conclude_aref = id;
244 K.conclude_method = "BU_Conversion";
247 { K.premise_id = gen_id premise_prefix seed;
248 K.premise_xref = inner_proof.K.proof_id;
249 K.premise_binder = None;
253 K.conclude_conclusion = Some expty
258 let generate_exact seed t id name ~ids_to_inner_types =
259 let module C2A = Cic2acic in
260 let module K = Content in
261 { K.proof_name = name;
262 K.proof_id = gen_id proof_prefix seed ;
263 K.proof_context = [] ;
264 K.proof_apply_context = [];
266 { K.conclude_id = gen_id conclude_prefix seed;
267 K.conclude_aref = id;
268 K.conclude_method = "Exact";
269 K.conclude_args = [K.Term (false, t)];
270 K.conclude_conclusion =
271 try Some (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
272 with Not_found -> None
277 let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_types =
278 let module C2A = Cic2acic in
279 let module C = Cic in
280 let module K = Content in
281 { K.proof_name = name;
282 K.proof_id = gen_id proof_prefix seed ;
283 K.proof_context = [] ;
284 K.proof_apply_context = [];
286 { K.conclude_id = gen_id conclude_prefix seed;
287 K.conclude_aref = id;
288 K.conclude_method = "Intros+LetTac";
289 K.conclude_args = [K.ArgProof inner_proof];
290 K.conclude_conclusion =
292 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
294 (match inner_proof.K.proof_conclude.K.conclude_conclusion with
297 if is_intro then Some (C.AProd ("gen"^id,n,s,t))
298 else Some (C.ALetIn ("gen"^id,n,s,t)))
303 let build_decl_item seed id n s ~ids_to_inner_sorts =
304 let module K = Content in
307 Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
308 with Not_found -> None
313 { K.dec_name = name_of n;
314 K.dec_id = gen_id declaration_prefix seed;
315 K.dec_inductive = false;
321 { K.dec_name = name_of n;
322 K.dec_id = gen_id declaration_prefix seed;
323 K.dec_inductive = false;
329 let infer_dependent ~headless context metasenv = function
334 List.map (function s -> false,s) l
338 CicTypeChecker.type_of_aux'
339 metasenv context (Deannotate.deannotate_term he)
340 CicUniv.oblivion_ugraph
343 match CicReduction.whd context t with
344 | Cic.Prod _ -> false
347 let rec dummify_last_tgt t =
348 match CicReduction.whd context t with
349 | Cic.Prod (n,s,tgt) -> Cic.Prod(n,s, dummify_last_tgt tgt)
350 | _ -> Cic.Implicit None
352 let rec aux ty = function
356 FreshNamesGenerator.clean_dummy_dependent_types
357 (dummify_last_tgt ty)
359 | Cic.Prod (n,src,tgt) ->
360 (n <> Cic.Anonymous && fstorder src, t) ::
361 aux (CicSubstitution.subst
362 (Deannotate.deannotate_term t) tgt) tl
363 | _ -> List.map (fun s -> false,s) (t::tl)
365 (false, he) :: aux hety tl
366 with CicTypeChecker.TypeCheckerFailure _ -> assert false
369 let rec build_subproofs_and_args ?(headless=false) seed context metasenv l ~ids_to_inner_types ~ids_to_inner_sorts =
370 let module C = Cic in
371 let module K = Content in
377 test_for_lifting t ~ids_to_inner_types ~ids_to_inner_sorts in
378 let subproofs,args = aux (n + if need_lifting then 1 else 0) l1 in
382 seed context metasenv
383 ~name:("H" ^ string_of_int n) ~ids_to_inner_types
384 ~ids_to_inner_sorts t in
387 { K.premise_id = gen_id premise_prefix seed;
388 K.premise_xref = new_subproof.K.proof_id;
389 K.premise_binder = new_subproof.K.proof_name;
392 new_subproof::subproofs,new_arg::args
396 C.ARel (idr,idref,n,b) ->
399 Hashtbl.find ids_to_inner_sorts idr
400 with Not_found -> `Type (CicUniv.fresh())) in
403 { K.premise_id = gen_id premise_prefix seed;
404 K.premise_xref = idr;
405 K.premise_binder = Some b;
408 else (K.Term (dep,t))
409 | C.AConst(id,uri,[]) ->
412 Hashtbl.find ids_to_inner_sorts id
413 with Not_found -> `Type (CicUniv.fresh())) in
416 { K.lemma_id = gen_id lemma_prefix seed;
417 K.lemma_name = UriManager.name_of_uri uri;
418 K.lemma_uri = UriManager.string_of_uri uri
420 else (K.Term (dep,t))
421 | C.AMutConstruct(id,uri,tyno,consno,[]) ->
424 Hashtbl.find ids_to_inner_sorts id
425 with Not_found -> `Type (CicUniv.fresh())) in
427 let inductive_types =
429 CicEnvironment.get_obj CicUniv.empty_ugraph uri
432 | Cic.InductiveDefinition (l,_,_,_) -> l
435 let (_,_,_,constructors) =
436 List.nth inductive_types tyno in
437 let name,_ = List.nth constructors (consno - 1) in
439 { K.lemma_id = gen_id lemma_prefix seed;
442 UriManager.string_of_uri uri ^ "#xpointer(1/" ^
443 string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^
446 else (K.Term (dep,t))
447 | _ -> (K.Term (dep,t))) in
450 match (aux 1 (infer_dependent ~headless context metasenv l)) with
452 [{p with K.proof_name = None}],
455 K.Premise prem when prem.K.premise_xref = p.K.proof_id ->
456 K.Premise {prem with K.premise_binder = None}
462 build_def_item seed context metasenv id n t ~ids_to_inner_sorts ~ids_to_inner_types =
463 let module K = Content in
465 let sort = Hashtbl.find ids_to_inner_sorts id in
468 (acic2content seed context metasenv ?name:(name_of n) ~ids_to_inner_sorts ~ids_to_inner_types t)
473 { K.def_name = name_of n;
474 K.def_id = gen_id definition_prefix seed;
479 Not_found -> assert false
481 (* the following function must be called with an object of sort
482 Prop. For debugging purposes this is tested again, possibly raising an
483 Not_a_proof exception *)
485 and acic2content seed context metasenv ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
486 let rec aux ?name context t =
487 let module C = Cic in
488 let module K = Content in
489 let module C2A = Cic2acic in
492 C.ARel (id,idref,n,b) as t ->
493 let sort = Hashtbl.find ids_to_inner_sorts id in
495 generate_exact seed t id name ~ids_to_inner_types
496 else raise Not_a_proof
497 | C.AVar (id,uri,exp_named_subst) as t ->
498 let sort = Hashtbl.find ids_to_inner_sorts id in
500 generate_exact seed t id name ~ids_to_inner_types
501 else raise Not_a_proof
502 | C.AMeta (id,n,l) as t ->
503 let sort = Hashtbl.find ids_to_inner_sorts id in
505 generate_exact seed t id name ~ids_to_inner_types
506 else raise Not_a_proof
507 | C.ASort (id,s) -> raise Not_a_proof
508 | C.AImplicit _ -> raise NotImplemented
509 | C.AProd (_,_,_,_) -> raise Not_a_proof
510 | C.ACast (id,v,t) -> aux context v
511 | C.ALambda (id,n,s,t) ->
512 let sort = Hashtbl.find ids_to_inner_sorts id in
515 aux ((Some (n,Cic.Decl (Deannotate.deannotate_term s)))::context) t
518 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
519 match proof.K.proof_conclude.K.conclude_args with
527 (build_decl_item seed id n s ids_to_inner_sorts)::
528 proof'.K.proof_context
531 generate_intros_let_tac seed id n s true proof'' name ~ids_to_inner_types
534 | C.ALetIn (id,n,s,t) ->
535 let sort = Hashtbl.find ids_to_inner_sorts id in
537 let proof = (* XXX TIPAMI!!! *)
538 aux ((Some (n,Cic.Def (Deannotate.deannotate_term s,None)))::context) t
541 if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
542 match proof.K.proof_conclude.K.conclude_args with
550 ((build_def_item seed context metasenv (get_id s) n s ids_to_inner_sorts
551 ids_to_inner_types):> Cic.annterm K.in_proof_context_element)
552 ::proof'.K.proof_context;
555 generate_intros_let_tac seed id n s false proof'' name ~ids_to_inner_types
560 seed context metasenv li ~ids_to_inner_types ~ids_to_inner_sorts
561 with NotApplicable ->
563 seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts
564 with NotApplicable ->
566 seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts
567 with NotApplicable ->
569 seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts
570 with NotApplicable ->
571 let subproofs, args =
572 build_subproofs_and_args
573 seed context metasenv li ~ids_to_inner_types ~ids_to_inner_sorts in
576 List.filter (test_for_lifting ~ids_to_inner_types) li in
578 match args_to_lift with
579 [_] -> List.map aux args_to_lift
580 | _ -> List.map (aux ~name:"H") args_to_lift in
581 let args = build_args seed li subproofs
582 ~ids_to_inner_types ~ids_to_inner_sorts in *)
583 { K.proof_name = name;
584 K.proof_id = gen_id proof_prefix seed;
585 K.proof_context = [];
586 K.proof_apply_context = serialize seed subproofs;
588 { K.conclude_id = gen_id conclude_prefix seed;
589 K.conclude_aref = id;
590 K.conclude_method = "Apply";
591 K.conclude_args = args;
592 K.conclude_conclusion =
594 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
595 with Not_found -> None
598 | C.AConst (id,uri,exp_named_subst) as t ->
599 let sort = Hashtbl.find ids_to_inner_sorts id in
601 generate_exact seed t id name ~ids_to_inner_types
602 else raise Not_a_proof
603 | C.AMutInd (id,uri,i,exp_named_subst) -> raise Not_a_proof
604 | C.AMutConstruct (id,uri,i,j,exp_named_subst) as t ->
605 let sort = Hashtbl.find ids_to_inner_sorts id in
607 generate_exact seed t id name ~ids_to_inner_types
608 else raise Not_a_proof
609 | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
610 let inductive_types,noparams =
611 (let o, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
613 Cic.Constant _ -> assert false
614 | Cic.Variable _ -> assert false
615 | Cic.CurrentProof _ -> assert false
616 | Cic.InductiveDefinition (l,_,n,_) -> l,n
618 let (_,_,_,constructors) = List.nth inductive_types typeno in
619 let name_and_arities =
620 let rec count_prods =
622 C.Prod (_,_,t) -> 1 + count_prods t
625 (function (n,t) -> Some n,((count_prods t) - noparams)) constructors in
627 let build_proof p (name,arity) =
628 let rec make_context_and_body c p n =
629 if n = 0 then c,(aux context p)
632 Cic.ALambda(idl,vname,s1,t1) ->
635 seed idl vname s1 ~ids_to_inner_sorts in
636 make_context_and_body (ce::c) t1 (n-1)
637 | _ -> assert false) in
638 let context,body = make_context_and_body [] p arity in
640 {body with K.proof_name = name; K.proof_context=context} in
641 List.map2 build_proof patterns name_and_arities in
644 build_subproofs_and_args ~headless:true
645 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts [te]
648 | _ -> assert false) in
649 { K.proof_name = name;
650 K.proof_id = gen_id proof_prefix seed;
651 K.proof_context = [];
652 K.proof_apply_context = serialize seed context;
654 { K.conclude_id = gen_id conclude_prefix seed;
655 K.conclude_aref = id;
656 K.conclude_method = "Case";
658 (K.Aux (UriManager.string_of_uri uri))::
659 (K.Aux (string_of_int typeno))::(K.Term (false,ty))::term::pp;
660 K.conclude_conclusion =
662 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
663 with Not_found -> None
666 | C.AFix (id, no, funs) ->
669 (fun ctx (_,n,_,ty,_) ->
670 let ty = Deannotate.deannotate_term ty in
671 Some (Cic.Name n,Cic.Decl ty) :: ctx)
676 (function (_,name,_,_,bo) -> `Proof (aux context' ~name bo)) funs in
678 List.nth (List.map (fun (_,name,_,_,_) -> name) funs) no
680 let decreasing_args =
681 List.map (function (_,_,n,_,_) -> n) funs in
683 { K.joint_id = gen_id joint_prefix seed;
684 K.joint_kind = `Recursive decreasing_args;
685 K.joint_defs = proofs
688 { K.proof_name = name;
689 K.proof_id = gen_id proof_prefix seed;
690 K.proof_context = [`Joint jo];
691 K.proof_apply_context = [];
693 { K.conclude_id = gen_id conclude_prefix seed;
694 K.conclude_aref = id;
695 K.conclude_method = "Exact";
698 { K.premise_id = gen_id premise_prefix seed;
699 K.premise_xref = jo.K.joint_id;
700 K.premise_binder = Some fun_name;
701 K.premise_n = Some no;
704 K.conclude_conclusion =
706 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
707 with Not_found -> None
710 | C.ACoFix (id,no,funs) ->
713 (fun ctx (_,n,ty,_) ->
714 let ty = Deannotate.deannotate_term ty in
715 Some (Cic.Name n,Cic.Decl ty) :: ctx)
720 (function (_,name,_,bo) -> `Proof (aux context' ~name bo)) funs in
722 { K.joint_id = gen_id joint_prefix seed;
723 K.joint_kind = `CoRecursive;
724 K.joint_defs = proofs
727 { K.proof_name = name;
728 K.proof_id = gen_id proof_prefix seed;
729 K.proof_context = [`Joint jo];
730 K.proof_apply_context = [];
732 { K.conclude_id = gen_id conclude_prefix seed;
733 K.conclude_aref = id;
734 K.conclude_method = "Exact";
737 { K.premise_id = gen_id premise_prefix seed;
738 K.premise_xref = jo.K.joint_id;
739 K.premise_binder = Some "tiralo fuori";
740 K.premise_n = Some no;
743 K.conclude_conclusion =
745 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
746 with Not_found -> None
751 generate_conversion seed false id t1 ~ids_to_inner_types
752 in aux ?name context t
754 and inductive seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts =
755 let aux context ?name =
756 acic2content seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts
758 let module C2A = Cic2acic in
759 let module K = Content in
760 let module C = Cic in
762 C.AConst (idc,uri,exp_named_subst)::args ->
763 let uri_str = UriManager.string_of_uri uri in
764 let suffix = Str.regexp_string "_ind.con" in
765 let len = String.length uri_str in
766 let n = (try (Str.search_backward suffix uri_str len)
767 with Not_found -> -1) in
768 if n<0 then raise NotApplicable
771 if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
772 else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
773 else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
774 else "ByInduction" in
775 let prefix = String.sub uri_str 0 n in
776 let ind_str = (prefix ^ ".ind") in
777 let ind_uri = UriManager.uri_of_string ind_str in
778 let inductive_types,noparams =
779 (let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph ind_uri in
781 | Cic.InductiveDefinition (l,_,n,_) -> (l,n)
785 if n = 0 then ([],l) else
786 let p,a = split (n-1) (List.tl l) in
787 ((List.hd l::p),a) in
788 let params_and_IP,tail_args = split (noparams+1) args in
790 (match inductive_types with
792 | _ -> raise NotApplicable) (* don't care for mutual ind *) in
794 let rec clean_up n t =
797 (label,Cic.Prod (_,_,t)) -> clean_up (n-1) (label,t)
798 | _ -> assert false) in
799 List.map (clean_up noparams) constructors in
800 let no_constructors= List.length constructors in
801 let args_for_cases, other_args =
802 split no_constructors tail_args in
803 let subproofs,other_method_args =
804 build_subproofs_and_args ~headless:true seed context metasenv
805 other_args ~ids_to_inner_types ~ids_to_inner_sorts in
807 let rec build_method_args =
809 [],_-> [] (* extra args are ignored ???? *)
810 | (name,ty)::tlc,arg::tla ->
811 let idarg = get_id arg in
813 (try (Hashtbl.find ids_to_inner_sorts idarg)
814 with Not_found -> `Type (CicUniv.fresh())) in
816 if sortarg = `Prop then
820 Cic.Prod (_,s,t),Cic.ALambda(idl,n,s1,t1) ->
822 Some (n,Cic.Decl(Deannotate.deannotate_term s1))
827 seed idl n s1 ~ids_to_inner_sorts in
828 if (occur ind_uri s) then
830 Cic.ALambda(id2,n2,s2,t2) ->
834 (Deannotate.deannotate_term s2))
839 { K.dec_name = name_of n2;
841 gen_id declaration_prefix seed;
842 K.dec_inductive = true;
846 let (context,body) = bc context'' (t,t2) in
847 (ce::inductive_hyp::context,body)
851 let (context,body) = bc context' (t,t1) in
853 | _ , t -> ([],aux context t) in
854 bc context (ty,arg) in
857 K.proof_name = Some name;
858 K.proof_context = co;
860 else (K.Term (false,arg)) in
861 hdarg::(build_method_args (tlc,tla))
862 | _ -> assert false in
863 build_method_args (constructors1,args_for_cases) in
864 { K.proof_name = name;
865 K.proof_id = gen_id proof_prefix seed;
866 K.proof_context = [];
867 K.proof_apply_context = serialize seed subproofs;
869 { K.conclude_id = gen_id conclude_prefix seed;
870 K.conclude_aref = id;
871 K.conclude_method = method_name;
873 K.Aux (string_of_int no_constructors)
874 ::K.Term (false,(C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP))))
875 ::method_args@other_method_args;
876 K.conclude_conclusion =
878 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
879 with Not_found -> None
882 | _ -> raise NotApplicable
884 and coercion seed context metasenv li ~ids_to_inner_types ~ids_to_inner_sorts =
886 | ((Cic.AConst _) as he)::tl
887 | ((Cic.AMutInd _) as he)::tl
888 | ((Cic.AMutConstruct _) as he)::tl when
889 CoercDb.is_a_coercion' (Deannotate.deannotate_term he) &&
898 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts (last tl)
899 | _ -> raise NotApplicable
901 and rewrite seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts =
902 let aux context ?name =
903 acic2content seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts
905 let module C2A = Cic2acic in
906 let module K = Content in
907 let module C = Cic in
909 C.AConst (sid,uri,exp_named_subst)::args ->
910 if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
911 UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI or
912 LibraryObjects.is_eq_ind_URI uri or
913 LibraryObjects.is_eq_ind_r_URI uri then
916 build_subproofs_and_args
917 seed context metasenv
918 ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3]
921 | _,_ -> assert false) in
923 let rec ma_aux n = function
929 let aid = get_id a in
930 let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
931 with Not_found -> `Type (CicUniv.fresh())) in
932 if asort = `Prop then
933 K.ArgProof (aux context a)
934 else K.Term (false,a) in
935 hd::(ma_aux (n-1) tl) in
937 { K.proof_name = name;
938 K.proof_id = gen_id proof_prefix seed;
939 K.proof_context = [];
940 K.proof_apply_context = serialize seed subproofs;
942 { K.conclude_id = gen_id conclude_prefix seed;
943 K.conclude_aref = id;
945 if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI
946 || LibraryObjects.is_eq_ind_URI uri then
951 K.Term (false,(C.AConst (sid,uri,exp_named_subst)))::method_args;
952 K.conclude_conclusion =
954 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
955 with Not_found -> None
958 else raise NotApplicable
959 | _ -> raise NotApplicable
962 seed context metasenv name id li ~ids_to_inner_types ~ids_to_inner_sorts
964 let module C2A = Cic2acic in
965 let module K = Content in
966 let module C = Cic in
968 | C.AConst (sid,uri,exp_named_subst)::args
969 when LibraryObjects.is_trans_eq_URI uri ->
970 let exp_args = List.map snd exp_named_subst in
972 match exp_args@args with
973 | [_;t1;t2;t3;p1;p2] -> t1,t2,t3,p1,p2
974 | _ -> raise NotApplicable
976 { K.proof_name = name;
977 K.proof_id = gen_id proof_prefix seed;
978 K.proof_context = [];
979 K.proof_apply_context = [];
981 { K.conclude_id = gen_id conclude_prefix seed;
982 K.conclude_aref = id;
983 K.conclude_method = "Eq_chain";
987 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts p1)
988 @ [K.Term (false,t2)]@
990 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts p2)
991 @ [K.Term (false,t3)];
992 K.conclude_conclusion =
994 (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized
995 with Not_found -> None
998 | _ -> raise NotApplicable
1000 and transitivity_aux seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts t =
1001 let module C2A = Cic2acic in
1002 let module K = Content in
1003 let module C = Cic in
1005 | C.AAppl (_,C.AConst (sid,uri,exp_named_subst)::args)
1006 when LibraryObjects.is_trans_eq_URI uri ->
1007 let exp_args = List.map snd exp_named_subst in
1008 let t1,t2,t3,p1,p2 =
1009 match exp_args@args with
1010 | [_;t1;t2;t3;p1;p2] -> t1,t2,t3,p1,p2
1011 | _ -> raise NotApplicable
1014 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts p1)
1015 @[K.Term (false,t2)]
1017 seed context metasenv ~ids_to_inner_types ~ids_to_inner_sorts p2)
1019 (acic2content seed context metasenv ~ids_to_inner_sorts ~ids_to_inner_types t)]
1025 seed ~ids_to_inner_sorts ~ids_to_inner_types (id,n,context,ty)
1027 let module K = Content in
1032 | (id,Some (name,Cic.ADecl t)) ->
1034 (* We should call build_decl_item, but we have not computed *)
1035 (* the inner-types ==> we always produce a declaration *)
1037 { K.dec_name = name_of name;
1038 K.dec_id = gen_id declaration_prefix seed;
1039 K.dec_inductive = false;
1040 K.dec_aref = get_id t;
1043 | (id,Some (name,Cic.ADef t)) ->
1045 (* We should call build_def_item, but we have not computed *)
1046 (* the inner-types ==> we always produce a declaration *)
1048 { K.def_name = name_of name;
1049 K.def_id = gen_id definition_prefix seed;
1050 K.def_aref = get_id t;
1058 (* map_sequent is similar to map_conjectures, but the for the hid
1059 of the hypothesis, which are preserved instead of generating
1060 fresh ones. We shall have to adopt a uniform policy, soon or later *)
1062 let map_sequent ((id,n,context,ty):Cic.annconjecture) =
1063 let module K = Content in
1068 | (id,Some (name,Cic.ADecl t)) ->
1070 (* We should call build_decl_item, but we have not computed *)
1071 (* the inner-types ==> we always produce a declaration *)
1073 { K.dec_name = name_of name;
1075 K.dec_inductive = false;
1076 K.dec_aref = get_id t;
1079 | (id,Some (name,Cic.ADef t)) ->
1081 (* We should call build_def_item, but we have not computed *)
1082 (* the inner-types ==> we always produce a declaration *)
1084 { K.def_name = name_of name;
1086 K.def_aref = get_id t;
1094 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
1095 let module C = Cic in
1096 let module K = Content in
1097 let module C2A = Cic2acic in
1100 C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
1101 (gen_id object_prefix seed, params,
1104 (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
1108 seed [] (Deannotate.deannotate_conjectures conjectures)
1109 (get_id bo) (C.Name n) bo
1110 ~ids_to_inner_sorts ~ids_to_inner_types))
1111 | C.AConstant (_,_,n,Some bo,ty,params,_) ->
1112 (gen_id object_prefix seed, params, None,
1114 build_def_item seed [] [] (get_id bo) (C.Name n) bo
1115 ~ids_to_inner_sorts ~ids_to_inner_types))
1116 | C.AConstant (id,_,n,None,ty,params,_) ->
1117 (gen_id object_prefix seed, params, None,
1119 build_decl_item seed id (C.Name n) ty
1120 ~ids_to_inner_sorts))
1121 | C.AVariable (_,n,Some bo,ty,params,_) ->
1122 (gen_id object_prefix seed, params, None,
1124 build_def_item seed [] [] (get_id bo) (C.Name n) bo
1125 ~ids_to_inner_sorts ~ids_to_inner_types))
1126 | C.AVariable (id,n,None,ty,params,_) ->
1127 (gen_id object_prefix seed, params, None,
1129 build_decl_item seed id (C.Name n) ty
1130 ~ids_to_inner_sorts))
1131 | C.AInductiveDefinition (id,l,params,nparams,_) ->
1132 (gen_id object_prefix seed, params, None,
1134 { K.joint_id = gen_id joint_prefix seed;
1135 K.joint_kind = `Inductive nparams;
1136 K.joint_defs = List.map (build_inductive seed) l
1140 build_inductive seed =
1141 let module K = Content in
1144 { K.inductive_id = gen_id inductive_prefix seed;
1145 K.inductive_name = n;
1146 K.inductive_kind = b;
1147 K.inductive_type = ty;
1148 K.inductive_constructors = build_constructors seed l
1152 build_constructors seed l =
1153 let module K = Content in
1156 { K.dec_name = Some n;
1157 K.dec_id = gen_id declaration_prefix seed;
1158 K.dec_inductive = false;
1165 and 'term cinductiveType =
1166 id * string * bool * 'term * (* typename, inductive, arity *)
1167 'term cconstructor list (* constructors *)
1169 and 'term cconstructor =