1 (* cOpyright (C) 2005, 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 (* $Id: inference.ml 6245 2006-04-05 12:07:51Z tassi $ *)
28 type rule = SuperpositionRight | SuperpositionLeft | Demodulation
29 type uncomparable = int -> int
31 uncomparable * (* trick to break structural equality *)
34 (Cic.term * (* type *)
35 Cic.term * (* left side *)
36 Cic.term * (* right side *)
37 Utils.comparison) * (* ordering *)
38 Cic.metasenv * (* environment for metas *)
42 | Step of Subst.substitution * (rule * int*(Utils.pos*int)* Cic.term)
43 (* subst, (rule,eq1, eq2,predicate) *)
44 and goal_proof = (Utils.pos * int * Subst.substitution * Cic.term) list
49 let id_to_eq = Hashtbl.create 1024;;
57 Hashtbl.clear id_to_eq
60 let uncomparable = fun _ -> 0
62 let mk_equality (weight,p,(ty,l,r,o),m) =
63 let id = freshid () in
64 let eq = (uncomparable,weight,p,(ty,l,r,o),m,id) in
65 Hashtbl.add id_to_eq id eq;
69 let mk_tmp_equality (weight,(ty,l,r,o),m) =
71 uncomparable,weight,Exact (Cic.Implicit None),(ty,l,r,o),m,id
75 let open_equality (_,weight,proof,(ty,l,r,o),m,id) =
76 (weight,proof,(ty,l,r,o),m,id)
78 let string_of_equality ?env eq =
81 let w, _, (ty, left, right, o), _ , id = open_equality eq in
82 Printf.sprintf "Id: %d, Weight: %d, {%s}: %s =(%s) %s"
83 id w (CicPp.ppterm ty)
85 (Utils.string_of_comparison o) (CicPp.ppterm right)
86 | Some (_, context, _) ->
87 let names = Utils.names_of_context context in
88 let w, _, (ty, left, right, o), _ , id = open_equality eq in
89 Printf.sprintf "Id: %d, Weight: %d, {%s}: %s =(%s) %s"
90 id w (CicPp.pp ty names)
91 (CicPp.pp left names) (Utils.string_of_comparison o)
92 (CicPp.pp right names)
95 let compare (_,_,_,s1,_,_) (_,_,_,s2,_,_) =
96 Pervasives.compare s1 s2
101 let (_,p,(_,l,r,_),_,_) = open_equality (Hashtbl.find id_to_eq id) in
104 Not_found -> assert false
107 let string_of_proof ?(names=[]) p gp =
108 let str_of_rule = function
109 | SuperpositionRight -> "SupR"
110 | SuperpositionLeft -> "SupL"
111 | Demodulation -> "Demod"
113 let str_of_pos = function
114 | Utils.Left -> "left"
115 | Utils.Right -> "right"
117 let fst3 (x,_,_) = x in
118 let rec aux margin name =
119 let prefix = String.make margin ' ' ^ name ^ ": " in function
121 Printf.sprintf "%sExact (%s)\n"
122 prefix (CicPp.pp t names)
123 | Step (subst,(rule,eq1,(pos,eq2),pred)) ->
124 Printf.sprintf "%s%s(%s|%d with %d dir %s pred %s))\n"
125 prefix (str_of_rule rule) (Subst.ppsubst ~names subst) eq1 eq2 (str_of_pos pos)
126 (CicPp.pp pred names)^
127 aux (margin+1) (Printf.sprintf "%d" eq1) (fst3 (proof_of_id eq1)) ^
128 aux (margin+1) (Printf.sprintf "%d" eq2) (fst3 (proof_of_id eq2))
135 "GOAL: %s %d %s %s\n"
136 (str_of_pos pos) i (Subst.ppsubst ~names s) (CicPp.pp t names)) ^
137 aux 1 (Printf.sprintf "%d " i) (fst3 (proof_of_id i)))
141 let rec depend eq id =
142 let (_,p,(_,_,_,_),_,ideq) = open_equality eq in
143 if id = ideq then true else
146 | Step (_,(_,id1,(_,id2),_)) ->
147 let eq1 = Hashtbl.find id_to_eq id1 in
148 let eq2 = Hashtbl.find id_to_eq id2 in
149 depend eq1 id || depend eq2 id
152 let ppsubst = Subst.ppsubst ~names:[];;
154 (* returns an explicit named subst and a list of arguments for sym_eq_URI *)
155 let build_ens uri termlist =
156 let obj, _ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
158 | Cic.Constant (_, _, _, uris, _) ->
159 assert (List.length uris <= List.length termlist);
160 let rec aux = function
162 | (uri::uris), (term::tl) ->
163 let ens, args = aux (uris, tl) in
164 (uri, term)::ens, args
165 | _, _ -> assert false
171 let mk_sym uri ty t1 t2 p =
172 let ens, args = build_ens uri [ty;t1;t2;p] in
173 Cic.Appl (Cic.Const(uri, ens) :: args)
176 let mk_trans uri ty t1 t2 t3 p12 p23 =
177 let ens, args = build_ens uri [ty;t1;t2;t3;p12;p23] in
178 Cic.Appl (Cic.Const (uri, ens) :: args)
181 let mk_eq_ind uri ty what pred p1 other p2 =
182 Cic.Appl [Cic.Const (uri, []); ty; what; pred; p1; other; p2]
185 let p_of_sym ens tl =
186 let args = List.map snd ens @ tl in
192 let open_trans ens tl =
193 let args = List.map snd ens @ tl in
195 | [ty;l;m;r;p1;p2] -> ty,l,m,r,p1,p2
199 let open_eq_ind args =
201 | [ty;l;pred;pl;r;pleqr] -> ty,l,pred,pl,r,pleqr
207 | Cic.Lambda (_,ty,(Cic.Appl [Cic.MutInd (uri, 0,_);_;l;r]))
208 when LibraryObjects.is_eq_URI uri -> ty,uri,l,r
209 | _ -> prerr_endline (CicPp.ppterm pred); assert false
213 CicSubstitution.subst (Cic.Implicit None) t <>
214 CicSubstitution.subst (Cic.Rel 1) t
219 let rec remove_refl t =
221 | Cic.Appl (((Cic.Const(uri_trans,ens))::tl) as args)
222 when LibraryObjects.is_trans_eq_URI uri_trans ->
223 let ty,l,m,r,p1,p2 = open_trans ens tl in
225 | Cic.Appl [Cic.MutConstruct (uri, 0, 1,_);_;_],p2 ->
227 | p1,Cic.Appl [Cic.MutConstruct (uri, 0, 1,_);_;_] ->
229 | _ -> Cic.Appl (List.map remove_refl args))
230 | Cic.Appl l -> Cic.Appl (List.map remove_refl l)
233 let rec canonical t =
235 | Cic.Appl (((Cic.Const(uri_sym,ens))::tl) as args)
236 when LibraryObjects.is_sym_eq_URI uri_sym ->
237 (match p_of_sym ens tl with
238 | Cic.Appl ((Cic.Const(uri,ens))::tl)
239 when LibraryObjects.is_sym_eq_URI uri ->
240 canonical (p_of_sym ens tl)
241 | Cic.Appl ((Cic.Const(uri_trans,ens))::tl)
242 when LibraryObjects.is_trans_eq_URI uri_trans ->
243 let ty,l,m,r,p1,p2 = open_trans ens tl in
244 mk_trans uri_trans ty r m l
245 (canonical (mk_sym uri_sym ty m r p2))
246 (canonical (mk_sym uri_sym ty l m p1))
247 | Cic.Appl (((Cic.Const(uri_ind,ens)) as he)::tl)
248 when LibraryObjects.is_eq_ind_URI uri_ind ||
249 LibraryObjects.is_eq_ind_r_URI uri_ind ->
250 let ty, what, pred, p1, other, p2 =
252 | [ty;what;pred;p1;other;p2] -> ty, what, pred, p1, other, p2
257 | Cic.Lambda (name,s,Cic.Appl [Cic.MutInd(uri,0,ens);ty;l;r])
258 when LibraryObjects.is_eq_URI uri ->
260 (name,s,Cic.Appl [Cic.MutInd(uri,0,ens);ty;r;l]),l,r
262 prerr_endline (CicPp.ppterm pred);
265 let l = CicSubstitution.subst what l in
266 let r = CicSubstitution.subst what r in
269 canonical (mk_sym uri_sym ty l r p1);other;canonical p2]
270 | Cic.Appl [Cic.MutConstruct (uri, 0, 1,_);_;_] as t
271 when LibraryObjects.is_eq_URI uri -> t
272 | _ -> Cic.Appl (List.map canonical args))
273 | Cic.Appl l -> Cic.Appl (List.map canonical l)
276 remove_refl (canonical t)
279 let ty_of_lambda = function
280 | Cic.Lambda (_,ty,_) -> ty
284 let compose_contexts ctx1 ctx2 =
285 ProofEngineReduction.replace_lifting
286 ~equality:(=) ~what:[Cic.Rel 1] ~with_what:[ctx2] ~where:ctx1
289 let put_in_ctx ctx t =
290 ProofEngineReduction.replace_lifting
291 ~equality:(=) ~what:[Cic.Rel 1] ~with_what:[t] ~where:ctx
294 let mk_eq uri ty l r =
295 Cic.Appl [Cic.MutInd(uri,0,[]);ty;l;r]
298 let mk_refl uri ty t =
299 Cic.Appl [Cic.MutConstruct(uri,0,1,[]);ty;t]
302 let open_eq = function
303 | Cic.Appl [Cic.MutInd(uri,0,[]);ty;l;r] when LibraryObjects.is_eq_URI uri ->
308 let contextualize uri ty left right t =
309 (* aux [uri] [ty] [left] [right] [ctx] [t]
311 * the parameters validate this invariant
312 * t: eq(uri) ty left right
313 * that is used only by the base case
315 * ctx is a term with an open (Rel 1). (Rel 1) is the empty context
317 let rec aux uri ty left right ctx_d = function
318 | Cic.Appl ((Cic.Const(uri_ind,ens))::tl)
319 when LibraryObjects.is_eq_ind_URI uri_ind ||
320 LibraryObjects.is_eq_ind_r_URI uri_ind ->
321 let ty1,what,pred,p1,other,p2 = open_eq_ind tl in
322 let ty2,eq,lp,rp = open_pred pred in
323 let uri_trans = LibraryObjects.trans_eq_URI ~eq:uri in
324 let uri_sym = LibraryObjects.sym_eq_URI ~eq:uri in
325 let is_not_fixed_lp = is_not_fixed lp in
326 let avoid_eq_ind = LibraryObjects.is_eq_ind_URI uri_ind in
327 (* extract the context and the fixed term from the predicate *)
329 let m, ctx_c = if is_not_fixed_lp then rp,lp else lp,rp in
330 (* they were under a lambda *)
331 let m = CicSubstitution.subst (Cic.Implicit None) m in
332 let ctx_c = CicSubstitution.subst (Cic.Rel 1) ctx_c in
335 (* create the compound context and put the terms under it *)
336 let ctx_dc = compose_contexts ctx_d ctx_c in
337 let dc_what = put_in_ctx ctx_dc what in
338 let dc_other = put_in_ctx ctx_dc other in
339 (* m is already in ctx_c so it is put in ctx_d only *)
340 let d_m = put_in_ctx ctx_d m in
341 (* we also need what in ctx_c *)
342 let c_what = put_in_ctx ctx_c what in
343 (* now put the proofs in the compound context *)
344 let p1 = (* p1: dc_what = d_m *)
345 if is_not_fixed_lp then
346 aux uri ty1 c_what m ctx_d p1
348 mk_sym uri_sym ty d_m dc_what
349 (aux uri ty1 m c_what ctx_d p1)
351 let p2 = (* p2: dc_other = dc_what *)
353 mk_sym uri_sym ty dc_what dc_other
354 (aux uri ty1 what other ctx_dc p2)
356 aux uri ty1 other what ctx_dc p2
358 (* if pred = \x.C[x]=m --> t : C[other]=m --> trans other what m
359 if pred = \x.m=C[x] --> t : m=C[other] --> trans m what other *)
360 let a,b,c,paeqb,pbeqc =
361 if is_not_fixed_lp then
362 dc_other,dc_what,d_m,p2,p1
364 d_m,dc_what,dc_other,
365 (mk_sym uri_sym ty dc_what d_m p1),
366 (mk_sym uri_sym ty dc_other dc_what p2)
368 mk_trans uri_trans ty a b c paeqb pbeqc
370 let uri_sym = LibraryObjects.sym_eq_URI ~eq:uri in
371 let uri_ind = LibraryObjects.eq_ind_URI ~eq:uri in
373 (* ctx_d will go under a lambda, but put_in_ctx substitutes Rel 1 *)
374 let ctx_d = CicSubstitution.lift_from 2 1 ctx_d in (* bleah *)
375 let r = put_in_ctx ctx_d (CicSubstitution.lift 1 left) in
377 let lty = CicSubstitution.lift 1 ty in
378 Cic.Lambda (Cic.Name "foo",ty,(mk_eq uri lty l r))
380 let d_left = put_in_ctx ctx_d left in
381 let d_right = put_in_ctx ctx_d right in
382 let refl_eq = mk_refl uri ty d_left in
383 mk_sym uri_sym ty d_right d_left
384 (mk_eq_ind uri_ind ty left pred refl_eq right t)
386 let empty_context = Cic.Rel 1 in
387 aux uri ty left right empty_context t
390 let contextualize_rewrites t ty =
391 let eq,ty,l,r = open_eq ty in
392 contextualize eq ty l r t
395 let build_proof_step subst p1 p2 pos l r pred =
396 let p1 = Subst.apply_subst subst p1 in
397 let p2 = Subst.apply_subst subst p2 in
398 let l = Subst.apply_subst subst l in
399 let r = Subst.apply_subst subst r in
400 let pred = Subst.apply_subst subst pred in
403 | Cic.Lambda (_,ty,body) -> ty,body
407 if pos = Utils.Left then l,r else r,l
411 mk_eq_ind (Utils.eq_ind_URI ()) ty what pred p1 other p2
413 mk_eq_ind (Utils.eq_ind_r_URI ()) ty what pred p1 other p2
416 let build_proof_term proof =
417 let rec aux = function
419 | Step (subst,(_, id1, (pos,id2), pred)) ->
420 let p,_,_ = proof_of_id id1 in
422 let p,l,r = proof_of_id id2 in
424 build_proof_step subst p1 p2 pos l r pred
429 let wfo goalproof proof =
431 let p,_,_ = proof_of_id id in
433 | Exact _ -> if (List.mem id acc) then acc else id :: acc
434 | Step (_,(_,id1, (_,id2), _)) ->
435 let acc = if not (List.mem id1 acc) then aux acc id1 else acc in
436 let acc = if not (List.mem id2 acc) then aux acc id2 else acc in
442 | Step (_,(_,id1, (_,id2), _)) -> aux (aux [] id1) id2
444 List.fold_left (fun acc (_,id,_,_) -> aux acc id) acc goalproof
447 let string_of_id names id =
449 let (_,p,(_,l,r,_),_,_) = open_equality (Hashtbl.find id_to_eq id) in
452 Printf.sprintf "%d = %s: %s = %s" id
453 (CicPp.pp t names) (CicPp.pp l names) (CicPp.pp r names)
454 | Step (_,(step,id1, (_,id2), _) ) ->
455 Printf.sprintf "%6d: %s %6d %6d %s = %s" id
456 (if step = SuperpositionRight then "SupR" else "Demo")
457 id1 id2 (CicPp.pp l names) (CicPp.pp r names)
459 Not_found -> assert false
461 let pp_proof names goalproof proof =
462 String.concat "\n" (List.map (string_of_id names) (wfo goalproof proof)) ^
463 "\ngoal is demodulated with " ^
465 ((List.map (fun (_,i,_,_) -> string_of_int i) goalproof)))
468 let build_goal_proof l initial ty =
471 (fun current_proof (pos,id,subst,pred) ->
472 let p,l,r = proof_of_id id in
473 let p = build_proof_term p in
474 let pos = if pos = Utils.Left then Utils.Right else Utils.Left in
475 build_proof_step subst current_proof p pos l r pred)
479 (*canonical (contextualize_rewrites proof ty)*)
482 let refl_proof ty term =
485 (LibraryObjects.eq_URI (), 0, 1, []);
489 let metas_of_proof p =
490 Utils.metas_of_term (build_proof_term p)
493 let relocate newmeta menv =
494 let subst, metasenv, newmeta =
496 (fun (i, context, ty) (subst, menv, maxmeta) ->
498 CicMkImplicit.identity_relocation_list_for_metavariable context *)
500 let newsubst = Subst.buildsubst i context (Cic.Meta(maxmeta,irl)) ty subst in
501 let newmeta = maxmeta, context, ty in
502 newsubst, newmeta::menv, maxmeta+1)
503 menv (Subst.empty_subst, [], newmeta+1)
505 let metasenv = Subst.apply_subst_metasenv subst metasenv in
506 let subst = Subst.flatten_subst subst in
507 subst, metasenv, newmeta
510 let fix_metas newmeta eq =
511 let w, p, (ty, left, right, o), menv,_ = open_equality eq in
514 fix_metas_old newmeta (w, p, (ty, left, right, o), menv, args) in
515 prerr_endline (string_of_equality eq); *)
516 let subst, metasenv, newmeta = relocate newmeta menv in
517 let ty = Subst.apply_subst subst ty in
518 let left = Subst.apply_subst subst left in
519 let right = Subst.apply_subst subst right in
520 let fix_proof = function
521 | Exact p -> Exact (Subst.apply_subst subst p)
522 | Step (s,(r,id1,(pos,id2),pred)) ->
523 Step (Subst.concat_substs s subst,(r,id1,(pos,id2), pred))
525 let p = fix_proof p in
526 let eq = mk_equality (w, p, (ty, left, right, o), metasenv) in
527 (* debug prerr_endline (string_of_equality eq); *)
530 exception NotMetaConvertible;;
532 let meta_convertibility_aux table t1 t2 =
533 let module C = Cic in
534 let rec aux ((table_l, table_r) as table) t1 t2 =
536 | C.Meta (m1, tl1), C.Meta (m2, tl2) ->
537 let m1_binding, table_l =
538 try List.assoc m1 table_l, table_l
539 with Not_found -> m2, (m1, m2)::table_l
540 and m2_binding, table_r =
541 try List.assoc m2 table_r, table_r
542 with Not_found -> m1, (m2, m1)::table_r
544 if (m1_binding <> m2) || (m2_binding <> m1) then
545 raise NotMetaConvertible
551 | None, Some _ | Some _, None -> raise NotMetaConvertible
553 | Some t1, Some t2 -> (aux res t1 t2))
554 (table_l, table_r) tl1 tl2
555 with Invalid_argument _ ->
556 raise NotMetaConvertible
558 | C.Var (u1, ens1), C.Var (u2, ens2)
559 | C.Const (u1, ens1), C.Const (u2, ens2) when (UriManager.eq u1 u2) ->
560 aux_ens table ens1 ens2
561 | C.Cast (s1, t1), C.Cast (s2, t2)
562 | C.Prod (_, s1, t1), C.Prod (_, s2, t2)
563 | C.Lambda (_, s1, t1), C.Lambda (_, s2, t2)
564 | C.LetIn (_, s1, t1), C.LetIn (_, s2, t2) ->
565 let table = aux table s1 s2 in
567 | C.Appl l1, C.Appl l2 -> (
568 try List.fold_left2 (fun res t1 t2 -> (aux res t1 t2)) table l1 l2
569 with Invalid_argument _ -> raise NotMetaConvertible
571 | C.MutInd (u1, i1, ens1), C.MutInd (u2, i2, ens2)
572 when (UriManager.eq u1 u2) && i1 = i2 -> aux_ens table ens1 ens2
573 | C.MutConstruct (u1, i1, j1, ens1), C.MutConstruct (u2, i2, j2, ens2)
574 when (UriManager.eq u1 u2) && i1 = i2 && j1 = j2 ->
575 aux_ens table ens1 ens2
576 | C.MutCase (u1, i1, s1, t1, l1), C.MutCase (u2, i2, s2, t2, l2)
577 when (UriManager.eq u1 u2) && i1 = i2 ->
578 let table = aux table s1 s2 in
579 let table = aux table t1 t2 in (
580 try List.fold_left2 (fun res t1 t2 -> (aux res t1 t2)) table l1 l2
581 with Invalid_argument _ -> raise NotMetaConvertible
583 | C.Fix (i1, il1), C.Fix (i2, il2) when i1 = i2 -> (
586 (fun res (n1, i1, s1, t1) (n2, i2, s2, t2) ->
587 if i1 <> i2 then raise NotMetaConvertible
589 let res = (aux res s1 s2) in aux res t1 t2)
591 with Invalid_argument _ -> raise NotMetaConvertible
593 | C.CoFix (i1, il1), C.CoFix (i2, il2) when i1 = i2 -> (
596 (fun res (n1, s1, t1) (n2, s2, t2) ->
597 let res = aux res s1 s2 in aux res t1 t2)
599 with Invalid_argument _ -> raise NotMetaConvertible
601 | t1, t2 when t1 = t2 -> table
602 | _, _ -> raise NotMetaConvertible
604 and aux_ens table ens1 ens2 =
605 let cmp (u1, t1) (u2, t2) =
606 Pervasives.compare (UriManager.string_of_uri u1) (UriManager.string_of_uri u2)
608 let ens1 = List.sort cmp ens1
609 and ens2 = List.sort cmp ens2 in
612 (fun res (u1, t1) (u2, t2) ->
613 if not (UriManager.eq u1 u2) then raise NotMetaConvertible
616 with Invalid_argument _ -> raise NotMetaConvertible
622 let meta_convertibility_eq eq1 eq2 =
623 let _, _, (ty, left, right, _), _,_ = open_equality eq1 in
624 let _, _, (ty', left', right', _), _,_ = open_equality eq2 in
627 else if (left = left') && (right = right') then
629 else if (left = right') && (right = left') then
633 let table = meta_convertibility_aux ([], []) left left' in
634 let _ = meta_convertibility_aux table right right' in
636 with NotMetaConvertible ->
638 let table = meta_convertibility_aux ([], []) left right' in
639 let _ = meta_convertibility_aux table right left' in
641 with NotMetaConvertible ->
646 let meta_convertibility t1 t2 =
651 ignore(meta_convertibility_aux ([], []) t1 t2);
653 with NotMetaConvertible ->
657 exception TermIsNotAnEquality;;
659 let term_is_equality term =
660 let iseq uri = UriManager.eq uri (LibraryObjects.eq_URI ()) in
662 | Cic.Appl [Cic.MutInd (uri, _, _); _; _; _] when iseq uri -> true
666 let equality_of_term proof term =
667 let eq_uri = LibraryObjects.eq_URI () in
668 let iseq uri = UriManager.eq uri eq_uri in
670 | Cic.Appl [Cic.MutInd (uri, _, _); ty; t1; t2] when iseq uri ->
671 let o = !Utils.compare_terms t1 t2 in
672 let stat = (ty,t1,t2,o) in
673 let w = Utils.compute_equality_weight stat in
674 let e = mk_equality (w, Exact proof, stat,[]) in
677 raise TermIsNotAnEquality
680 let is_weak_identity eq =
681 let _,_,(_,left, right,_),_,_ = open_equality eq in
682 left = right || meta_convertibility left right
685 let is_identity (_, context, ugraph) eq =
686 let _,_,(ty,left,right,_),menv,_ = open_equality eq in
688 (* (meta_convertibility left right)) *)
689 fst (CicReduction.are_convertible ~metasenv:menv context left right ugraph)
693 let term_of_equality equality =
694 let _, _, (ty, left, right, _), menv, _= open_equality equality in
695 let eq i = function Cic.Meta (j, _) -> i = j | _ -> false in
696 let argsno = List.length menv in
698 CicSubstitution.lift argsno
699 (Cic.Appl [Cic.MutInd (LibraryObjects.eq_URI (), 0, []); ty; left; right])
703 (fun (i,_,ty) (n, t) ->
704 let name = Cic.Name ("X" ^ (string_of_int n)) in
705 let ty = CicSubstitution.lift (n-1) ty in
707 ProofEngineReduction.replace
708 ~equality:eq ~what:[i]
709 ~with_what:[Cic.Rel (argsno - (n - 1))] ~where:t
711 (n-1, Cic.Prod (name, ty, t)))