]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_omdoc/cic2content.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / cic_omdoc / cic2content.ml
index 149fd90ec4389dfb47015cbb16dc2803e976fcf3..72699f7e3cb2b584da6617a278a1b1f611945abd 100644 (file)
 (*                           PROJECT HELM                                 *)
 (*                                                                        *)
 (*                Andrea Asperti <asperti@cs.unibo.it>                    *)
-(*                             16/62003                                   *)
+(*                             16/6/2003                                   *)
 (*                                                                        *)
 (**************************************************************************)
 
+let object_prefix = "obj:";;
+let declaration_prefix = "decl:";;
+let definition_prefix = "def:";;
+let inductive_prefix = "ind:";;
+let joint_prefix = "joint:";;
+let proof_prefix = "proof:";;
+let conclude_prefix = "concl:";;
+let premise_prefix = "prem:";;
+let lemma_prefix = "lemma:";;
+
 (* e se mettessi la conversione di BY nell'apply_context ? *)
 (* sarebbe carino avere l'invariante che la proof2pres
 generasse sempre prove con contesto vuoto *)
  
-let gen_id seed =
- let res = "p" ^ string_of_int !seed in
+let gen_id prefix seed =
+ let res = prefix ^ string_of_int !seed in
   incr seed ;
   res
 ;;
@@ -60,7 +70,7 @@ let rec occur uri =
     | C.Var _ -> false
     | C.Meta _ -> false
     | C.Sort _ -> false
-    | C.Implicit -> raise NotImplemented
+    | C.Implicit _ -> assert false
     | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
     | C.Cast (te,ty) -> (occur uri te)
     | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
@@ -99,14 +109,21 @@ let get_id =
     | C.ACoFix (id,_,_) -> id
 ;;
 
-let test_for_lifting ~ids_to_inner_types = 
+let test_for_lifting ~ids_to_inner_types ~ids_to_inner_sorts
   let module C = Cic in
   let module C2A = Cic2acic in
   (* atomic terms are never lifted, according to my policy *)
   function
       C.ARel (id,_,_,_) -> false
-    | C.AVar (id,_,_) -> false
-    | C.AMeta (id,_,_) -> false
+    | C.AVar (id,_,_) -> 
+         (try 
+            ignore (Hashtbl.find ids_to_inner_types id).C2A.annsynthesized;
+            true;
+          with Not_found -> false) 
+    | C.AMeta (id,_,_) -> 
+         (try 
+            Hashtbl.find ids_to_inner_sorts id = `Prop
+          with Not_found -> assert false)
     | C.ASort (id,_) -> false
     | C.AImplicit _ -> raise NotImplemented
     | C.AProd (id,_,_,_) -> false
@@ -159,45 +176,6 @@ let test_for_lifting ~ids_to_inner_types =
           with Not_found -> false)
 ;;
 
-let build_args seed l subproofs ~ids_to_inner_types ~ids_to_inner_sorts =
-  let module C = Cic in
-  let module K = Content in
-  let rec aux l subrpoofs =
-    match l with
-      [] -> []
-    | t::l1 -> 
-        if (test_for_lifting t ~ids_to_inner_types) then
-          (match subproofs with
-             [] -> assert false
-           | p::tl -> 
-              let new_arg = 
-                K.Premise
-                  { K.premise_id = gen_id seed;
-                    K.premise_xref = p.K.proof_id;
-                    K.premise_binder = p.K.proof_name;
-                    K.premise_n = None
-                  }
-                in new_arg::(aux l1 tl))
-        else 
-          let hd = 
-            (match t with 
-               C.ARel (idr,idref,n,b) ->
-                 let sort = 
-                   (try Hashtbl.find ids_to_inner_sorts idr 
-                    with Not_found -> "Type") in 
-                 if sort ="Prop" then 
-                    K.Premise 
-                      { K.premise_id = gen_id seed;
-                        K.premise_xref = idr;
-                        K.premise_binder = Some b;
-                        K.premise_n = Some n
-                      }
-                 else (K.Term t)
-             | _ -> (K.Term t)) in 
-          hd::(aux l1 subproofs)
-  in aux l subproofs
-;;
-
 (* transform a proof p into a proof list, concatenating the last 
 conclude element to the apply_context list, in case context is
 empty. Otherwise, it just returns [p] *)
@@ -219,8 +197,9 @@ let flat seed p =
 
 let rec serialize seed = 
   function 
-      [] -> []
-    | p::tl -> (flat seed p)@(serialize seed tl);;
+    [] -> []
+  | a::l -> (flat seed a)@(serialize seed l) 
+;;
 
 (* top_down = true if the term is a LAMBDA or a decl *)
 let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
@@ -233,30 +212,31 @@ let generate_conversion seed top_down id inner_proof ~ids_to_inner_types =
      None -> inner_proof
    | Some expty ->
        if inner_proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
-         { K.proof_name = None ;
-            K.proof_id   = gen_id seed;
+         { K.proof_name = inner_proof.K.proof_name;
+            K.proof_id   = gen_id proof_prefix seed;
             K.proof_context = [] ;
             K.proof_apply_context = [];
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
                 K.conclude_method = "TD_Conversion";
-                K.conclude_args = [K.ArgProof inner_proof];
+                K.conclude_args = 
+                  [K.ArgProof {inner_proof with K.proof_name = None}];
                 K.conclude_conclusion = Some expty
               };
           }
         else
-          { K.proof_name = None ;
-            K.proof_id   = gen_id seed;
+          { K.proof_name =  inner_proof.K.proof_name;
+            K.proof_id   = gen_id proof_prefix seed;
             K.proof_context = [] ;
-            K.proof_apply_context = [inner_proof];
+            K.proof_apply_context = [{inner_proof with K.proof_name = None}];
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
                 K.conclude_method = "BU_Conversion";
                 K.conclude_args =  
                  [K.Premise 
-                  { K.premise_id = gen_id seed;
+                  { K.premise_id = gen_id premise_prefix seed;
                     K.premise_xref = inner_proof.K.proof_id; 
                     K.premise_binder = None;
                     K.premise_n = None
@@ -271,11 +251,11 @@ let generate_exact seed t id name ~ids_to_inner_types =
   let module C2A = Cic2acic in
   let module K = Content in
     { K.proof_name = name;
-      K.proof_id   = id ;
+      K.proof_id   = gen_id proof_prefix seed ;
       K.proof_context = [] ;
       K.proof_apply_context = [];
       K.proof_conclude = 
-        { K.conclude_id = gen_id seed; 
+        { K.conclude_id = gen_id conclude_prefix seed; 
           K.conclude_aref = id;
           K.conclude_method = "Exact";
           K.conclude_args = [K.Term t];
@@ -291,11 +271,11 @@ let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_
   let module C = Cic in
   let module K = Content in
     { K.proof_name = name;
-      K.proof_id   = id ;
+      K.proof_id  = gen_id proof_prefix seed ;
       K.proof_context = [] ;
       K.proof_apply_context = [];
       K.proof_conclude = 
-        { K.conclude_id = gen_id seed; 
+        { K.conclude_id = gen_id conclude_prefix seed; 
           K.conclude_aref = id;
           K.conclude_method = "Intros+LetTac";
           K.conclude_args = [K.ArgProof inner_proof];
@@ -314,38 +294,132 @@ let generate_intros_let_tac seed id n s is_intro inner_proof name ~ids_to_inner_
 
 let build_decl_item seed id n s ~ids_to_inner_sorts =
  let module K = Content in
-  try
-   let sort = Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id) in
-   if sort = "Prop" then
-      `Hypothesis
-        { K.dec_name = name_of n;
-          K.dec_id = gen_id seed; 
-          K.dec_inductive = false;
-          K.dec_aref = id;
-          K.dec_type = s
-        }
-   else 
-      `Declaration
-        { K.dec_name = name_of n;
-          K.dec_id = gen_id seed; 
-          K.dec_inductive = false;
-          K.dec_aref = id;
-          K.dec_type = s
-        }
-  with
-   Not_found -> assert false
+ let sort =
+   try
+    Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
+   with Not_found -> None
+ in
+ match sort with
+ | Some `Prop ->
+    `Hypothesis
+      { K.dec_name = name_of n;
+        K.dec_id = gen_id declaration_prefix seed; 
+        K.dec_inductive = false;
+        K.dec_aref = id;
+        K.dec_type = s
+      }
+ | _ ->
+    `Declaration
+      { K.dec_name = name_of n;
+        K.dec_id = gen_id declaration_prefix seed; 
+        K.dec_inductive = false;
+        K.dec_aref = id;
+        K.dec_type = s
+      }
 ;;
 
-let rec build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
+let rec build_subproofs_and_args seed l ~ids_to_inner_types ~ids_to_inner_sorts =
+  let module C = Cic in
+  let module K = Content in
+  let rec aux =
+    function
+      [] -> [],[]
+    | t::l1 -> 
+       let subproofs,args = aux l1 in
+        if (test_for_lifting t ~ids_to_inner_types ~ids_to_inner_sorts) then
+          let new_subproof = 
+            acic2content 
+              seed ~name:"H" ~ids_to_inner_types ~ids_to_inner_sorts t in
+          let new_arg = 
+            K.Premise
+              { K.premise_id = gen_id premise_prefix seed;
+                K.premise_xref = new_subproof.K.proof_id;
+                K.premise_binder = new_subproof.K.proof_name;
+                K.premise_n = None
+              } in
+          new_subproof::subproofs,new_arg::args
+        else 
+          let hd = 
+            (match t with 
+               C.ARel (idr,idref,n,b) ->
+                 let sort = 
+                   (try
+                     Hashtbl.find ids_to_inner_sorts idr 
+                    with Not_found -> `Type (CicUniv.fresh())) in 
+                 if sort = `Prop then 
+                    K.Premise 
+                      { K.premise_id = gen_id premise_prefix seed;
+                        K.premise_xref = idr;
+                        K.premise_binder = Some b;
+                        K.premise_n = Some n
+                      }
+                 else (K.Term t)
+             | C.AConst(id,uri,[]) ->
+                 let sort = 
+                   (try
+                     Hashtbl.find ids_to_inner_sorts id 
+                    with Not_found -> `Type (CicUniv.fresh())) in 
+                 if sort = `Prop then 
+                    K.Lemma 
+                      { K.lemma_id = gen_id lemma_prefix seed;
+                        K.lemma_name = UriManager.name_of_uri uri;
+                        K.lemma_uri = UriManager.string_of_uri uri
+                      }
+                 else (K.Term t)
+             | C.AMutConstruct(id,uri,tyno,consno,[]) ->
+                 let sort = 
+                   (try
+                     Hashtbl.find ids_to_inner_sorts id 
+                    with Not_found -> `Type (CicUniv.fresh())) in 
+                 if sort = `Prop then 
+                    let inductive_types =
+                      (let o,_ = 
+                        CicEnvironment.get_obj CicUniv.empty_ugraph uri
+                      in
+                        match o with 
+                          | Cic.InductiveDefinition (l,_,_,_) -> l 
+                           | _ -> assert false
+                      ) in
+                    let (_,_,_,constructors) = 
+                      List.nth inductive_types tyno in 
+                    let name,_ = List.nth constructors (consno - 1) in
+                    K.Lemma 
+                      { K.lemma_id = gen_id lemma_prefix seed;
+                        K.lemma_name = name;
+                        K.lemma_uri = 
+                          UriManager.string_of_uri uri ^ "#xpointer(1/" ^
+                          string_of_int (tyno+1) ^ "/" ^ string_of_int consno ^
+                          ")"
+                      }
+                 else (K.Term t) 
+             | _ -> (K.Term t)) in
+          subproofs,hd::args
+  in 
+  match (aux l) with
+    [p],args -> 
+      [{p with K.proof_name = None}], 
+        List.map 
+         (function 
+             K.Premise prem when prem.K.premise_xref = p.K.proof_id ->
+               K.Premise {prem with K.premise_binder = None}
+            | i -> i) args
+  | p,a as c -> c
+
+and
+
+build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
  let module K = Content in
   try
    let sort = Hashtbl.find ids_to_inner_sorts id in
-   if sort = "Prop" then
-      `Proof (acic2content seed ?name:(name_of n) ~ids_to_inner_sorts  ~ids_to_inner_types t)
+   if sort = `Prop then
+       (let p = 
+        (acic2content seed ?name:(name_of n) ~ids_to_inner_sorts  ~ids_to_inner_types t)
+       in 
+        `Proof p;)
    else 
       `Definition
         { K.def_name = name_of n;
-          K.def_id = gen_id seed; 
+          K.def_id = gen_id definition_prefix seed; 
           K.def_aref = id;
           K.def_term = t
         }
@@ -365,17 +439,17 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
     match t with 
       C.ARel (id,idref,n,b) as t ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then
+        if sort = `Prop then
           generate_exact seed t id name ~ids_to_inner_types 
         else raise Not_a_proof
     | C.AVar (id,uri,exp_named_subst) as t ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then
+        if sort = `Prop then
           generate_exact seed t id name ~ids_to_inner_types 
         else raise Not_a_proof
     | C.AMeta (id,n,l) as t ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then
+        if sort = `Prop then
           generate_exact seed t id name ~ids_to_inner_types 
         else raise Not_a_proof
     | C.ASort (id,s) -> raise Not_a_proof
@@ -384,7 +458,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
     | C.ACast (id,v,t) -> aux v
     | C.ALambda (id,n,s,t) -> 
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then 
+        if sort = `Prop then 
           let proof = aux t in
           let proof' = 
             if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
@@ -404,7 +478,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
         else raise Not_a_proof 
     | C.ALetIn (id,n,s,t) ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then 
+        if sort = `Prop then
           let proof = aux t in
           let proof' = 
             if proof.K.proof_conclude.K.conclude_method = "Intros+LetTac" then
@@ -414,7 +488,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
             else proof in
           let proof'' =
             { proof' with
-               K.proof_name = name;
+               K.proof_name = None;
                K.proof_context = 
                  ((build_def_item seed id n s ids_to_inner_sorts 
                    ids_to_inner_types):> Cic.annterm K.in_proof_context_element)
@@ -425,11 +499,15 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
         else raise Not_a_proof 
     | C.AAppl (id,li) ->
         (try rewrite 
-           seed name id li ids_to_inner_types ids_to_inner_sorts
+           seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
          with NotApplicable ->
          try inductive 
-          seed name id li ids_to_inner_types ids_to_inner_sorts
+          seed name id li ~ids_to_inner_types ~ids_to_inner_sorts
          with NotApplicable ->
+          let subproofs, args =
+            build_subproofs_and_args 
+              seed li ~ids_to_inner_types ~ids_to_inner_sorts in
+(*            
           let args_to_lift = 
             List.filter (test_for_lifting ~ids_to_inner_types) li in
           let subproofs = 
@@ -437,13 +515,13 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
                 [_] -> List.map aux args_to_lift 
             | _ -> List.map (aux ~name:"H") args_to_lift in
           let args = build_args seed li subproofs 
-                 ~ids_to_inner_types ~ids_to_inner_sorts in
+                 ~ids_to_inner_types ~ids_to_inner_sorts in *)
             { K.proof_name = name;
-              K.proof_id   = gen_id seed;
+              K.proof_id   = gen_id proof_prefix seed;
               K.proof_context = [];
               K.proof_apply_context = serialize seed subproofs;
               K.proof_conclude = 
-                { K.conclude_id = gen_id seed;
+                { K.conclude_id = gen_id conclude_prefix seed;
                   K.conclude_aref = id;
                   K.conclude_method = "Apply";
                   K.conclude_args = args;
@@ -455,49 +533,61 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
             })
     | C.AConst (id,uri,exp_named_subst) as t ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then
+        if sort = `Prop then
           generate_exact seed t id name ~ids_to_inner_types
         else raise Not_a_proof
     | C.AMutInd (id,uri,i,exp_named_subst) -> raise Not_a_proof
     | C.AMutConstruct (id,uri,i,j,exp_named_subst) as t ->
         let sort = Hashtbl.find ids_to_inner_sorts id in
-        if sort = "Prop" then 
+        if sort = `Prop then 
           generate_exact seed t id name ~ids_to_inner_types
         else raise Not_a_proof
     | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
-        let inductive_types =
-           (match CicEnvironment.get_obj uri with
-               Cic.Constant _ -> assert false
-             | Cic.Variable _ -> assert false
-             | Cic.CurrentProof _ -> assert false
-             | Cic.InductiveDefinition (l,_,_) -> l 
-           ) in
-        let (_,_,_,constructors) = List.nth inductive_types typeno in 
+        let inductive_types,noparams =
+          (let o, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+            match o with
+                Cic.Constant _ -> assert false
+               | Cic.Variable _ -> assert false
+               | Cic.CurrentProof _ -> assert false
+               | Cic.InductiveDefinition (l,_,n,_) -> l,n 
+          ) in
+        let (_,_,_,constructors) = List.nth inductive_types typeno in
+        let name_and_arities = 
+          let rec count_prods =
+            function 
+               C.Prod (_,_,t) -> 1 + count_prods t
+             | _ -> 0 in
+          List.map 
+            (function (n,t) -> Some n,((count_prods t) - noparams)) constructors in
+        let pp = 
+          let build_proof p (name,arity) =
+            let rec make_context_and_body c p n =
+              if n = 0 then c,(aux p)
+              else 
+                (match p with
+                   Cic.ALambda(idl,vname,s1,t1) ->
+                     let ce = 
+                       build_decl_item seed idl vname s1 ~ids_to_inner_sorts in
+                     make_context_and_body (ce::c) t1 (n-1)
+                   | _ -> assert false) in
+             let context,body = make_context_and_body [] p arity in
+               K.ArgProof
+                {body with K.proof_name = name; K.proof_context=context} in
+          List.map2 build_proof patterns name_and_arities in
         let teid = get_id te in
-        let pp = List.map2 
-          (fun p (name,_) -> (K.ArgProof (aux ~name p))) 
-           patterns constructors in
-        let apply_context,term =
+        let context,term =
           (match 
-            (try Some (Hashtbl.find ids_to_inner_types teid).C2A.annsynthesized
-             with Not_found -> None)
+             build_subproofs_and_args 
+               seed ~ids_to_inner_types ~ids_to_inner_sorts [te]
            with
-             Some tety -> 
-               let p = (aux te) in
-               (flat seed p, 
-                K.Premise
-                { K.premise_id = gen_id seed; 
-                   K.premise_xref = p.K.proof_id;
-                   K.premise_binder = p.K.proof_name;
-                   K.premise_n = None
-                 })
-           | None -> [],K.Term te) in
+             l,[t] -> l,t
+           | _ -> assert false) in
         { K.proof_name = name;
-          K.proof_id   = gen_id seed;
+          K.proof_id   = gen_id proof_prefix seed;
           K.proof_context = []; 
-          K.proof_apply_context = apply_context;
+          K.proof_apply_context = serialize seed context;
           K.proof_conclude = 
-            { K.conclude_id = gen_id seed; 
+            { K.conclude_id = gen_id conclude_prefix seed; 
               K.conclude_aref = id;
               K.conclude_method = "Case";
               K.conclude_args = 
@@ -513,27 +603,30 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
         let proofs = 
           List.map 
             (function (_,name,_,_,bo) -> `Proof (aux ~name bo)) funs in
+        let fun_name = 
+          List.nth (List.map (fun (_,name,_,_,_) -> name) funs) no 
+        in
         let decreasing_args = 
           List.map (function (_,_,n,_,_) -> n) funs in
         let jo = 
-          { K.joint_id = gen_id seed;
+          { K.joint_id = gen_id joint_prefix seed;
             K.joint_kind = `Recursive decreasing_args;
             K.joint_defs = proofs
           } 
         in
           { K.proof_name = name;
-            K.proof_id   = gen_id seed;
+            K.proof_id  = gen_id proof_prefix seed;
             K.proof_context = [`Joint jo]; 
             K.proof_apply_context = [];
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
                 K.conclude_method = "Exact";
                 K.conclude_args =
                 [ K.Premise
-                  { K.premise_id = gen_id seed; 
+                  { K.premise_id = gen_id premise_prefix seed; 
                     K.premise_xref = jo.K.joint_id;
-                    K.premise_binder = Some "tiralo fuori";
+                    K.premise_binder = Some fun_name;
                     K.premise_n = Some no;
                   }
                 ];
@@ -548,22 +641,22 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
           List.map 
             (function (_,name,_,bo) -> `Proof (aux ~name bo)) funs in
         let jo = 
-          { K.joint_id = gen_id seed;
+          { K.joint_id = gen_id joint_prefix seed;
             K.joint_kind = `CoRecursive;
             K.joint_defs = proofs
           } 
         in
           { K.proof_name = name;
-            K.proof_id   = gen_id seed;
+            K.proof_id   = gen_id proof_prefix seed;
             K.proof_context = [`Joint jo]; 
             K.proof_apply_context = [];
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
                 K.conclude_method = "Exact";
                 K.conclude_args =
                 [ K.Premise
-                  { K.premise_id = gen_id seed; 
+                  { K.premise_id = gen_id premise_prefix seed; 
                     K.premise_xref = jo.K.joint_id;
                     K.premise_binder = Some "tiralo fuori";
                     K.premise_n = Some no;
@@ -580,7 +673,7 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
      generate_conversion seed false id t1 ~ids_to_inner_types
 in aux ?name t
 
-and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
+and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
   let aux ?name = acic2content seed  ~ids_to_inner_types ~ids_to_inner_sorts in
   let module C2A = Cic2acic in
   let module K = Content in
@@ -594,21 +687,25 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
                with Not_found -> -1) in
       if n<0 then raise NotApplicable
       else 
+        let method_name =
+          if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
+          else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
+          else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
+          else "ByInduction" in
         let prefix = String.sub uri_str 0 n in
         let ind_str = (prefix ^ ".ind") in 
         let ind_uri = UriManager.uri_of_string ind_str in
         let inductive_types,noparams =
-           (match CicEnvironment.get_obj ind_uri with
-               Cic.Constant _ -> assert false
-             | Cic.Variable _ -> assert false
-             | Cic.CurrentProof _ -> assert false
-             | Cic.InductiveDefinition (l,_,n) -> (l,n) 
-           ) in
+          (let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph ind_uri in
+            match o with
+               | Cic.InductiveDefinition (l,_,n,_) -> (l,n) 
+               | _ -> assert false
+          ) in
         let rec split n l =
           if n = 0 then ([],l) else
           let p,a = split (n-1) (List.tl l) in
           ((List.hd l::p),a) in
-        let params_and_IP,tail_args = split (noparams+1) args in 
+        let params_and_IP,tail_args = split (noparams+1) args in
         let constructors = 
             (match inductive_types with
               [(_,_,_,l)] -> l
@@ -623,26 +720,9 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
         let no_constructors= List.length constructors in
         let args_for_cases, other_args = 
           split no_constructors tail_args in
-        let args_to_lift = 
-          List.filter (test_for_lifting ~ids_to_inner_types) other_args in
-        let subproofs = 
-          match args_to_lift with
-            [_] -> List.map aux args_to_lift 
-          | _ -> List.map (aux ~name:"H") args_to_lift in
-        prerr_endline "****** end subproofs *******"; flush stderr;
-        let other_method_args = 
-          build_args seed other_args subproofs 
+        let subproofs,other_method_args =
+          build_subproofs_and_args seed other_args
              ~ids_to_inner_types ~ids_to_inner_sorts in
-(*
-        let rparams,inductive_arg =
-          let rec aux =
-            function 
-              [] -> assert false            
-            | [ia] -> [],ia
-            | a::tl -> let (p,ia) = aux tl in (a::p,ia) in
-          aux other_method_args in 
-*)
-        prerr_endline "****** end other *******"; flush stderr;
         let method_args=
           let rec build_method_args =
             function
@@ -651,9 +731,9 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
                   let idarg = get_id arg in
                   let sortarg = 
                     (try (Hashtbl.find ids_to_inner_sorts idarg)
-                     with Not_found -> "Type") in
+                     with Not_found -> `Type (CicUniv.fresh())) in
                   let hdarg = 
-                    if sortarg = "Prop" then
+                    if sortarg = `Prop then
                       let (co,bo) = 
                         let rec bc = 
                           function 
@@ -662,13 +742,13 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
                                 build_decl_item 
                                   seed idl n s1 ~ids_to_inner_sorts in
                               if (occur ind_uri s) then
-                                (  prerr_endline ("inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr; 
-                                   match t1 with
+                                ( match t1 with
                                    Cic.ALambda(id2,n2,s2,t2) ->
                                      let inductive_hyp =
                                        `Hypothesis
                                          { K.dec_name = name_of n2;
-                                           K.dec_id = gen_id seed; 
+                                           K.dec_id =
+                                            gen_id declaration_prefix seed; 
                                            K.dec_inductive = true;
                                            K.dec_aref = id2;
                                            K.dec_type = s2
@@ -677,7 +757,7 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
                                      (ce::inductive_hyp::context,body)
                                  | _ -> assert false)
                               else 
-                                (  prerr_endline ("no inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr; 
+                                ( 
                                 let (context,body) = bc (t,t1) in
                                 (ce::context,body))
                             | _ , t -> ([],aux t) in
@@ -691,17 +771,17 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
                   hdarg::(build_method_args (tlc,tla))
               | _ -> assert false in
           build_method_args (constructors1,args_for_cases) in
-          { K.proof_name = None;
-            K.proof_id   = gen_id seed;
+          { K.proof_name = name;
+            K.proof_id   = gen_id proof_prefix seed;
             K.proof_context = []; 
-            K.proof_apply_context = subproofs;
+            K.proof_apply_context = serialize seed subproofs;
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
-                K.conclude_method = "ByInduction";
+                K.conclude_method = method_name;
                 K.conclude_args =
                   K.Aux (string_of_int no_constructors) 
-                  ::K.Term (C.AAppl id ((C.AConst(idc,uri,exp_named_subst))::params_and_IP))
+                  ::K.Term (C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))
                   ::method_args@other_method_args;
                 K.conclude_conclusion = 
                    try Some 
@@ -711,44 +791,43 @@ and inductive seed name id li ids_to_inner_types ids_to_inner_sorts =
           } 
   | _ -> raise NotApplicable
 
-and rewrite seed name id li ids_to_inner_types ids_to_inner_sorts =
+and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
   let aux ?name = acic2content seed ~ids_to_inner_types ~ids_to_inner_sorts in
   let module C2A = Cic2acic in
   let module K = Content in
   let module C = Cic in
   match li with 
     C.AConst (sid,uri,exp_named_subst)::args ->
-      let uri_str = UriManager.string_of_uri uri in
-      if uri_str = "cic:/Coq/Init/Logic/eq_ind.con" or
-         uri_str = "cic:/Coq/Init/Logic/eq_ind_r.con" then 
-        let subproof = aux (List.nth args 3) in
+      if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
+         UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI then 
+        let subproofs,arg = 
+          (match 
+             build_subproofs_and_args 
+               seed ~ids_to_inner_types ~ids_to_inner_sorts [List.nth args 3]
+           with 
+             l,[p] -> l,p
+           | _,_ -> assert false) in 
         let method_args =
           let rec ma_aux n = function
               [] -> []
             | a::tl -> 
                 let hd = 
-                  if n = 0 then
-                    K.Premise
-                     { K.premise_id = gen_id seed;
-                       K.premise_xref = subproof.K.proof_id;
-                       K.premise_binder = None;
-                       K.premise_n = None
-                     }
+                  if n = 0 then arg
                   else 
                     let aid = get_id a in
                     let asort = (try (Hashtbl.find ids_to_inner_sorts aid)
-                      with Not_found -> "Type") in
-                    if asort = "Prop" then
+                      with Not_found -> `Type (CicUniv.fresh())) in
+                    if asort = `Prop then
                       K.ArgProof (aux a)
                     else K.Term a in
                 hd::(ma_aux (n-1) tl) in
           (ma_aux 3 args) in 
-          { K.proof_name = None;
-            K.proof_id   = gen_id seed;
+          { K.proof_name = name;
+            K.proof_id  = gen_id proof_prefix seed;
             K.proof_context = []; 
-            K.proof_apply_context = [subproof];
+            K.proof_apply_context = serialize seed subproofs;
             K.proof_conclude = 
-              { K.conclude_id = gen_id seed; 
+              { K.conclude_id = gen_id conclude_prefix seed; 
                 K.conclude_aref = id;
                 K.conclude_method = "Rewrite";
                 K.conclude_args = 
@@ -770,30 +849,64 @@ let map_conjectures
  let context' =
   List.map
    (function
-       (id,None) as item -> item
+       (id,None) -> None
      | (id,Some (name,Cic.ADecl t)) ->
-         id,
-          Some
-           (* We should call build_decl_item, but we have not computed *)
-           (* the inner-types ==> we always produce a declaration      *)
-           (`Declaration
-             { K.dec_name = name_of name;
-               K.dec_id = gen_id seed; 
-               K.dec_inductive = false;
-               K.dec_aref = get_id t;
-               K.dec_type = t
+         Some
+          (* We should call build_decl_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration      *)
+          (`Declaration
+            { K.dec_name = name_of name;
+              K.dec_id = gen_id declaration_prefix seed; 
+              K.dec_inductive = false;
+              K.dec_aref = get_id t;
+              K.dec_type = t
+            })
+     | (id,Some (name,Cic.ADef t)) ->
+         Some
+          (* We should call build_def_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration     *)
+          (`Definition
+             { K.def_name = name_of name;
+               K.def_id = gen_id definition_prefix seed; 
+               K.def_aref = get_id t;
+               K.def_term = t
              })
+   ) context
+ in
+  (id,n,context',ty)
+;;
+
+(* map_sequent is similar to map_conjectures, but the for the hid
+of the hypothesis, which are preserved instead of generating
+fresh ones. We shall have to adopt a uniform policy, soon or later *)
+
+let map_sequent ((id,n,context,ty):Cic.annconjecture) =
+ let module K = Content in
+ let context' =
+  List.map
+   (function
+       (id,None) -> None
+     | (id,Some (name,Cic.ADecl t)) ->
+         Some
+          (* We should call build_decl_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration      *)
+          (`Declaration
+            { K.dec_name = name_of name;
+              K.dec_id = id; 
+              K.dec_inductive = false;
+              K.dec_aref = get_id t;
+              K.dec_type = t
+            })
      | (id,Some (name,Cic.ADef t)) ->
-         id,
-          Some
-           (* We should call build_def_item, but we have not computed *)
-           (* the inner-types ==> we always produce a declaration     *)
-           (`Definition
-              { K.def_name = name_of name;
-                K.def_id = gen_id seed; 
-                K.def_aref = get_id t;
-                K.def_term = t
-              })
+         Some
+          (* We should call build_def_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration     *)
+          (`Definition
+             { K.def_name = name_of name;
+               K.def_id = id; 
+               K.def_aref = get_id t;
+               K.def_term = t
+             })
    ) context
  in
   (id,n,context',ty)
@@ -805,8 +918,8 @@ let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
   let module C2A = Cic2acic in
   let seed = ref 0 in
   function
-      C.ACurrentProof (_,_,n,conjectures,bo,ty,params) ->
-        (gen_id seed, params,
+      C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
+        (gen_id object_prefix seed, params,
           Some
            (List.map
              (map_conjectures seed ~ids_to_inner_sorts ~ids_to_inner_types)
@@ -814,30 +927,30 @@ let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
           `Def (K.Const,ty,
             build_def_item seed (get_id bo) (C.Name n) bo 
              ~ids_to_inner_sorts ~ids_to_inner_types))
-    | C.AConstant (_,_,n,Some bo,ty,params) ->
-         (gen_id seed, params, None,
+    | C.AConstant (_,_,n,Some bo,ty,params,_) ->
+         (gen_id object_prefix seed, params, None,
            `Def (K.Const,ty,
              build_def_item seed (get_id bo) (C.Name n) bo 
                ~ids_to_inner_sorts ~ids_to_inner_types))
-    | C.AConstant (id,_,n,None,ty,params) ->
-         (gen_id seed, params, None,
+    | C.AConstant (id,_,n,None,ty,params,_) ->
+         (gen_id object_prefix seed, params, None,
            `Decl (K.Const,
              build_decl_item seed id (C.Name n) ty 
                ~ids_to_inner_sorts))
-    | C.AVariable (_,n,Some bo,ty,params) ->
-         (gen_id seed, params, None,
+    | C.AVariable (_,n,Some bo,ty,params,_) ->
+         (gen_id object_prefix seed, params, None,
            `Def (K.Var,ty,
              build_def_item seed (get_id bo) (C.Name n) bo
                ~ids_to_inner_sorts ~ids_to_inner_types))
-    | C.AVariable (id,n,None,ty,params) ->
-         (gen_id seed, params, None,
+    | C.AVariable (id,n,None,ty,params,_) ->
+         (gen_id object_prefix seed, params, None,
            `Decl (K.Var,
              build_decl_item seed id (C.Name n) ty
               ~ids_to_inner_sorts))
-    | C.AInductiveDefinition (id,l,params,nparams) ->
-         (gen_id seed, params, None,
+    | C.AInductiveDefinition (id,l,params,nparams,_) ->
+         (gen_id object_prefix seed, params, None,
             `Joint
-              { K.joint_id = gen_id seed;
+              { K.joint_id = gen_id joint_prefix seed;
                 K.joint_kind = `Inductive nparams;
                 K.joint_defs = List.map (build_inductive seed) l
               }) 
@@ -847,7 +960,8 @@ and
      let module K = Content in
       fun (_,n,b,ty,l) ->
         `Inductive
-          { K.inductive_id = gen_id seed;
+          { K.inductive_id = gen_id inductive_prefix seed;
+            K.inductive_name = n;
             K.inductive_kind = b;
             K.inductive_type = ty;
             K.inductive_constructors = build_constructors seed l
@@ -859,7 +973,7 @@ and
       List.map 
        (fun (n,t) ->
            { K.dec_name = Some n;
-             K.dec_id = gen_id seed;
+             K.dec_id = gen_id declaration_prefix seed;
              K.dec_inductive = false;
              K.dec_aref = "";
              K.dec_type = t