let obj, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
match obj with
| Cic.Constant (_, _, _, uris, _) ->
- assert (List.length uris <= List.length termlist);
+ (* assert (List.length uris <= List.length termlist); *)
let rec aux = function
| [], tl -> [], tl
| (uri::uris), (term::tl) ->
;;
let canonical t context menv =
+ let remove_cycles t =
+ let is_transitive =
+ function
+ Cic.Appl (Cic.Const (uri_trans,_)::_)
+ when LibraryObjects.is_trans_eq_URI uri_trans ->
+ true
+ | _ -> false in
+ let rec collect =
+ function
+ Cic.Appl (Cic.Const (uri_trans,ens)::tl)
+ when LibraryObjects.is_trans_eq_URI uri_trans ->
+ let ty,l,m,r,p1,p2 = open_trans ens tl in
+ (if is_transitive p1 then fst (collect p1) else [l,p1]) @
+ (if is_transitive p2 then fst (collect p2) else [m,p2]),
+ (r, uri_trans, ty)
+ | t -> assert false in
+ let rec cut_to_last_duplicate l acc =
+ function
+ [] -> List.rev acc
+ | (l',p)::tl when l=l' ->
+if acc <> [] then
+prerr_endline ("!!! RISPARMIO " ^ string_of_int (List.length acc) ^ " PASSI");
+ cut_to_last_duplicate l [l',p] tl
+ | (l',p)::tl ->
+ cut_to_last_duplicate l ((l',p)::acc) tl
+ in
+ let rec rebuild =
+ function
+ (l,_)::_::_ as steps, ((r,uri_trans,ty) as last) ->
+ (match cut_to_last_duplicate l [] steps with
+ (l,p1)::((m,_)::_::_ as tl) ->
+ mk_trans uri_trans ty l m r p1 (rebuild (tl,last))
+ | [l,p1 ; m,p2] -> mk_trans uri_trans ty l m r p1 p2
+ | [l,p1] -> p1
+ | [] -> assert false)
+ | _ -> assert false
+ in
+ if is_transitive t then
+ rebuild (collect t)
+ else
+ t
+ in
let rec remove_refl t =
match t with
| Cic.Appl (((Cic.Const(uri_trans,ens))::tl) as args)
| Cic.Appl l -> Cic.Appl (List.map (canonical context) l)
| _ -> t
in
- remove_refl (canonical context t)
+ remove_cycles (remove_refl (canonical context t))
;;
let compose_contexts ctx1 ctx2 =
* ctx is a term with an hole. Cic.Implicit(Some `Hole) is the empty context
* ctx_ty is the type of ctx
*)
- let rec aux uri ty left right ctx_d ctx_ty = function
+ let rec aux uri ty left right ctx_d ctx_ty t =
+ match t with
| Cic.Appl ((Cic.Const(uri_sym,ens))::tl)
when LibraryObjects.is_sym_eq_URI uri_sym ->
let ty,l,r,p = open_sym ens tl in
let c_what = put_in_ctx ctx_c what in
(* now put the proofs in the compound context *)
let p1 = (* p1: dc_what = d_m *)
- if is_not_fixed_lp then
- aux uri ty2 c_what m ctx_d ctx_ty p1
+ if is_not_fixed_lp then
+ aux uri ty2 c_what m ctx_d ctx_ty p1
else
mk_sym uri_sym ctx_ty d_m dc_what
(aux uri ty2 m c_what ctx_d ctx_ty p1)
if avoid_eq_ind then
mk_sym uri_sym ctx_ty dc_what dc_other
(aux uri ty1 what other ctx_dc ctx_ty p2)
- else
+ else
aux uri ty1 other what ctx_dc ctx_ty p2
in
(* if pred = \x.C[x]=m --> t : C[other]=m --> trans other what m
p
;;
-let parametrize_proof p l r ty =
+let parametrize_proof menv p l r ty =
let uniq l = HExtlib.list_uniq (List.sort Pervasives.compare l) in
let mot = CicUtil.metas_of_term_set in
let parameters = uniq (mot p @ mot l @ mot r) in
match t1,t2 with Cic.Meta (i,_),Cic.Meta(j,_) -> i=j | _ -> false)
~what ~with_what ~where:p
in
+ let ty_of_m _ = Cic.Implicit (Some `Type)
+(*
+ let ty_of_m = function
+ | Cic.Meta (i,_) ->
+ (try
+ let _,_,ty = CicUtil.lookup_meta i menv in ty
+ with CicUtil.Meta_not_found _ ->
+ prerr_endline "eccoci";assert false)
+ | _ -> assert false
+*)
+ (*
let ty_of_m _ = ty (*function
| Cic.Meta (i,_) -> List.assoc i menv
| _ -> assert false *)
+ *)
in
let args, proof,_ =
List.fold_left
let p,l,r = proof_of_id bag id in
let cic = build_proof_term bag eq h n p in
let real_cic,instance =
- parametrize_proof cic l r (CicSubstitution.lift n mty)
+ parametrize_proof menv cic l r (CicSubstitution.lift n mty)
in
let h = (id, instance)::lift_list h in
acc@[id,real_cic],n+1,h)
let meta_convertibility_aux table t1 t2 =
let module C = Cic in
- let rec aux ((table_l, table_r) as table) t1 t2 =
+ let rec aux ((table_l,table_r) as table) t1 t2 =
match t1, t2 with
+ | C.Meta (m1, tl1), C.Meta (m2, tl2) when m1 = m2 -> table
+ | C.Meta (m1, tl1), C.Meta (m2, tl2) when m1 < m2 -> aux table t2 t1
| C.Meta (m1, tl1), C.Meta (m2, tl2) ->
- let tl1, tl2 = [],[] in
let m1_binding, table_l =
try List.assoc m1 table_l, table_l
with Not_found -> m2, (m1, m2)::table_l
in
if (m1_binding <> m2) || (m2_binding <> m1) then
raise NotMetaConvertible
- else (
- try
- List.fold_left2
- (fun res t1 t2 ->
- match t1, t2 with
- | None, Some _ | Some _, None -> raise NotMetaConvertible
- | None, None -> res
- | Some t1, Some t2 -> (aux res t1 t2))
- (table_l, table_r) tl1 tl2
- with Invalid_argument _ ->
- raise NotMetaConvertible
- )
+ else table_l,table_r
| C.Var (u1, ens1), C.Var (u2, ens2)
| C.Const (u1, ens1), C.Const (u2, ens2) when (UriManager.eq u1 u2) ->
aux_ens table ens1 ens2
true
else
try
- let table = meta_convertibility_aux ([], []) left left' in
+ let table = meta_convertibility_aux ([],[]) left left' in
let _ = meta_convertibility_aux table right right' in
true
with NotMetaConvertible ->
try
- let table = meta_convertibility_aux ([], []) left right' in
+ let table = meta_convertibility_aux ([],[]) left right' in
let _ = meta_convertibility_aux table right left' in
true
with NotMetaConvertible ->
true
else
try
- ignore(meta_convertibility_aux ([], []) t1 t2);
+ ignore(meta_convertibility_aux ([],[]) t1 t2);
true
with NotMetaConvertible ->
false
let is_weak_identity eq =
let _,_,(_,left, right,_),_,_ = open_equality eq in
- left = right || meta_convertibility left right
+ left = right
+ (* doing metaconv here is meaningless *)
;;
let is_identity (_, context, ugraph) eq =
let _,_,(ty,left,right,_),menv,_ = open_equality eq in
- left = right ||
- (* (meta_convertibility left right)) *)
- fst (CicReduction.are_convertible ~metasenv:menv context left right ugraph)
+ (* doing metaconv here is meaningless *)
+ left = right
+(* fst (CicReduction.are_convertible ~metasenv:menv context left right ugraph)
+ * *)
;;