2 let debug_print = Utils.debug_print;;
5 type retrieval_mode = Matching | Unification;;
8 let print_candidates mode term res =
12 Printf.printf "| candidates Matching %s\n" (CicPp.ppterm term)
14 Printf.printf "| candidates Unification %s\n" (CicPp.ppterm term)
20 Printf.sprintf "| (%s, %s)" (Utils.string_of_pos p)
21 (Inference.string_of_equality e))
27 let indexing_retrieval_time = ref 0.;;
30 (* let my_apply_subst subst term = *)
31 (* let module C = Cic in *)
32 (* let lookup lift_amount meta = *)
34 (* | C.Meta (i, _) -> ( *)
36 (* let _, (_, t, _) = List.find (fun (m, _) -> m = i) subst in *)
37 (* (\* CicSubstitution.lift lift_amount *\)t *)
38 (* with Not_found -> meta *)
40 (* | _ -> assert false *)
42 (* let rec apply_aux lift_amount = function *)
43 (* | C.Meta (i, l) as t -> lookup lift_amount t *)
44 (* | C.Appl l -> C.Appl (List.map (apply_aux lift_amount) l) *)
45 (* | C.Prod (nn, s, t) -> *)
46 (* C.Prod (nn, apply_aux lift_amount s, apply_aux (lift_amount+1) t) *)
47 (* | C.Lambda (nn, s, t) -> *)
48 (* C.Lambda (nn, apply_aux lift_amount s, apply_aux (lift_amount+1) t) *)
51 (* apply_aux 0 term *)
55 (* let apply_subst subst term = *)
56 (* Printf.printf "| apply_subst:\n| subst: %s\n| term: %s\n" *)
57 (* (Utils.print_subst ~prefix:" ; " subst) (CicPp.ppterm term); *)
58 (* let res = my_apply_subst subst term in *)
59 (* (\* let res = CicMetaSubst.apply_subst subst term in *\) *)
60 (* Printf.printf "| res: %s\n" (CicPp.ppterm res); *)
61 (* print_endline "|"; *)
65 (* let apply_subst = my_apply_subst *)
66 let apply_subst = CicMetaSubst.apply_subst
71 let profile = CicUtil.profile "apply_subst" in
72 (fun s a -> profile.profile (apply_subst s) a)
79 let empty_table () = []
81 let index table equality =
82 let _, _, (_, l, r, ordering), _, _ = equality in
84 | Utils.Gt -> (Utils.Left, equality)::table
85 | Utils.Lt -> (Utils.Right, equality)::table
86 | _ -> (Utils.Left, equality)::(Utils.Right, equality)::table
89 let remove_index table equality =
90 List.filter (fun (p, e) -> e != equality) table
93 let in_index table equality =
94 List.exists (fun (p, e) -> e == equality) table
97 let get_candidates mode table term = table
104 Path_indexing.PSTrie.empty
107 let index = Path_indexing.index
108 and remove_index = Path_indexing.remove_index
109 and in_index = Path_indexing.in_index;;
111 let get_candidates mode trie term =
112 let t1 = Unix.gettimeofday () in
116 | Matching -> Path_indexing.retrieve_generalizations trie term
117 | Unification -> Path_indexing.retrieve_unifiables trie term
118 (* Path_indexing.retrieve_all trie term *)
120 Path_indexing.PosEqSet.elements s
122 (* print_candidates mode term res; *)
123 let t2 = Unix.gettimeofday () in
124 indexing_retrieval_time := !indexing_retrieval_time +. (t2 -. t1);
130 (* DISCRIMINATION TREES *)
132 Discrimination_tree.DiscriminationTree.empty
135 let index = Discrimination_tree.index
136 and remove_index = Discrimination_tree.remove_index
137 and in_index = Discrimination_tree.in_index;;
139 let get_candidates mode tree term =
140 let t1 = Unix.gettimeofday () in
144 | Matching -> Discrimination_tree.retrieve_generalizations tree term
145 | Unification -> Discrimination_tree.retrieve_unifiables tree term
147 Discrimination_tree.PosEqSet.elements s
149 (* print_candidates mode term res; *)
150 (* print_endline (Discrimination_tree.string_of_discrimination_tree tree); *)
151 (* print_newline (); *)
152 let t2 = Unix.gettimeofday () in
153 indexing_retrieval_time := !indexing_retrieval_time +. (t2 -. t1);
158 (* let get_candidates = *)
159 (* let profile = CicUtil.profile "Indexing.get_candidates" in *)
160 (* (fun mode tree term -> profile.profile (get_candidates mode tree) term) *)
164 let match_unif_time_ok = ref 0.;;
165 let match_unif_time_no = ref 0.;;
168 let rec find_matches metasenv context ugraph lift_amount term termty =
169 let module C = Cic in
170 let module U = Utils in
171 let module S = CicSubstitution in
172 let module M = CicMetaSubst in
173 let module HL = HelmLibraryObjects in
174 let cmp = !Utils.compare_terms in
175 (* let names = Utils.names_of_context context in *)
176 (* let termty, ugraph = *)
177 (* CicTypeChecker.type_of_aux' metasenv context term ugraph *)
182 let pos, (_, proof, (ty, left, right, o), metas, args) = candidate in
183 (* if not (fst (CicReduction.are_convertible *)
184 (* ~metasenv context termty ty ugraph)) then ( *)
185 (* (\* debug_print ( *\) *)
186 (* (\* Printf.sprintf "CANDIDATE HAS WRONG TYPE: %s required, %s found" *\) *)
187 (* (\* (CicPp.pp termty names) (CicPp.pp ty names)); *\) *)
188 (* find_matches metasenv context ugraph lift_amount term termty tl *)
190 let do_match c other eq_URI =
191 let subst', metasenv', ugraph' =
192 let t1 = Unix.gettimeofday () in
195 Inference.matching (metasenv @ metas) context
196 term (S.lift lift_amount c) ugraph in
197 let t2 = Unix.gettimeofday () in
198 match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
200 with Inference.MatchingFailure as e ->
201 let t2 = Unix.gettimeofday () in
202 match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
205 Some (C.Rel (1 + lift_amount), subst', metasenv', ugraph',
208 let c, other, eq_URI =
209 if pos = Utils.Left then left, right, HL.Logic.eq_ind_URI
210 else right, left, HL.Logic.eq_ind_r_URI
212 if o <> U.Incomparable then
214 do_match c other eq_URI
215 with Inference.MatchingFailure ->
216 find_matches metasenv context ugraph lift_amount term termty tl
219 try do_match c other eq_URI
220 with Inference.MatchingFailure -> None
223 | Some (_, s, _, _, _) ->
224 let c' = (* M. *)apply_subst s c
225 and other' = (* M. *)apply_subst s other in
226 let order = cmp c' other' in
227 let names = U.names_of_context context in
232 metasenv context ugraph lift_amount term termty tl
234 find_matches metasenv context ugraph lift_amount term termty tl
238 let rec find_all_matches ?(unif_fun=Inference.unification)
239 metasenv context ugraph lift_amount term termty =
240 let module C = Cic in
241 let module U = Utils in
242 let module S = CicSubstitution in
243 let module M = CicMetaSubst in
244 let module HL = HelmLibraryObjects in
245 let cmp = !Utils.compare_terms in
246 (* let names = Utils.names_of_context context in *)
247 (* let termty, ugraph = *)
248 (* CicTypeChecker.type_of_aux' metasenv context term ugraph *)
253 let pos, (_, _, (ty, left, right, o), metas, args) = candidate in
254 (* if not (fst (CicReduction.are_convertible *)
255 (* ~metasenv context termty ty ugraph)) then ( *)
256 (* (\* debug_print ( *\) *)
257 (* (\* Printf.sprintf "CANDIDATE HAS WRONG TYPE: %s required, %s found" *\) *)
258 (* (\* (CicPp.pp termty names) (CicPp.pp ty names)); *\) *)
259 (* find_all_matches ~unif_fun metasenv context ugraph *)
260 (* lift_amount term termty tl *)
262 let do_match c other eq_URI =
263 let subst', metasenv', ugraph' =
264 let t1 = Unix.gettimeofday () in
267 unif_fun (metasenv @ metas) context
268 term (S.lift lift_amount c) ugraph in
269 let t2 = Unix.gettimeofday () in
270 match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
273 | Inference.MatchingFailure
274 | CicUnification.UnificationFailure _
275 | CicUnification.Uncertain _ as e ->
276 let t2 = Unix.gettimeofday () in
277 match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
280 (C.Rel (1 + lift_amount), subst', metasenv', ugraph',
283 let c, other, eq_URI =
284 if pos = Utils.Left then left, right, HL.Logic.eq_ind_URI
285 else right, left, HL.Logic.eq_ind_r_URI
287 if o <> U.Incomparable then
289 let res = do_match c other eq_URI in
290 res::(find_all_matches ~unif_fun metasenv context ugraph
291 lift_amount term termty tl)
293 | Inference.MatchingFailure
294 | CicUnification.UnificationFailure _
295 | CicUnification.Uncertain _ ->
296 find_all_matches ~unif_fun metasenv context ugraph
297 lift_amount term termty tl
300 let res = do_match c other eq_URI in
303 let c' = (* M. *)apply_subst s c
304 and other' = (* M. *)apply_subst s other in
305 let order = cmp c' other' in
306 let names = U.names_of_context context in
307 if order <> U.Lt && order <> U.Le then
308 res::(find_all_matches ~unif_fun metasenv context ugraph
309 lift_amount term termty tl)
311 find_all_matches ~unif_fun metasenv context ugraph
312 lift_amount term termty tl
314 | Inference.MatchingFailure
315 | CicUnification.UnificationFailure _
316 | CicUnification.Uncertain _ ->
317 find_all_matches ~unif_fun metasenv context ugraph
318 lift_amount term termty tl
322 let subsumption env table target =
323 let _, (ty, left, right, _), tmetas, _ = target in
324 let metasenv, context, ugraph = env in
325 let metasenv = metasenv @ tmetas in
326 let samesubst subst subst' =
327 let tbl = Hashtbl.create (List.length subst) in
328 List.iter (fun (m, (c, t1, t2)) -> Hashtbl.add tbl m (c, t1, t2)) subst;
330 (fun (m, (c, t1, t2)) ->
332 let c', t1', t2' = Hashtbl.find tbl m in
333 if (c = c') && (t1 = t1') && (t2 = t2') then true
343 let leftc = get_candidates Matching table left in
344 find_all_matches ~unif_fun:Inference.matching
345 metasenv context ugraph 0 left ty leftc
347 let ok what (_, subst, menv, ug, ((pos, (_, _, (_, l, r, o), _, _)), _)) =
349 let other = if pos = Utils.Left then r else l in
350 let subst', menv', ug' =
351 let t1 = Unix.gettimeofday () in
354 Inference.matching metasenv context what other ugraph in
355 let t2 = Unix.gettimeofday () in
356 match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
358 with Inference.MatchingFailure as e ->
359 let t2 = Unix.gettimeofday () in
360 match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
363 samesubst subst subst'
364 with Inference.MatchingFailure ->
367 let r = List.exists (ok right) leftr in
375 let rightc = get_candidates Matching table right in
376 find_all_matches ~unif_fun:Inference.matching
377 metasenv context ugraph 0 right ty rightc
379 List.exists (ok left) rightr
383 let rec demodulate_term metasenv context ugraph table lift_amount term =
384 let module C = Cic in
385 let module S = CicSubstitution in
386 let module M = CicMetaSubst in
387 let module HL = HelmLibraryObjects in
388 let candidates = get_candidates Matching table term in
393 C.Implicit None, ugraph
394 (* CicTypeChecker.type_of_aux' metasenv context term ugraph *)
397 find_matches metasenv context ugraph lift_amount term termty candidates
408 (res, tl @ [S.lift 1 t])
411 demodulate_term metasenv context ugraph table
415 | None -> (None, tl @ [S.lift 1 t])
416 | Some (rel, _, _, _, _) -> (r, tl @ [rel]))
421 | Some (_, subst, menv, ug, eq_found) ->
422 Some (C.Appl ll, subst, menv, ug, eq_found)
424 | C.Prod (nn, s, t) ->
426 demodulate_term metasenv context ugraph table lift_amount s in (
430 demodulate_term metasenv
431 ((Some (nn, C.Decl s))::context) ugraph
432 table (lift_amount+1) t
436 | Some (t', subst, menv, ug, eq_found) ->
437 Some (C.Prod (nn, (S.lift 1 s), t'),
438 subst, menv, ug, eq_found)
440 | Some (s', subst, menv, ug, eq_found) ->
441 Some (C.Prod (nn, s', (S.lift 1 t)),
442 subst, menv, ug, eq_found)
449 let build_ens_for_sym_eq ty x y =
450 [(UriManager.uri_of_string
451 "cic:/Coq/Init/Logic/Logic_lemmas/equality/A.var", ty);
452 (UriManager.uri_of_string
453 "cic:/Coq/Init/Logic/Logic_lemmas/equality/x.var", x);
454 (UriManager.uri_of_string
455 "cic:/Coq/Init/Logic/Logic_lemmas/equality/y.var", y)]
459 let build_newtarget_time = ref 0.;;
462 let demod_counter = ref 1;;
464 let rec demodulation newmeta env table sign target =
465 let module C = Cic in
466 let module S = CicSubstitution in
467 let module M = CicMetaSubst in
468 let module HL = HelmLibraryObjects in
469 let metasenv, context, ugraph = env in
470 let _, proof, (eq_ty, left, right, order), metas, args = target in
471 let metasenv' = metasenv @ metas in
473 let maxmeta = ref newmeta in
475 let build_newtarget is_left (t, subst, menv, ug, (eq_found, eq_URI)) =
476 let time1 = Unix.gettimeofday () in
478 let pos, (_, proof', (ty, what, other, _), menv', args') = eq_found in
479 let what, other = if pos = Utils.Left then what, other else other, what in
480 let newterm, newproof =
481 let bo = (* M. *)apply_subst subst (S.subst other t) in
483 let name = C.Name ("x_Demod_" ^ (string_of_int !demod_counter)) in
486 if is_left then t, S.lift 1 right else S.lift 1 left, t in
487 (name, ty, S.lift 1 eq_ty, l, r)
489 if sign = Utils.Positive then
491 Inference.ProofBlock (subst, eq_URI, t', eq_found, proof))
496 CicMkImplicit.identity_relocation_list_for_metavariable context in
497 Printf.printf "\nADDING META: %d\n" !maxmeta;
499 C.Meta (!maxmeta, irl)
505 if pos = Utils.Left then
506 build_ens_for_sym_eq ty what other
508 build_ens_for_sym_eq ty other what
510 Inference.ProofSymBlock (ens, proof')
513 if pos = Utils.Left then what, other else other, what
515 pos, (0, proof', (ty, other, what, Utils.Incomparable),
520 Inference.ProofBlock (subst, eq_URI, t', eq_found,
521 Inference.BasicProof metaproof)
524 | Inference.BasicProof _ ->
525 print_endline "replacing a BasicProof";
527 | Inference.ProofGoalBlock (_, parent_eq) ->
528 print_endline "replacing another ProofGoalBlock";
529 Inference.ProofGoalBlock (pb, parent_eq)
532 (0, target_proof, (eq_ty, left, right, order), metas, args)
535 C.Appl [C.MutConstruct (* reflexivity *)
536 (HelmLibraryObjects.Logic.eq_URI, 0, 1, []);
537 eq_ty; if is_left then right else left]
540 Inference.ProofGoalBlock (Inference.BasicProof refl, target'))
542 let left, right = if is_left then newterm, right else left, newterm in
543 let m = (Inference.metas_of_term left) @ (Inference.metas_of_term right) in
544 let newmetasenv = List.filter (fun (i, _, _) -> List.mem i m) metas
547 (function C.Meta (i, _) -> List.mem i m | _ -> assert false)
550 let ordering = !Utils.compare_terms left right in
552 let time2 = Unix.gettimeofday () in
553 build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
556 let w = Utils.compute_equality_weight eq_ty left right in
557 (w, newproof, (eq_ty, left, right, ordering), newmetasenv, newargs)
559 (* if sign = Utils.Positive then ( *)
560 (* let newm, res = Inference.fix_metas !maxmeta res in *)
561 (* maxmeta := newm; *)
564 !maxmeta(* newmeta *), res
566 let res = demodulate_term metasenv' context ugraph table 0 left in
567 (* let build_identity (w, p, (t, l, r, o), m, a) = *)
569 (* | Utils.Gt -> (w, p, (t, r, r, Utils.Eq), m, a) *)
570 (* | _ -> (w, p, (t, l, l, Utils.Eq), m, a) *)
574 let newmeta, newtarget = build_newtarget true t in
575 if (Inference.is_identity (metasenv', context, ugraph) newtarget) ||
576 (Inference.meta_convertibility_eq target newtarget) then
579 (* if subsumption env table newtarget then *)
580 (* newmeta, build_identity newtarget *)
582 demodulation newmeta env table sign newtarget
584 let res = demodulate_term metasenv' context ugraph table 0 right in
587 let newmeta, newtarget = build_newtarget false t in
588 if (Inference.is_identity (metasenv', context, ugraph) newtarget) ||
589 (Inference.meta_convertibility_eq target newtarget) then
592 (* if subsumption env table newtarget then *)
593 (* newmeta, build_identity newtarget *)
595 demodulation newmeta env table sign newtarget
601 let rec betaexpand_term metasenv context ugraph table lift_amount term =
602 let module C = Cic in
603 let module S = CicSubstitution in
604 let module M = CicMetaSubst in
605 let module HL = HelmLibraryObjects in
606 let candidates = get_candidates Unification table term in
607 let res, lifted_term =
612 (fun arg (res, lifted_tl) ->
615 let arg_res, lifted_arg =
616 betaexpand_term metasenv context ugraph table
620 (fun (t, s, m, ug, eq_found) ->
621 (Some t)::lifted_tl, s, m, ug, eq_found)
626 (fun (l, s, m, ug, eq_found) ->
627 (Some lifted_arg)::l, s, m, ug, eq_found)
629 (Some lifted_arg)::lifted_tl)
632 (fun (r, s, m, ug, eq_found) ->
633 None::r, s, m, ug, eq_found) res,
639 (fun (l, s, m, ug, eq_found) ->
640 (C.Meta (i, l), s, m, ug, eq_found)) l'
642 e, C.Meta (i, lifted_l)
645 [], if m <= lift_amount then C.Rel m else C.Rel (m+1)
647 | C.Prod (nn, s, t) ->
649 betaexpand_term metasenv context ugraph table lift_amount s in
651 betaexpand_term metasenv ((Some (nn, C.Decl s))::context) ugraph
652 table (lift_amount+1) t in
655 (fun (t, s, m, ug, eq_found) ->
656 C.Prod (nn, t, lifted_t), s, m, ug, eq_found) l1
659 (fun (t, s, m, ug, eq_found) ->
660 C.Prod (nn, lifted_s, t), s, m, ug, eq_found) l2 in
661 l1' @ l2', C.Prod (nn, lifted_s, lifted_t)
666 (fun arg (res, lifted_tl) ->
667 let arg_res, lifted_arg =
668 betaexpand_term metasenv context ugraph table lift_amount arg
672 (fun (a, s, m, ug, eq_found) ->
673 a::lifted_tl, s, m, ug, eq_found)
678 (fun (r, s, m, ug, eq_found) ->
679 lifted_arg::r, s, m, ug, eq_found)
681 lifted_arg::lifted_tl)
685 (fun (l, s, m, ug, eq_found) -> (C.Appl l, s, m, ug, eq_found)) l',
688 | t -> [], (S.lift lift_amount t)
691 | C.Meta _ -> res, lifted_term
694 C.Implicit None, ugraph
695 (* CicTypeChecker.type_of_aux' metasenv context term ugraph *)
699 metasenv context ugraph lift_amount term termty candidates
705 let sup_l_counter = ref 1;;
707 let superposition_left newmeta (metasenv, context, ugraph) table target =
708 let module C = Cic in
709 let module S = CicSubstitution in
710 let module M = CicMetaSubst in
711 let module HL = HelmLibraryObjects in
712 let module CR = CicReduction in
713 let module U = Utils in
714 let weight, proof, (eq_ty, left, right, ordering), _, _ = target in
716 let term = if ordering = U.Gt then left else right in
717 betaexpand_term metasenv context ugraph table 0 term
719 let maxmeta = ref newmeta in
720 let build_new (bo, s, m, ug, (eq_found, eq_URI)) =
722 print_endline "\nSUPERPOSITION LEFT\n";
724 let time1 = Unix.gettimeofday () in
726 let pos, (_, proof', (ty, what, other, _), menv', args') = eq_found in
727 let what, other = if pos = Utils.Left then what, other else other, what in
728 let newgoal, newproof =
729 let bo' = (* M. *)apply_subst s (S.subst other bo) in
731 let name = C.Name ("x_SupL_" ^ (string_of_int !sup_l_counter)) in
734 if ordering = U.Gt then bo, S.lift 1 right else S.lift 1 left, bo in
735 (name, ty, S.lift 1 eq_ty, l, r)
739 (* [C.MutInd (HL.Logic.eq_URI, 0, []); *)
740 (* S.lift 1 eq_ty] @ *)
741 (* if ordering = U.Gt then [S.lift 1 bo'; S.lift 1 right] *)
742 (* else [S.lift 1 left; S.lift 1 bo']) *)
745 (* let name = C.Name ("x_SupL_" ^ (string_of_int !sup_l_counter)) in *)
746 (* incr sup_l_counter; *)
747 (* C.Lambda (name, ty, bo'') *)
752 CicMkImplicit.identity_relocation_list_for_metavariable context in
753 C.Meta (!maxmeta, irl)
759 if pos = Utils.Left then
760 build_ens_for_sym_eq ty what other
762 build_ens_for_sym_eq ty other what
764 Inference.ProofSymBlock (ens, proof')
767 if pos = Utils.Left then what, other else other, what
769 pos, (0, proof', (ty, other, what, Utils.Incomparable), menv', args')
773 Inference.ProofBlock (s, eq_URI, t', eq_found,
774 Inference.BasicProof metaproof)
777 | Inference.BasicProof _ ->
778 print_endline "replacing a BasicProof";
780 | Inference.ProofGoalBlock (_, parent_eq) ->
781 print_endline "replacing another ProofGoalBlock";
782 Inference.ProofGoalBlock (pb, parent_eq)
785 (weight, target_proof, (eq_ty, left, right, ordering), [], [])
788 C.Appl [C.MutConstruct (* reflexivity *)
789 (HelmLibraryObjects.Logic.eq_URI, 0, 1, []);
790 eq_ty; if ordering = U.Gt then right else left]
793 Inference.ProofGoalBlock (Inference.BasicProof refl, target'))
796 if ordering = U.Gt then newgoal, right else left, newgoal in
797 let neworder = !Utils.compare_terms left right in
799 let time2 = Unix.gettimeofday () in
800 build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
803 let w = Utils.compute_equality_weight eq_ty left right in
804 (w, newproof, (eq_ty, left, right, neworder), [], [])
808 !maxmeta, List.map build_new expansions
812 let sup_r_counter = ref 1;;
814 let superposition_right newmeta (metasenv, context, ugraph) table target =
815 let module C = Cic in
816 let module S = CicSubstitution in
817 let module M = CicMetaSubst in
818 let module HL = HelmLibraryObjects in
819 let module CR = CicReduction in
820 let module U = Utils in
821 let _, eqproof, (eq_ty, left, right, ordering), newmetas, args = target in
822 let metasenv' = metasenv @ newmetas in
823 let maxmeta = ref newmeta in
826 | U.Gt -> fst (betaexpand_term metasenv' context ugraph table 0 left), []
827 | U.Lt -> [], fst (betaexpand_term metasenv' context ugraph table 0 right)
831 (fun (_, subst, _, _, _) ->
832 let subst = (* M. *)apply_subst subst in
833 let o = !Utils.compare_terms (subst l) (subst r) in
834 o <> U.Lt && o <> U.Le)
835 (fst (betaexpand_term metasenv' context ugraph table 0 l))
837 (res left right), (res right left)
839 let build_new ordering (bo, s, m, ug, (eq_found, eq_URI)) =
841 let time1 = Unix.gettimeofday () in
843 let pos, (_, proof', (ty, what, other, _), menv', args') = eq_found in
844 let what, other = if pos = Utils.Left then what, other else other, what in
845 let newgoal, newproof =
846 let bo' = (* M. *)apply_subst s (S.subst other bo) in
848 let name = C.Name ("x_SupR_" ^ (string_of_int !sup_r_counter)) in
851 if ordering = U.Gt then bo, S.lift 1 right else S.lift 1 left, bo in
852 (name, ty, S.lift 1 eq_ty, l, r)
856 (* [C.MutInd (HL.Logic.eq_URI, 0, []); S.lift 1 eq_ty] @ *)
857 (* if ordering = U.Gt then [S.lift 1 bo'; S.lift 1 right] *)
858 (* else [S.lift 1 left; S.lift 1 bo']) *)
861 (* let name = C.Name ("x_SupR_" ^ (string_of_int !sup_r_counter)) in *)
862 (* incr sup_r_counter; *)
863 (* C.Lambda (name, ty, bo'') *)
866 Inference.ProofBlock (s, eq_URI, t', eq_found, eqproof(* target *))
867 (* (\* M. *\)apply_subst s *)
868 (* (C.Appl [C.Const (eq_URI, []); ty; what; t'; *)
869 (* eqproof; other; proof']) *)
871 let newmeta, newequality =
873 if ordering = U.Gt then newgoal, (* M. *)apply_subst s right
874 else (* M. *)apply_subst s left, newgoal in
875 let neworder = !Utils.compare_terms left right
876 and newmenv = newmetas @ menv'
877 and newargs = args @ args' in
879 let w = Utils.compute_equality_weight eq_ty left right in
880 (w, newproof, (eq_ty, left, right, neworder), newmenv, newargs)
881 and env = (metasenv, context, ugraph) in
882 let newm, eq' = Inference.fix_metas !maxmeta eq' in
887 let time2 = Unix.gettimeofday () in
888 build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
893 (* let build_new = *)
894 (* let profile = CicUtil.profile "Indexing.superposition_right.build_new" in *)
895 (* (fun o e -> profile.profile (build_new o) e) *)
898 let new1 = List.map (build_new U.Gt) res1
899 and new2 = List.map (build_new U.Lt) res2 in
901 | _, _, (_, left, right, _), _, _ ->
902 not (fst (CR.are_convertible context left right ugraph))
905 (List.filter ok (new1 @ new2)))