(* PROJECT HELM *)
(* *)
(* Andrea Asperti <asperti@cs.unibo.it> *)
-(* 16/62003 *)
+(* 16/6/2003 *)
(* *)
(**************************************************************************)
| 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 ?? *)
with Not_found -> false)
| C.AMeta (id,_,_) ->
(try
- Hashtbl.find ids_to_inner_sorts id = "Prop"
+ Hashtbl.find ids_to_inner_sorts id = `Prop
with Not_found -> assert false)
| C.ASort (id,_) -> false
| C.AImplicit _ -> raise NotImplemented
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 declaration_prefix 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 declaration_prefix 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_subproofs_and_args seed l ~ids_to_inner_types ~ids_to_inner_sorts =
(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
+ (try
+ Hashtbl.find ids_to_inner_sorts idr
+ with Not_found -> `Type) in
+ if sort = `Prop then
K.Premise
{ K.premise_id = gen_id premise_prefix seed;
K.premise_xref = idr;
else (K.Term t)
| C.AConst(id,uri,[]) ->
let sort =
- (try Hashtbl.find ids_to_inner_sorts id
- with Not_found -> "Type") in
- if sort ="Prop" then
+ (try
+ Hashtbl.find ids_to_inner_sorts id
+ with Not_found -> `Type) in
+ if sort = `Prop then
K.Lemma
{ K.lemma_id = gen_id lemma_prefix seed;
K.lemma_name = UriManager.name_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") in
- if sort ="Prop" then
+ (try
+ Hashtbl.find ids_to_inner_sorts id
+ with Not_found -> `Type) in
+ if sort = `Prop then
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
+ (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 module K = Content in
try
let sort = Hashtbl.find ids_to_inner_sorts id in
- if sort = "Prop" then
+ if sort = `Prop then
(let p =
(acic2content seed ?name:(name_of n) ~ids_to_inner_sorts ~ids_to_inner_types t)
in
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
| 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
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
})
| 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 context,term =
(match
build_subproofs_and_args
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.Premise
{ 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;
}
];
if n<0 then raise NotApplicable
else
let method_name =
- if (uri_str = "cic:/Coq/Init/Logic_Type/exT_ind.con" or
- uri_str = "cic:/Coq/Init/Logic/ex_ind.con") then "Exists"
- else if uri_str = "cic:/Coq/Init/Logic/and_ind.con" then "AndInd"
- else if uri_str = "cic:/Coq/Init/Logic/False_ind.con" then "FalseInd"
+ 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
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) in
let hdarg =
- if sortarg = "Prop" then
+ if sortarg = `Prop then
let (co,bo) =
let rec bc =
function
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
+ 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
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) in
+ if asort = `Prop then
K.ArgProof (aux a)
else K.Term a in
hd::(ma_aux (n-1) tl) 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)) ->
+ 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)
+;;
+
let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types =
let module C = Cic in
let module K = Content in
let module C2A = Cic2acic in
let seed = ref 0 in
function
- C.ACurrentProof (_,_,n,conjectures,bo,ty,params) ->
+ C.ACurrentProof (_,_,n,conjectures,bo,ty,params,_) ->
(gen_id object_prefix seed, params,
Some
(List.map
`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) ->
+ | 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) ->
+ | 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) ->
+ | 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) ->
+ | 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) ->
+ | C.AInductiveDefinition (id,l,params,nparams,_) ->
(gen_id object_prefix seed, params, None,
`Joint
{ K.joint_id = gen_id joint_prefix seed;
fun (_,n,b,ty,l) ->
`Inductive
{ 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