]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/paramodulation/indexing.ml
various updates, removed proofs for now because they are the real bottleneck!!
[helm.git] / helm / ocaml / paramodulation / indexing.ml
1
2 type retrieval_mode = Matching | Unification;;
3
4
5 let print_candidates mode term res =
6   let _ =
7     match mode with
8     | Matching ->
9         Printf.printf "| candidates Matching %s\n" (CicPp.ppterm term)
10     | Unification ->
11         Printf.printf "| candidates Unification %s\n" (CicPp.ppterm term)
12   in
13   print_endline
14     (String.concat "\n"
15        (List.map
16           (fun (p, e) ->
17              Printf.sprintf "| (%s, %s)" (Utils.string_of_pos p)
18                (Inference.string_of_equality e))
19           res));
20   print_endline "|";
21 ;;
22
23
24 let indexing_retrieval_time = ref 0.;;
25
26
27 (* let my_apply_subst subst term = *)
28 (*   let module C = Cic in *)
29 (*   let lookup lift_amount meta = *)
30 (*     match meta with *)
31 (*     | C.Meta (i, _) -> ( *)
32 (*         try *)
33 (*           let _, (_, t, _) = List.find (fun (m, _) -> m = i) subst in *)
34 (*           (\* CicSubstitution.lift lift_amount  *\)t *)
35 (*         with Not_found -> meta *)
36 (*       ) *)
37 (*     | _ -> assert false *)
38 (*   in *)
39 (*   let rec apply_aux lift_amount =  function *)
40 (*     | C.Meta (i, l) as t -> lookup lift_amount t *)
41 (*     | C.Appl l -> C.Appl (List.map (apply_aux lift_amount) l) *)
42 (*     | C.Prod (nn, s, t) -> *)
43 (*         C.Prod (nn, apply_aux lift_amount s, apply_aux (lift_amount+1) t) *)
44 (*     | C.Lambda (nn, s, t) -> *)
45 (*         C.Lambda (nn, apply_aux lift_amount s, apply_aux (lift_amount+1) t) *)
46 (*     | t -> t *)
47 (*   in *)
48 (*   apply_aux 0 term *)
49 (* ;; *)
50
51
52 (* let apply_subst subst term = *)
53 (*   Printf.printf "| apply_subst:\n| subst: %s\n| term: %s\n" *)
54 (*     (Utils.print_subst ~prefix:" ; " subst) (CicPp.ppterm term); *)
55 (*   let res = my_apply_subst subst term in *)
56 (* (\*   let res = CicMetaSubst.apply_subst subst term in *\) *)
57 (*   Printf.printf "| res: %s\n" (CicPp.ppterm res); *)
58 (*   print_endline "|"; *)
59 (*   res *)
60 (* ;; *)
61
62 (* let apply_subst = my_apply_subst *)
63 let apply_subst = CicMetaSubst.apply_subst
64
65
66 let apply_subst =
67   let profile = CicUtil.profile "apply_subst" in
68   (fun s a -> profile (apply_subst s) a)
69 ;;
70
71
72 (*
73 let empty_table () =
74   Path_indexing.PSTrie.empty
75 ;;
76
77 let index = Path_indexing.index
78 and remove_index = Path_indexing.remove_index
79 and in_index = Path_indexing.in_index;;
80   
81 let get_candidates mode trie term =
82   let t1 = Unix.gettimeofday () in
83   let res = 
84     let s = 
85       match mode with
86       | Matching -> Path_indexing.retrieve_generalizations trie term
87       | Unification -> Path_indexing.retrieve_unifiables trie term
88 (*       Path_indexing.retrieve_all trie term *)
89     in
90     Path_indexing.PosEqSet.elements s
91   in
92 (*   print_candidates mode term res; *)
93   let t2 = Unix.gettimeofday () in
94   indexing_retrieval_time := !indexing_retrieval_time +. (t2 -. t1);
95   res
96 ;;
97 *)
98
99
100 let empty_table () =
101   Discrimination_tree.DiscriminationTree.empty
102 ;;
103
104 let index = Discrimination_tree.index
105 and remove_index = Discrimination_tree.remove_index
106 and in_index = Discrimination_tree.in_index;;
107
108 let get_candidates mode tree term =
109   let t1 = Unix.gettimeofday () in
110   let res =
111     let s = 
112       match mode with
113       | Matching -> Discrimination_tree.retrieve_generalizations tree term
114       | Unification -> Discrimination_tree.retrieve_unifiables tree term
115     in
116     Discrimination_tree.PosEqSet.elements s
117   in
118 (*   print_candidates mode term res; *)
119   let t2 = Unix.gettimeofday () in
120   indexing_retrieval_time := !indexing_retrieval_time +. (t2 -. t1);
121   res
122 ;;
123
124
125 (* let get_candidates = *)
126 (*   let profile = CicUtil.profile "Indexing.get_candidates" in *)
127 (*   (fun mode tree term -> profile (get_candidates mode tree) term) *)
128 (* ;; *)
129
130
131 let match_unif_time_ok = ref 0.;;
132 let match_unif_time_no = ref 0.;;
133
134
135 let rec find_matches metasenv context ugraph lift_amount term =
136   let module C = Cic in
137   let module U = Utils in
138   let module S = CicSubstitution in
139   let module M = CicMetaSubst in
140   let module HL = HelmLibraryObjects in
141   let cmp = !Utils.compare_terms in
142   let names = Utils.names_of_context context in
143   function
144     | [] -> None
145     | candidate::tl ->
146         let pos, (proof, (ty, left, right, o), metas, args) = candidate in
147         let do_match c other eq_URI =
148           let subst', metasenv', ugraph' =
149             let t1 = Unix.gettimeofday () in
150             try
151               let r = 
152                 Inference.matching (metasenv @ metas) context
153                   term (S.lift lift_amount c) ugraph in
154               let t2 = Unix.gettimeofday () in
155               match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
156               r
157             with e ->
158               let t2 = Unix.gettimeofday () in
159               match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
160               raise e
161           in
162             Some (C.Rel (1 + lift_amount), subst', metasenv', ugraph',
163                   (candidate, eq_URI))
164         in
165         let c, other, eq_URI =
166           if pos = Utils.Left then left, right, HL.Logic.eq_ind_URI
167           else right, left, HL.Logic.eq_ind_r_URI
168         in
169         if o <> U.Incomparable then
170           try
171             do_match c other eq_URI
172           with e ->
173             find_matches metasenv context ugraph lift_amount term tl
174         else
175           let res = try do_match c other eq_URI with e -> None in
176           match res with
177           | Some (_, s, _, _, _) ->
178               let c' = (* M. *)apply_subst s c
179               and other' = (* M. *)apply_subst s other in
180               let order = cmp c' other' in
181               let names = U.names_of_context context in
182               if order = U.Gt then
183                 res
184               else
185                 find_matches metasenv context ugraph lift_amount term tl
186           | None ->
187               find_matches metasenv context ugraph lift_amount term tl
188 ;;
189
190
191 let rec find_all_matches ?(unif_fun=Inference.unification)
192     metasenv context ugraph lift_amount term =
193   let module C = Cic in
194   let module U = Utils in
195   let module S = CicSubstitution in
196   let module M = CicMetaSubst in
197   let module HL = HelmLibraryObjects in
198   let cmp = !Utils.compare_terms in
199   let names = Utils.names_of_context context in
200   function
201     | [] -> []
202     | candidate::tl ->
203         let pos, (proof, (ty, left, right, o), metas, args) = candidate in
204         let do_match c other eq_URI =
205           let subst', metasenv', ugraph' =
206             let t1 = Unix.gettimeofday () in
207             try
208               let r = 
209                 unif_fun (metasenv @ metas) context
210                   term (S.lift lift_amount c) ugraph in
211               let t2 = Unix.gettimeofday () in
212               match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
213               r
214             with e ->
215               let t2 = Unix.gettimeofday () in
216               match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
217               raise e
218           in
219           (C.Rel (1 + lift_amount), subst', metasenv', ugraph',
220            (candidate, eq_URI))
221         in
222         let c, other, eq_URI =
223           if pos = Utils.Left then left, right, HL.Logic.eq_ind_URI
224           else right, left, HL.Logic.eq_ind_r_URI
225         in
226         if o <> U.Incomparable then
227           try
228             let res = do_match c other eq_URI in
229             res::(find_all_matches ~unif_fun metasenv context ugraph
230                     lift_amount term tl)
231           with e ->
232             find_all_matches ~unif_fun metasenv context ugraph
233               lift_amount term tl
234         else
235           try
236             let res = do_match c other eq_URI in
237             match res with
238             | _, s, _, _, _ ->
239                 let c' = (* M. *)apply_subst s c
240                 and other' = (* M. *)apply_subst s other in
241                 let order = cmp c' other' in
242                 let names = U.names_of_context context in
243                 if order <> U.Lt && order <> U.Le then
244                   res::(find_all_matches ~unif_fun metasenv context ugraph
245                           lift_amount term tl)
246                 else
247                   find_all_matches ~unif_fun metasenv context ugraph
248                     lift_amount term tl
249           with e ->
250             find_all_matches ~unif_fun metasenv context ugraph
251               lift_amount term tl
252 ;;
253
254
255 let subsumption env table target =
256   let _, (ty, left, right, _), tmetas, _ = target in
257   let metasenv, context, ugraph = env in
258   let metasenv = metasenv @ tmetas in
259   let samesubst subst subst' =
260     let tbl = Hashtbl.create (List.length subst) in
261     List.iter (fun (m, (c, t1, t2)) -> Hashtbl.add tbl m (c, t1, t2)) subst;
262     List.for_all
263       (fun (m, (c, t1, t2)) ->
264          try
265            let c', t1', t2' = Hashtbl.find tbl m in
266            if (c = c') && (t1 = t1') && (t2 = t2') then true
267            else false
268          with Not_found ->
269            true)
270       subst'
271   in
272   let leftr =
273     match left with
274     | Cic.Meta _ -> []
275     | _ ->
276         let leftc = get_candidates Matching table left in
277         find_all_matches ~unif_fun:Inference.matching
278           metasenv context ugraph 0 left leftc
279   in
280   let ok what (_, subst, menv, ug, ((pos, (_, (_, l, r, o), _, _)), _)) =
281     try
282       let other = if pos = Utils.Left then r else l in
283       let subst', menv', ug' =
284         let t1 = Unix.gettimeofday () in
285         try
286           let r = 
287             Inference.matching metasenv context what other ugraph in
288           let t2 = Unix.gettimeofday () in
289           match_unif_time_ok := !match_unif_time_ok +. (t2 -. t1);
290           r
291         with e ->
292           let t2 = Unix.gettimeofday () in
293           match_unif_time_no := !match_unif_time_no +. (t2 -. t1);
294           raise e
295       in
296       samesubst subst subst'
297     with e ->
298       false
299   in
300   let r = List.exists (ok right) leftr in
301   if r then
302     true
303   else
304     let rightr =
305       match right with
306       | Cic.Meta _ -> []
307       | _ ->
308           let rightc = get_candidates Matching table right in
309           find_all_matches ~unif_fun:Inference.matching
310             metasenv context ugraph 0 right rightc
311     in
312     List.exists (ok left) rightr
313 ;;
314
315
316 let rec demodulate_term metasenv context ugraph table lift_amount term =
317   let module C = Cic in
318   let module S = CicSubstitution in
319   let module M = CicMetaSubst in
320   let module HL = HelmLibraryObjects in
321   let candidates = get_candidates Matching table term in
322   match term with
323   | C.Meta _ -> None
324   | term ->
325       let res =
326         find_matches metasenv context ugraph lift_amount term candidates
327       in
328       if res <> None then
329         res
330       else
331         match term with
332         | C.Appl l ->
333             let res, ll = 
334               List.fold_left
335                 (fun (res, tl) t ->
336                    if res <> None then
337                      (res, tl @ [S.lift 1 t])
338                    else 
339                      let r =
340                        demodulate_term metasenv context ugraph table
341                          lift_amount t
342                      in
343                      match r with
344                      | None -> (None, tl @ [S.lift 1 t])
345                      | Some (rel, _, _, _, _) -> (r, tl @ [rel]))
346                 (None, []) l
347             in (
348               match res with
349               | None -> None
350               | Some (_, subst, menv, ug, eq_found) ->
351                   Some (C.Appl ll, subst, menv, ug, eq_found)
352             )
353         | C.Prod (nn, s, t) ->
354             let r1 =
355               demodulate_term metasenv context ugraph table lift_amount s in (
356               match r1 with
357               | None ->
358                   let r2 =
359                     demodulate_term metasenv
360                       ((Some (nn, C.Decl s))::context) ugraph
361                       table (lift_amount+1) t
362                   in (
363                     match r2 with
364                     | None -> None
365                     | Some (t', subst, menv, ug, eq_found) ->
366                         Some (C.Prod (nn, (S.lift 1 s), t'),
367                               subst, menv, ug, eq_found)
368                   )
369               | Some (s', subst, menv, ug, eq_found) ->
370                   Some (C.Prod (nn, s', (S.lift 1 t)),
371                         subst, menv, ug, eq_found)
372             )
373         | t ->
374             None
375 ;;
376
377
378 let build_newtarget_time = ref 0.;;
379
380 let rec demodulation newmeta env table target =
381   let module C = Cic in
382   let module S = CicSubstitution in
383   let module M = CicMetaSubst in
384   let module HL = HelmLibraryObjects in
385   let metasenv, context, ugraph = env in
386   let proof, (eq_ty, left, right, order), metas, args = target in
387   let metasenv' = metasenv @ metas in
388   let build_newtarget is_left (t, subst, menv, ug, (eq_found, eq_URI)) =
389     let time1 = Unix.gettimeofday () in
390     
391     let pos, (proof', (ty, what, other, _), menv', args') = eq_found in
392     let what, other = if pos = Utils.Left then what, other else other, what in
393     let newterm, newproof =
394       let bo = (* M. *)apply_subst subst (S.subst other t) in
395       let bo'' =
396         C.Appl ([C.MutInd (HL.Logic.eq_URI, 0, []);
397                  S.lift 1 eq_ty] @
398                  if is_left then [bo; S.lift 1 right] else [S.lift 1 left; bo])
399       in
400       let t' = C.Lambda (C.Anonymous, ty, bo'') in
401       bo,
402       C.Implicit None
403 (*       (\* M. *\)apply_subst subst (C.Appl [C.Const (eq_URI, []); ty; what; t'; *)
404 (*                                    proof; other; proof']) *)
405     in
406     let left, right = if is_left then newterm, right else left, newterm in
407     let m =
408       (Inference.metas_of_term left) @ (Inference.metas_of_term right)
409     in
410     let newmetasenv = List.filter (fun (i, _, _) -> List.mem i m) metas
411     and newargs =
412       List.filter
413         (function C.Meta (i, _) -> List.mem i m | _ -> assert false)
414         args
415     in
416     let ordering = !Utils.compare_terms left right in
417
418     let time2 = Unix.gettimeofday () in
419     build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
420     
421     newmeta, (newproof, (eq_ty, left, right, ordering), newmetasenv, newargs)
422   in
423 (*   let build_newtarget = *)
424 (*     let profile = CicUtil.profile "Indexing.demodulation.build_newtarget" in *)
425 (*     (fun a b -> profile (build_newtarget a) b) *)
426 (*   in *)
427   let res = demodulate_term metasenv' context ugraph table 0 left in
428   let build_identity (p, (t, l, r, o), m, a) =
429     match o with
430     | Utils.Gt -> (p, (t, r, r, Utils.Eq), m, a)
431     | _ -> (p, (t, l, l, Utils.Eq), m, a)
432   in
433   match res with
434   | Some t ->
435       let newmeta, newtarget = build_newtarget true t in
436       if (Inference.is_identity (metasenv', context, ugraph) newtarget) ||
437         (Inference.meta_convertibility_eq target newtarget) then
438           newmeta, newtarget
439       else
440 (*         if subsumption env table newtarget then *)
441 (*           newmeta, build_identity newtarget *)
442 (*         else *)
443           demodulation newmeta env table newtarget
444   | None ->
445       let res = demodulate_term metasenv' context ugraph table 0 right in
446       match res with
447       | Some t ->
448           let newmeta, newtarget = build_newtarget false t in
449           if (Inference.is_identity (metasenv', context, ugraph) newtarget) ||
450             (Inference.meta_convertibility_eq target newtarget) then
451               newmeta, newtarget
452           else
453 (*             if subsumption env table newtarget then *)
454 (*               newmeta, build_identity newtarget *)
455 (*             else *)
456               demodulation newmeta env table newtarget
457       | None ->
458           newmeta, target
459 ;;
460
461
462 let rec betaexpand_term metasenv context ugraph table lift_amount term =
463   let module C = Cic in
464   let module S = CicSubstitution in
465   let module M = CicMetaSubst in
466   let module HL = HelmLibraryObjects in
467   let candidates = get_candidates Unification table term in
468   let res, lifted_term = 
469     match term with
470     | C.Meta (i, l) ->
471         let l', lifted_l = 
472           List.fold_right
473             (fun arg (res, lifted_tl) ->
474                match arg with
475                | Some arg ->
476                    let arg_res, lifted_arg =
477                      betaexpand_term metasenv context ugraph table
478                        lift_amount arg in
479                    let l1 =
480                      List.map
481                        (fun (t, s, m, ug, eq_found) ->
482                           (Some t)::lifted_tl, s, m, ug, eq_found)
483                        arg_res
484                    in
485                    (l1 @
486                       (List.map
487                          (fun (l, s, m, ug, eq_found) ->
488                             (Some lifted_arg)::l, s, m, ug, eq_found)
489                          res),
490                     (Some lifted_arg)::lifted_tl)
491                | None ->
492                    (List.map
493                       (fun (r, s, m, ug, eq_found) ->
494                          None::r, s, m, ug, eq_found) res, 
495                     None::lifted_tl)
496             ) l ([], [])
497         in
498         let e = 
499           List.map
500             (fun (l, s, m, ug, eq_found) ->
501                (C.Meta (i, l), s, m, ug, eq_found)) l'
502         in
503         e, C.Meta (i, lifted_l)
504           
505     | C.Rel m ->
506         [], if m <= lift_amount then C.Rel m else C.Rel (m+1)
507           
508     | C.Prod (nn, s, t) ->
509         let l1, lifted_s =
510           betaexpand_term metasenv context ugraph table lift_amount s in
511         let l2, lifted_t =
512           betaexpand_term metasenv ((Some (nn, C.Decl s))::context) ugraph
513             table (lift_amount+1) t in
514         let l1' =
515           List.map
516             (fun (t, s, m, ug, eq_found) ->
517                C.Prod (nn, t, lifted_t), s, m, ug, eq_found) l1
518         and l2' =
519           List.map
520             (fun (t, s, m, ug, eq_found) ->
521                C.Prod (nn, lifted_s, t), s, m, ug, eq_found) l2 in
522         l1' @ l2', C.Prod (nn, lifted_s, lifted_t)
523           
524     | C.Appl l ->
525         let l', lifted_l =
526           List.fold_right
527             (fun arg (res, lifted_tl) ->
528                let arg_res, lifted_arg =
529                  betaexpand_term metasenv context ugraph table lift_amount arg
530                in
531                let l1 =
532                  List.map
533                    (fun (a, s, m, ug, eq_found) ->
534                       a::lifted_tl, s, m, ug, eq_found)
535                    arg_res
536                in
537                (l1 @
538                   (List.map
539                      (fun (r, s, m, ug, eq_found) ->
540                         lifted_arg::r, s, m, ug, eq_found)
541                      res),
542                 lifted_arg::lifted_tl)
543             ) l ([], [])
544         in
545         (List.map
546            (fun (l, s, m, ug, eq_found) -> (C.Appl l, s, m, ug, eq_found)) l',
547          C.Appl lifted_l)
548
549     | t -> [], (S.lift lift_amount t)
550   in
551   match term with
552   | C.Meta _ -> res, lifted_term
553   | term ->
554       let r = 
555         find_all_matches metasenv context ugraph lift_amount term candidates
556       in
557       r @ res, lifted_term
558 ;;
559
560
561 let superposition_left (metasenv, context, ugraph) table target =
562   let module C = Cic in
563   let module S = CicSubstitution in
564   let module M = CicMetaSubst in
565   let module HL = HelmLibraryObjects in
566   let module CR = CicReduction in
567   let module U = Utils in
568   let proof, (eq_ty, left, right, ordering), _, _ = target in
569   let expansions, _ =
570     let term = if ordering = U.Gt then left else right in
571     betaexpand_term metasenv context ugraph table 0 term
572   in
573   let build_new (bo, s, m, ug, (eq_found, eq_URI)) =
574     let time1 = Unix.gettimeofday () in
575     
576     let pos, (proof', (ty, what, other, _), menv', args') = eq_found in
577     let what, other = if pos = Utils.Left then what, other else other, what in
578     let newgoal, newproof =
579       let bo' = (* M. *)apply_subst s (S.subst other bo) in
580       let bo'' =
581         C.Appl (
582           [C.MutInd (HL.Logic.eq_URI, 0, []);
583            S.lift 1 eq_ty] @
584             if ordering = U.Gt then [bo'; S.lift 1 right]
585             else [S.lift 1 left; bo'])
586       in
587       let t' = C.Lambda (C.Anonymous, ty, bo'') in
588       bo',
589       C.Implicit None
590 (*       (\* M. *\)apply_subst s *)
591 (*         (C.Appl [C.Const (eq_URI, []); ty; what; t'; *)
592 (*                  proof; other; proof']) *)
593     in
594     let left, right =
595       if ordering = U.Gt then newgoal, right else left, newgoal in
596     let neworder = !Utils.compare_terms left right in
597
598     let time2 = Unix.gettimeofday () in
599     build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
600     
601     (newproof, (eq_ty, left, right, neworder), [], [])
602   in
603 (*   let build_new = *)
604 (*     let profile = CicUtil.profile "Inference.superposition_left.build_new" in *)
605 (*     (fun e -> profile build_new e) *)
606 (*   in *)
607   List.map build_new expansions
608 ;;
609
610
611 let superposition_right newmeta (metasenv, context, ugraph) table target =
612   let module C = Cic in
613   let module S = CicSubstitution in
614   let module M = CicMetaSubst in
615   let module HL = HelmLibraryObjects in
616   let module CR = CicReduction in
617   let module U = Utils in
618   let eqproof, (eq_ty, left, right, ordering), newmetas, args = target in
619   let metasenv' = metasenv @ newmetas in
620   let maxmeta = ref newmeta in
621   let res1, res2 =
622     match ordering with
623     | U.Gt -> fst (betaexpand_term metasenv' context ugraph table 0 left), []
624     | U.Lt -> [], fst (betaexpand_term metasenv' context ugraph table 0 right)
625     | _ ->
626         let res l r =
627           List.filter
628             (fun (_, subst, _, _, _) ->
629                let subst = (* M. *)apply_subst subst in
630                let o = !Utils.compare_terms (subst l) (subst r) in
631                o <> U.Lt && o <> U.Le)
632             (fst (betaexpand_term metasenv' context ugraph table 0 l))
633         in
634         (res left right), (res right left)
635   in
636   let build_new ordering (bo, s, m, ug, (eq_found, eq_URI)) =
637
638     let time1 = Unix.gettimeofday () in
639     
640     let pos, (proof', (ty, what, other, _), menv', args') = eq_found in
641     let what, other = if pos = Utils.Left then what, other else other, what in
642     let newgoal, newproof =
643       let bo' = (* M. *)apply_subst s (S.subst other bo) in
644       let bo'' =
645         C.Appl (
646           [C.MutInd (HL.Logic.eq_URI, 0, []); S.lift 1 eq_ty] @
647             if ordering = U.Gt then [bo'; S.lift 1 right]
648             else [S.lift 1 left; bo'])
649       in
650       let t' = C.Lambda (C.Anonymous, ty, bo'') in
651       bo',
652       C.Implicit None
653 (*       (\* M. *\)apply_subst s *)
654 (*         (C.Appl [C.Const (eq_URI, []); ty; what; t'; *)
655 (*                  eqproof; other; proof']) *)
656     in
657     let newmeta, newequality = 
658       let left, right =
659         if ordering = U.Gt then newgoal, (* M. *)apply_subst s right
660         else (* M. *)apply_subst s left, newgoal in
661       let neworder = !Utils.compare_terms left right 
662       and newmenv = newmetas @ menv'
663       and newargs = args @ args' in
664       let eq' = (newproof, (eq_ty, left, right, neworder), newmenv, newargs)
665       and env = (metasenv, context, ugraph) in
666       let newm, eq' = Inference.fix_metas !maxmeta eq' in
667       newm, eq'
668     in
669     maxmeta := newmeta;
670
671     let time2 = Unix.gettimeofday () in
672     build_newtarget_time := !build_newtarget_time +. (time2 -. time1);
673     
674     newequality
675   in
676
677 (*   let build_new = *)
678 (*     let profile = CicUtil.profile "Indexing.superposition_right.build_new" in *)
679 (*     (fun o e -> profile (build_new o) e) *)
680 (*   in *)
681   
682   let new1 = List.map (build_new U.Gt) res1
683   and new2 = List.map (build_new U.Lt) res2 in
684   let ok = function
685     | _, (_, left, right, _), _, _ ->
686         not (fst (CR.are_convertible context left right ugraph))
687   in
688   (!maxmeta,
689    (List.filter ok (new1 @ new2)))
690 ;;