2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: index.mli 9822 2009-06-03 15:37:06Z tassi $ *)
14 module Superposition (B : Orderings.Blob) =
16 module IDX = Index.Index(B)
17 module Unif = FoUnif.Founif(B)
18 module Subst = FoSubst
20 module Utils = FoUtils.Utils(B)
23 exception Success of B.t Terms.bag * int * B.t Terms.unit_clause
25 (* let debug s = prerr_endline (Lazy.force s);; *)
29 let rec list_first f = function
31 | x::tl -> match f x with Some _ as x -> x | _ -> list_first f tl
34 let first_position pos ctx t f =
35 let inject_pos pos ctx = function
37 | Some (a,b,c,d) -> Some(ctx a,b,c,d,pos)
39 let rec aux pos ctx = function
40 | Terms.Leaf _ as t -> inject_pos pos ctx (f t)
44 | Some _ as x -> inject_pos pos ctx x
46 let rec first pre post = function
49 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
50 match aux (List.length pre :: pos) newctx t with
53 if post = [] then None (* tl is also empty *)
54 else first (pre @ [t]) (List.tl post) tl
56 first [] (List.tl l) l
61 let all_positions pos ctx t f =
62 let rec aux pos ctx = function
63 | Terms.Leaf _ as t -> f t pos ctx
68 (fun (acc,pre,post) t -> (* Invariant: pre @ [t] @ post = l *)
69 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
70 let acc = aux (List.length pre :: pos) newctx t @ acc in
71 if post = [] then acc, l, []
72 else acc, pre @ [t], List.tl post)
73 (f t pos ctx, [], List.tl l) l
80 let parallel_positions bag pos ctx id t f =
81 let rec aux bag pos ctx id = function
82 | Terms.Leaf _ as t -> f bag t pos ctx id
83 | Terms.Var _ as t -> bag,t,id
84 | Terms.Node (hd::l) as t->
85 let bag,t,id1 = f bag t pos ctx id in
89 (fun (bag,pre,post,id) t ->
90 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
91 let newpos = (List.length pre)::pos in
92 let bag,newt,id = aux bag newpos newctx id t in
93 if post = [] then bag, pre@[newt], [], id
94 else bag, pre @ [newt], List.tl post, id)
95 (bag, [hd], List.tl l, id) l
99 (* else aux bag pos ctx id1 t *)
105 let visit bag pos ctx id t f =
106 let rec aux bag pos ctx id subst = function
107 | Terms.Leaf _ as t ->
108 let bag,subst,t,id = f bag t pos ctx id
109 in assert (subst=[]); bag,t,id
110 | Terms.Var i as t ->
111 let t= Subst.apply_subst subst t in
113 | Terms.Node (hd::l) ->
116 (fun (bag,pre,post,id) t ->
117 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
118 let newpos = (List.length pre)::pos in
119 let bag,newt,id = aux bag newpos newctx id subst t in
120 if post = [] then bag, pre@[newt], [], id
121 else bag, pre @ [newt], List.tl post, id)
122 (bag, [hd], List.map (Subst.apply_subst subst) (List.tl l), id) l
124 let bag,subst,t,id1 = f bag (Terms.Node l) pos ctx id
126 if id1 = id then (assert (subst=[]); bag,t,id)
127 else aux bag pos ctx id1 subst t
130 aux bag pos ctx id [] t
133 let build_clause bag filter rule t subst id id2 pos dir =
134 let proof = Terms.Step(rule,id,id2,dir,pos,subst) in
135 let t = Subst.apply_subst subst t in
139 | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq ->
140 let o = Order.compare_terms l r in
141 Terms.Equation (l, r, ty, o)
142 | t -> Terms.Predicate t
145 Terms.add_to_bag (0, literal, Terms.vars_of_term t, proof) bag
149 ((*prerr_endline ("Filtering: " ^ Pp.pp_foterm t);*)None)
151 let prof_build_clause = HExtlib.profile ~enable "build_clause";;
152 let build_clause bag filter rule t subst id id2 pos x =
153 prof_build_clause.HExtlib.profile (build_clause bag filter rule t subst id id2 pos) x
157 (* ============ simplification ================= *)
158 let prof_demod_u = HExtlib.profile ~enable "demod.unify";;
159 let prof_demod_r = HExtlib.profile ~enable "demod.retrieve_generalizations";;
160 let prof_demod_o = HExtlib.profile ~enable "demod.compare_terms";;
161 let prof_demod_s = HExtlib.profile ~enable "demod.apply_subst";;
163 let demod table varlist subterm =
165 prof_demod_r.HExtlib.profile
166 (IDX.DT.retrieve_generalizations table) subterm
169 (fun (dir, (id,lit,vl,_)) ->
171 | Terms.Predicate _ -> assert false
172 | Terms.Equation (l,r,_,o) ->
173 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
176 prof_demod_u.HExtlib.profile
177 (Unif.unification (* (varlist@vl) *) varlist subterm) side
180 prof_demod_s.HExtlib.profile
181 (Subst.apply_subst subst) side
184 prof_demod_s.HExtlib.profile
185 (Subst.apply_subst subst) newside
187 if o = Terms.Incomparable || o = Terms.Invertible then
189 prof_demod_o.HExtlib.profile
190 (Order.compare_terms newside) side in
191 (* Riazanov, pp. 45 (ii) *)
193 Some (newside, subst, id, dir)
195 ((*prerr_endline ("Filtering: " ^
196 Pp.pp_foterm side ^ " =(< || =)" ^
197 Pp.pp_foterm newside ^ " coming from " ^
198 Pp.pp_unit_clause uc );*)None)
200 Some (newside, subst, id, dir)
201 with FoUnif.UnificationFailure _ -> None)
202 (IDX.ClauseSet.elements cands)
204 let prof_demod = HExtlib.profile ~enable "demod";;
205 let demod table varlist x =
206 prof_demod.HExtlib.profile (demod table varlist) x
209 let mydemod table varlist subterm =
211 prof_demod_r.HExtlib.profile
212 (IDX.DT.retrieve_generalizations table) subterm
215 (fun (dir, ((id,lit,vl,_) as c)) ->
216 debug (lazy("candidate: "
217 ^ Pp.pp_unit_clause c));
219 | Terms.Predicate _ -> assert false
220 | Terms.Equation (l,r,_,o) ->
221 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
224 prof_demod_u.HExtlib.profile
225 (Unif.unification (* (varlist@vl) *) varlist subterm) side
228 prof_demod_s.HExtlib.profile
229 (Subst.apply_subst subst) side
232 prof_demod_s.HExtlib.profile
233 (Subst.apply_subst subst) newside
235 if o = Terms.Incomparable || o = Terms.Invertible then
237 prof_demod_o.HExtlib.profile
238 (Order.compare_terms inewside) iside in
239 (* Riazanov, pp. 45 (ii) *)
241 Some (newside, subst, id, dir)
243 ((*prerr_endline ("Filtering: " ^
244 Pp.pp_foterm side ^ " =(< || =)" ^
245 Pp.pp_foterm newside ^ " coming from " ^
246 Pp.pp_unit_clause uc );*)None)
248 Some (newside, subst, id, dir)
249 with FoUnif.UnificationFailure _ -> None)
250 (IDX.ClauseSet.elements cands)
253 let ctx_demod table vl bag t pos ctx id =
254 match mydemod table vl t with
255 | None -> (bag,[],t,id)
256 | Some (newside, subst, id2, dir) ->
257 let inewside = Subst.apply_subst subst newside in
258 match build_clause bag (fun _ -> true)
259 Terms.Demodulation (ctx inewside) subst id id2 pos dir
261 | None -> assert false
262 | Some (bag,(id,_,_,_)) ->
263 (bag,subst,newside,id)
266 let rec demodulate bag (id, literal, vl, pr) table =
267 debug (lazy "demodulate...");
269 | Terms.Predicate t -> assert false
270 | Terms.Equation (l,r,ty,_) ->
273 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) id l
278 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) id1 r
281 let cl,_,_ = Terms.get_from_bag id2 bag in
285 let parallel_demod table vl bag t pos ctx id =
286 match demod table vl t with
288 | Some (newside, subst, id2, dir) ->
289 match build_clause bag (fun _ -> true)
290 Terms.Demodulation (ctx newside) subst id id2 pos dir
292 | None -> assert false
293 | Some (bag,(id,_,_,_)) ->
297 let are_alpha_eq cl1 cl2 =
298 let get_term (_,lit,_,_) =
300 | Terms.Predicate _ -> assert false
301 | Terms.Equation (l,r,ty,_) ->
302 Terms.Node [Terms.Leaf B.eqP; ty; l ; r]
304 try ignore(Unif.alpha_eq (get_term cl1) (get_term cl2)) ; true
305 with FoUnif.UnificationFailure _ -> false
308 let prof_demodulate = HExtlib.profile ~enable "demodulate";;
309 let demodulate bag clause x =
310 prof_demodulate.HExtlib.profile (demodulate bag clause) x
314 let is_identity_clause ~unify = function
315 | _, Terms.Equation (_,_,_,Terms.Eq), _, _ -> true
316 | _, Terms.Equation (l,r,_,_), vl, proof when unify ->
317 (try ignore(Unif.unification (* vl *) [] l r); true
318 with FoUnif.UnificationFailure _ -> false)
319 | _, Terms.Equation (_,_,_,_), _, _ -> false
320 | _, Terms.Predicate _, _, _ -> assert false
323 let build_new_clause bag maxvar filter rule t subst id id2 pos dir =
324 let maxvar, _vl, subst = Utils.relocate maxvar (Terms.vars_of_term
325 (Subst.apply_subst subst t)) subst in
326 match build_clause bag filter rule t subst id id2 pos dir with
327 | Some (bag, c) -> Some ((bag, maxvar), c)
330 let prof_build_new_clause = HExtlib.profile ~enable "build_new_clause";;
331 let build_new_clause bag maxvar filter rule t subst id id2 pos x =
332 prof_build_new_clause.HExtlib.profile (build_new_clause bag maxvar filter
333 rule t subst id id2 pos) x
336 let fold_build_new_clause bag maxvar id rule filter res =
337 let (bag, maxvar), res =
338 HExtlib.filter_map_acc
339 (fun (bag, maxvar) (t,subst,id2,pos,dir) ->
340 build_new_clause bag maxvar filter rule t subst id id2 pos dir)
347 let rewrite_eq ~unify l r ty vl table =
348 let retrieve = if unify then IDX.DT.retrieve_unifiables
349 else IDX.DT.retrieve_generalizations in
350 let lcands = retrieve table l in
351 let rcands = retrieve table r in
353 let id, dir, l, r, vl =
355 | (d, (id,Terms.Equation (l,r,ty,_),vl,_))-> id, d, l, r, vl
358 let reverse = (dir = Terms.Left2Right) = b in
359 let l, r, proof_rewrite_dir = if reverse then l,r,Terms.Left2Right
360 else r,l, Terms.Right2Left in
361 (id,proof_rewrite_dir,Terms.Node [ Terms.Leaf B.eqP; ty; l; r ], vl)
363 let cands1 = List.map (f true) (IDX.ClauseSet.elements lcands) in
364 let cands2 = List.map (f false) (IDX.ClauseSet.elements rcands) in
365 let t = Terms.Node [ Terms.Leaf B.eqP; ty; l; r ] in
366 let locked_vars = if unify then [] else vl in
367 let rec aux = function
369 | (id2,dir,c,vl1)::tl ->
371 let subst = Unif.unification (* (vl@vl1) *) locked_vars c t in
372 Some (id2, dir, subst)
373 with FoUnif.UnificationFailure _ -> aux tl
375 aux (cands1 @ cands2)
378 let is_subsumed ~unify bag maxvar (id, lit, vl, _) table =
380 | Terms.Predicate _ -> assert false
381 | Terms.Equation (l,r,ty,_) ->
382 match rewrite_eq ~unify l r ty vl table with
384 | Some (id2, dir, subst) ->
385 let id_t = Terms.Node [ Terms.Leaf B.eqP; ty; r; r ] in
386 build_new_clause bag maxvar (fun _ -> true)
387 Terms.Superposition id_t subst id id2 [2] dir
389 let prof_is_subsumed = HExtlib.profile ~enable "is_subsumed";;
390 let is_subsumed ~unify bag maxvar c x =
391 prof_is_subsumed.HExtlib.profile (is_subsumed ~unify bag maxvar c) x
393 (* id refers to a clause proving contextl l = contextr r *)
395 let rec deep_eq ~unify l r ty pos contextl contextr table acc =
398 | Some(bag,maxvar,(id,lit,vl,p),subst) ->
399 let l = Subst.apply_subst subst l in
400 let r = Subst.apply_subst subst r in
402 let subst1 = Unif.unification (* vl *) [] l r in
404 match lit with Terms.Predicate _ -> assert false
405 | Terms.Equation (l,r,ty,o) ->
406 Terms.Equation (FoSubst.apply_subst subst1 l,
407 FoSubst.apply_subst subst1 r, ty, o)
409 Some(bag,maxvar,(id,lit,vl,p),Subst.concat subst1 subst)
410 with FoUnif.UnificationFailure _ ->
411 match rewrite_eq ~unify l r ty vl table with
412 | Some (id2, dir, subst1) ->
413 let newsubst = Subst.concat subst1 subst in
415 FoSubst.apply_subst newsubst
416 (Terms.Node[Terms.Leaf B.eqP;ty;contextl r;contextr r])
419 build_new_clause bag maxvar (fun _ -> true)
420 Terms.Superposition id_t
421 subst1 id id2 (pos@[2]) dir
423 | Some ((bag, maxvar), c) ->
424 Some(bag,maxvar,c,newsubst)
425 | None -> assert false)
428 | Terms.Node (a::la), Terms.Node (b::lb) when
429 a = b && List.length la = List.length lb ->
432 (fun (acc,pre,postl,postr) a b ->
434 fun x -> contextl(Terms.Node (pre@(x::postl))) in
436 fun x -> contextr(Terms.Node (pre@(x::postr))) in
437 let newpos = List.length pre::pos in
439 if l = [] then [] else List.tl l in
440 (deep_eq ~unify a b ty
441 newpos newcl newcr table acc,pre@[b],
442 footail postl, footail postr))
443 (acc,[a],List.tl la,List.tl lb) la lb
447 let prof_deep_eq = HExtlib.profile ~enable "deep_eq";;
448 let deep_eq ~unify l r ty pos contextl contextr table x =
449 prof_deep_eq.HExtlib.profile (deep_eq ~unify l r ty pos contextl contextr table) x
452 let rec orphan_murder bag acc i =
453 match Terms.get_from_bag i bag with
454 | (_,_,_,Terms.Exact _),discarded,_ -> (discarded,acc)
455 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)),true,_ -> (true,acc)
456 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)),false,_ ->
457 if (List.mem i acc) then (false,acc)
458 else match orphan_murder bag acc i1 with
459 | (true,acc) -> (true,acc)
461 let (res,acc) = orphan_murder bag acc i2 in
462 if res then res,acc else res,i::acc
465 let orphan_murder bag actives cl =
466 let (id,_,_,_) = cl in
467 let actives = List.map (fun (i,_,_,_) -> i) actives in
468 let (res,_) = orphan_murder bag actives id in
469 if res then debug (lazy "Orphan murdered"); res
471 let prof_orphan_murder = HExtlib.profile ~enable "orphan_murder";;
472 let orphan_murder bag actives x =
473 prof_orphan_murder.HExtlib.profile (orphan_murder bag actives) x
476 (* demodulate and check for subsumption *)
477 let simplify table maxvar bag clause =
478 debug (lazy "simplify...");
479 if is_identity_clause ~unify:false clause then bag,None
480 (* else if orphan_murder bag actives clause then bag,None *)
481 else let bag, clause = demodulate bag clause table in
482 if is_identity_clause ~unify:false clause then bag,None
484 match is_subsumed ~unify:false bag maxvar clause table with
485 | None -> bag, Some clause
486 | Some _ -> bag, None
489 let simplify table maxvar bag clause =
490 match simplify table maxvar bag clause with
492 let (id,_,_,_) = clause in
493 let (_,_,iter) = Terms.get_from_bag id bag in
494 Terms.replace_in_bag (clause,true,iter) bag, None
495 | bag, Some clause -> bag, Some clause
496 (*let (id,_,_,_) = clause in
497 if orphan_murder bag clause then
498 Terms.M.add id (clause,true) bag, Some clause
499 else bag, Some clause*)
501 let prof_simplify = HExtlib.profile ~enable "simplify";;
502 let simplify table maxvar bag x =
503 prof_simplify.HExtlib.profile (simplify table maxvar bag ) x
506 let one_pass_simplification new_clause (alist,atable) bag maxvar =
507 match simplify atable maxvar bag new_clause with
508 | bag,None -> bag,None (* new_clause has been discarded *)
509 | bag,(Some clause) ->
510 let ctable = IDX.index_unit_clause IDX.DT.empty clause in
511 let bag, alist, atable =
513 (fun (bag, alist, atable) c ->
514 match simplify ctable maxvar bag c with
515 |bag,None -> (bag,alist,atable)
516 (* an active clause as been discarded *)
518 bag, c :: alist, IDX.index_unit_clause atable c)
519 (bag,[],IDX.DT.empty) alist
521 bag, Some (clause, (alist,atable))
523 let prof_one_pass_simplification = HExtlib.profile ~enable "one_pass_simplification";;
524 let one_pass_simplification new_clause t bag x =
525 prof_one_pass_simplification.HExtlib.profile (one_pass_simplification new_clause t bag ) x
528 let simplification_step ~new_cl cl (alist,atable) bag maxvar new_clause =
530 if new_cl then atable else
531 IDX.index_unit_clause atable cl
533 (* Simplification of new_clause with : *
534 * - actives and cl if new_clause is not cl *
535 * - only actives otherwise *)
537 simplify atable1 maxvar bag new_clause with
538 | bag,None -> bag,(Some cl, None) (* new_clause has been discarded *)
540 (* Simplification of each active clause with clause *
541 * which is the simplified form of new_clause *)
542 let ctable = IDX.index_unit_clause IDX.DT.empty clause in
543 let bag, newa, alist, atable =
545 (fun (bag, newa, alist, atable) c ->
546 match simplify ctable maxvar bag c with
547 |bag,None -> (bag, newa, alist, atable)
548 (* an active clause as been discarded *)
551 bag, newa, c :: alist,
552 IDX.index_unit_clause atable c
554 bag, c1 :: newa, alist, atable)
555 (bag,[],[],IDX.DT.empty) alist
558 bag, (Some cl, Some (clause, (alist,atable), newa))
560 (* if new_clause is not cl, we simplify cl with clause *)
561 match simplify ctable maxvar bag cl with
563 (* cl has been discarded *)
564 bag,(None, Some (clause, (alist,atable), newa))
566 bag,(Some cl1, Some (clause, (alist,atable), newa))
568 let prof_simplification_step = HExtlib.profile ~enable "simplification_step";;
569 let simplification_step ~new_cl cl (alist,atable) bag maxvar x =
570 prof_simplification_step.HExtlib.profile (simplification_step ~new_cl cl (alist,atable) bag maxvar) x
573 let keep_simplified cl (alist,atable) bag maxvar =
574 let rec keep_simplified_aux ~new_cl cl (alist,atable) bag newc =
576 match simplification_step ~new_cl cl (alist,atable) bag maxvar cl with
577 | _,(None, _) -> assert false
578 | bag,(Some _, None) -> bag,None
579 | bag,(Some _, Some (clause, (alist,atable), newa)) ->
580 keep_simplified_aux ~new_cl:(cl!=clause) clause (alist,atable)
584 | [] -> bag, Some (cl, (alist,atable))
586 match simplification_step ~new_cl cl
587 (alist,atable) bag maxvar hd with
588 | _,(None,None) -> assert false
589 | bag,(Some _,None) ->
590 keep_simplified_aux ~new_cl cl (alist,atable) bag tl
591 | bag,(None, Some _) -> bag,None
592 | bag,(Some cl1, Some (clause, (alist,atable), newa)) ->
594 (clause::alist, IDX.index_unit_clause atable clause)
596 keep_simplified_aux ~new_cl:(cl!=cl1) cl1 (alist,atable)
599 keep_simplified_aux ~new_cl:true cl (alist,atable) bag []
601 let prof_keep_simplified = HExtlib.profile ~enable "keep_simplified";;
602 let keep_simplified cl t bag x =
603 prof_keep_simplified.HExtlib.profile (keep_simplified cl t bag) x
606 (* this is like simplify but raises Success *)
607 let simplify_goal ~no_demod maxvar table bag g_actives clause =
609 if no_demod then bag, clause else demodulate bag clause table
611 if List.exists (are_alpha_eq clause) g_actives then None
612 else if (is_identity_clause ~unify:true clause)
613 then raise (Success (bag, maxvar, clause))
615 let (id,lit,vl,_) = clause in
616 if vl = [] then Some (bag,clause)
620 | Terms.Equation(l,r,ty,_) -> l,r,ty
623 match deep_eq ~unify:true l r ty [] (fun x -> x) (fun x -> x)
624 table (Some(bag,maxvar,clause,Subst.id_subst)) with
625 | None -> Some (bag,clause)
626 | Some (bag,maxvar,cl,subst) ->
627 prerr_endline "Goal subsumed";
628 raise (Success (bag,maxvar,cl))
630 else match is_subsumed ~unify:true bag maxvar clause table with
631 | None -> Some (bag, clause)
632 | Some ((bag,maxvar),c) ->
633 prerr_endline "Goal subsumed";
634 raise (Success (bag,maxvar,c))
638 let prof_simplify_goal = HExtlib.profile ~enable "simplify_goal";;
639 let simplify_goal ~no_demod maxvar table bag g_actives x =
640 prof_simplify_goal.HExtlib.profile ( simplify_goal ~no_demod maxvar table bag g_actives) x
643 (* =================== inference ===================== *)
645 (* this is OK for both the sup_left and sup_right inference steps *)
646 let superposition table varlist subterm pos context =
647 let cands = IDX.DT.retrieve_unifiables table subterm in
649 (fun (dir, (id,lit,vl,_ (*as uc*))) ->
651 | Terms.Predicate _ -> assert false
652 | Terms.Equation (l,r,_,o) ->
653 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
656 Unif.unification (* (varlist@vl)*) [] subterm side
658 if o = Terms.Incomparable || o = Terms.Invertible then
659 let side = Subst.apply_subst subst side in
660 let newside = Subst.apply_subst subst newside in
661 let o = Order.compare_terms side newside in
662 (* XXX: check Riazanov p. 33 (iii) *)
663 if o <> Terms.Lt && o <> Terms.Eq then
664 Some (context newside, subst, id, pos, dir)
666 ((*prerr_endline ("Filtering: " ^
667 Pp.pp_foterm side ^ " =(< || =)" ^
668 Pp.pp_foterm newside);*)None)
670 Some (context newside, subst, id, pos, dir)
671 with FoUnif.UnificationFailure _ -> None)
672 (IDX.ClauseSet.elements cands)
675 (* Superposes selected equation with equalities in table *)
676 let superposition_with_table bag maxvar (id,selected,vl,_) table =
678 | Terms.Predicate _ -> assert false
679 | Terms.Equation (l,r,ty,Terms.Lt) ->
680 fold_build_new_clause bag maxvar id Terms.Superposition
683 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
684 r (superposition table vl))
685 | Terms.Equation (l,r,ty,Terms.Invertible)
686 | Terms.Equation (l,r,ty,Terms.Gt) ->
687 fold_build_new_clause bag maxvar id Terms.Superposition
690 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ])
691 l (superposition table vl))
692 | Terms.Equation (l,r,ty,Terms.Incomparable) ->
693 let filtering avoid subst = (* Riazanov: p.33 condition (iv) *)
694 let l = Subst.apply_subst subst l in
695 let r = Subst.apply_subst subst r in
696 let o = Order.compare_terms l r in
697 o <> avoid && o <> Terms.Eq
699 let bag, maxvar,r_terms =
700 fold_build_new_clause bag maxvar id Terms.Superposition
703 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
704 r (superposition table vl))
706 let bag, maxvar, l_terms =
707 fold_build_new_clause bag maxvar id Terms.Superposition
710 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ])
711 l (superposition table vl))
713 bag, maxvar, r_terms @ l_terms
717 (* the current equation is normal w.r.t. demodulation with atable
718 * (and is not the identity) *)
719 let infer_right bag maxvar current (alist,atable) =
720 (* We demodulate actives clause with current until all *
721 * active clauses are reduced w.r.t each other *)
722 (* let bag, (alist,atable) = keep_simplified (alist,atable) bag [current] in *)
723 let ctable = IDX.index_unit_clause IDX.DT.empty current in
724 (* let bag, (alist, atable) =
726 HExtlib.filter_map_acc (simplify ctable) bag alist
728 bag, (alist, List.fold_left IDX.index_unit_clause IDX.DT.empty alist)
730 debug (lazy "Simplified active clauses with fact");
731 (* We superpose active clauses with current *)
732 let bag, maxvar, new_clauses =
734 (fun (bag, maxvar, acc) active ->
735 let bag, maxvar, newc =
736 superposition_with_table bag maxvar active ctable
738 bag, maxvar, newc @ acc)
739 (bag, maxvar, []) alist
741 debug (lazy "First superpositions");
742 (* We add current to active clauses so that it can be *
743 * superposed with itself *)
745 current :: alist, IDX.index_unit_clause atable current
747 debug (lazy "Indexed");
748 let fresh_current, maxvar = Utils.fresh_unit_clause maxvar current in
749 (* We need to put fresh_current into the bag so that all *
750 * variables clauses refer to are known. *)
751 let bag, fresh_current = Terms.add_to_bag fresh_current bag in
752 (* We superpose current with active clauses *)
753 let bag, maxvar, additional_new_clauses =
754 superposition_with_table bag maxvar fresh_current atable
756 debug (lazy "Another superposition");
757 let new_clauses = new_clauses @ additional_new_clauses in
758 (* debug (lazy (Printf.sprintf "Demodulating %d clauses"
759 (List.length new_clauses))); *)
760 let bag, new_clauses =
761 HExtlib.filter_map_monad (simplify atable maxvar) bag new_clauses
763 debug (lazy "Demodulated new clauses");
764 bag, maxvar, (alist, atable), new_clauses
767 let prof_ir = HExtlib.profile ~enable "infer_right";;
768 let infer_right bag maxvar current t =
769 prof_ir.HExtlib.profile (infer_right bag maxvar current) t
772 let infer_left bag maxvar goal (_alist, atable) =
773 (* We superpose the goal with active clauses *)
774 if (match goal with (_,_,[],_) -> true | _ -> false) then bag, maxvar, []
776 let bag, maxvar, new_goals =
777 superposition_with_table bag maxvar goal atable
779 debug(lazy "Superposed goal with active clauses");
780 (* We simplify the new goals with active clauses *)
784 match simplify_goal ~no_demod:false maxvar atable bag [] g with
785 | None -> assert false
786 | Some (bag,g) -> bag,g::acc)
789 debug (lazy "Simplified new goals with active clauses");
790 bag, maxvar, List.rev new_goals
793 let prof_il = HExtlib.profile ~enable "infer_left";;
794 let infer_left bag maxvar goal t =
795 prof_il.HExtlib.profile (infer_left bag maxvar goal) t