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 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
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, [], List.tl l, id) l
103 let build_clause bag filter rule t subst id id2 pos dir =
104 let proof = Terms.Step(rule,id,id2,dir,pos,subst) in
105 let t = Subst.apply_subst subst t in
109 | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq ->
110 let o = Order.compare_terms l r in
111 Terms.Equation (l, r, ty, o)
112 | t -> Terms.Predicate t
115 Terms.add_to_bag (0, literal, Terms.vars_of_term t, proof) bag
119 ((*prerr_endline ("Filtering: " ^ Pp.pp_foterm t);*)None)
121 let prof_build_clause = HExtlib.profile ~enable "build_clause";;
122 let build_clause bag filter rule t subst id id2 pos x =
123 prof_build_clause.HExtlib.profile (build_clause bag filter rule t subst id id2 pos) x
127 (* ============ simplification ================= *)
128 let prof_demod_u = HExtlib.profile ~enable "demod.unify";;
129 let prof_demod_r = HExtlib.profile ~enable "demod.retrieve_generalizations";;
130 let prof_demod_o = HExtlib.profile ~enable "demod.compare_terms";;
131 let prof_demod_s = HExtlib.profile ~enable "demod.apply_subst";;
133 let demod table varlist subterm =
135 prof_demod_r.HExtlib.profile
136 (IDX.DT.retrieve_generalizations table) subterm
139 (fun (dir, (id,lit,vl,_)) ->
141 | Terms.Predicate _ -> assert false
142 | Terms.Equation (l,r,_,o) ->
143 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
146 prof_demod_u.HExtlib.profile
147 (Unif.unification (* (varlist@vl) *) varlist subterm) side
150 prof_demod_s.HExtlib.profile
151 (Subst.apply_subst subst) side
154 prof_demod_s.HExtlib.profile
155 (Subst.apply_subst subst) newside
157 if o = Terms.Incomparable then
159 prof_demod_o.HExtlib.profile
160 (Order.compare_terms newside) side in
161 (* Riazanov, pp. 45 (ii) *)
163 Some (newside, subst, id, dir)
165 ((*prerr_endline ("Filtering: " ^
166 Pp.pp_foterm side ^ " =(< || =)" ^
167 Pp.pp_foterm newside ^ " coming from " ^
168 Pp.pp_unit_clause uc );*)None)
170 Some (newside, subst, id, dir)
171 with FoUnif.UnificationFailure _ -> None)
172 (IDX.ClauseSet.elements cands)
174 let prof_demod = HExtlib.profile ~enable "demod";;
175 let demod table varlist x =
176 prof_demod.HExtlib.profile (demod table varlist) x
179 let demodulate_once_old ~jump_to_right bag (id, literal, vl, pr) table =
181 | Terms.Predicate t -> assert false
182 | Terms.Equation (l,r,ty,_) ->
183 let left_position = if jump_to_right then None else
185 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) l
188 match left_position with
189 | Some (newt, subst, id2, dir, pos) ->
191 match build_clause bag (fun _ -> true) Terms.Demodulation
192 newt subst id id2 pos dir
194 | None -> assert false
195 | Some x -> Some (x,false)
199 [3] (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) r
203 | Some (newt, subst, id2, dir, pos) ->
204 match build_clause bag (fun _ -> true)
205 Terms.Demodulation newt subst id id2 pos dir
207 | None -> assert false
208 | Some x -> Some (x,true)
211 let parallel_demod table vl bag t pos ctx id =
212 match demod table vl t with
214 | Some (newside, subst, id2, dir) ->
215 match build_clause bag (fun _ -> true)
216 Terms.Demodulation (ctx newside) subst id id2 pos dir
218 | None -> assert false
219 | Some (bag,(id,_,_,_)) ->
223 let demodulate_once ~jump_to_right bag (id, literal, vl, pr) table =
225 | Terms.Predicate t -> assert false
226 | Terms.Equation (l,r,ty,_) ->
227 let bag,l,id1 = if jump_to_right then (bag,l,id) else
228 parallel_positions bag [2]
229 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) id l
230 (parallel_demod table vl)
232 let jump_to_right = id1 = id in
234 parallel_positions bag [3]
235 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) id1 r
236 (parallel_demod table vl)
238 if id = id2 then None
240 let cl,_,_ = Terms.get_from_bag id2 bag in
241 Some ((bag,cl),jump_to_right)
244 let rec demodulate ~jump_to_right bag clause table =
245 match demodulate_once ~jump_to_right bag clause table with
246 | None -> bag, clause
247 | Some ((bag, clause),r) -> demodulate ~jump_to_right:r
251 let rec demodulate_old ~jump_to_right bag clause table =
252 match demodulate_once_old ~jump_to_right bag clause table with
253 | None -> bag, clause
254 | Some ((bag, clause),r) -> demodulate_old ~jump_to_right:r
258 let are_alpha_eq cl1 cl2 =
259 let get_term (_,lit,_,_) =
261 | Terms.Predicate _ -> assert false
262 | Terms.Equation (l,r,ty,_) ->
263 Terms.Node [Terms.Leaf B.eqP; ty; l ; r]
265 try ignore(Unif.alpha_eq (get_term cl1) (get_term cl2)) ; true
266 with FoUnif.UnificationFailure _ -> false
269 let demodulate bag clause table =
270 (* let (bag1,c1), (_,c2) =*)
271 demodulate ~jump_to_right:false bag clause table
272 (* demodulate_old ~jump_to_right:false bag clause table *)
274 if are_alpha_eq c1 c2 then bag1,c1
276 prerr_endline (Pp.pp_unit_clause c1);
277 prerr_endline (Pp.pp_unit_clause c2);
278 prerr_endline "Bag :";
279 prerr_endline (Pp.pp_bag bag1);
283 let prof_demodulate = HExtlib.profile ~enable "demodulate";;
284 let demodulate bag clause x =
285 prof_demodulate.HExtlib.profile (demodulate bag clause) x
289 let is_identity_clause ~unify = function
290 | _, Terms.Equation (_,_,_,Terms.Eq), _, _ -> true
291 | _, Terms.Equation (l,r,_,_), vl, proof when unify ->
292 (try ignore(Unif.unification (* vl *) [] l r); true
293 with FoUnif.UnificationFailure _ -> false)
294 | _, Terms.Equation (_,_,_,_), _, _ -> false
295 | _, Terms.Predicate _, _, _ -> assert false
298 let build_new_clause bag maxvar filter rule t subst id id2 pos dir =
299 let maxvar, _vl, subst = Utils.relocate maxvar (Terms.vars_of_term
300 (Subst.apply_subst subst t)) subst in
301 match build_clause bag filter rule t subst id id2 pos dir with
302 | Some (bag, c) -> Some ((bag, maxvar), c)
305 let prof_build_new_clause = HExtlib.profile ~enable "build_new_clause";;
306 let build_new_clause bag maxvar filter rule t subst id id2 pos x =
307 prof_build_new_clause.HExtlib.profile (build_new_clause bag maxvar filter
308 rule t subst id id2 pos) x
311 let fold_build_new_clause bag maxvar id rule filter res =
312 let (bag, maxvar), res =
313 HExtlib.filter_map_acc
314 (fun (bag, maxvar) (t,subst,id2,pos,dir) ->
315 build_new_clause bag maxvar filter rule t subst id id2 pos dir)
322 let rewrite_eq ~unify l r ty vl table =
323 let retrieve = if unify then IDX.DT.retrieve_unifiables
324 else IDX.DT.retrieve_generalizations in
325 let lcands = retrieve table l in
326 let rcands = retrieve table r in
328 let id, dir, l, r, vl =
330 | (d, (id,Terms.Equation (l,r,ty,_),vl,_))-> id, d, l, r, vl
333 let reverse = (dir = Terms.Left2Right) = b in
334 let l, r, proof_rewrite_dir = if reverse then l,r,Terms.Left2Right
335 else r,l, Terms.Right2Left in
336 (id,proof_rewrite_dir,Terms.Node [ Terms.Leaf B.eqP; ty; l; r ], vl)
338 let cands1 = List.map (f true) (IDX.ClauseSet.elements lcands) in
339 let cands2 = List.map (f false) (IDX.ClauseSet.elements rcands) in
340 let t = Terms.Node [ Terms.Leaf B.eqP; ty; l; r ] in
341 let locked_vars = if unify then [] else vl in
342 let rec aux = function
344 | (id2,dir,c,vl1)::tl ->
346 let subst = Unif.unification (* (vl@vl1) *) locked_vars c t in
347 Some (id2, dir, subst)
348 with FoUnif.UnificationFailure _ -> aux tl
350 aux (cands1 @ cands2)
353 let is_subsumed ~unify bag maxvar (id, lit, vl, _) table =
355 | Terms.Predicate _ -> assert false
356 | Terms.Equation (l,r,ty,_) ->
357 match rewrite_eq ~unify l r ty vl table with
359 | Some (id2, dir, subst) ->
360 let id_t = Terms.Node [ Terms.Leaf B.eqP; ty; r; r ] in
361 build_new_clause bag maxvar (fun _ -> true)
362 Terms.Superposition id_t subst id id2 [2] dir
364 let prof_is_subsumed = HExtlib.profile ~enable "is_subsumed";;
365 let is_subsumed ~unify bag maxvar c x =
366 prof_is_subsumed.HExtlib.profile (is_subsumed ~unify bag maxvar c) x
368 (* id refers to a clause proving contextl l = contextr r *)
370 let rec deep_eq ~unify l r ty pos contextl contextr table acc =
373 | Some(bag,maxvar,(id,lit,vl,p),subst) ->
374 let l = Subst.apply_subst subst l in
375 let r = Subst.apply_subst subst r in
377 let subst1 = Unif.unification (* vl *) [] l r in
379 match lit with Terms.Predicate _ -> assert false
380 | Terms.Equation (l,r,ty,o) ->
381 Terms.Equation (FoSubst.apply_subst subst1 l,
382 FoSubst.apply_subst subst1 r, ty, o)
384 Some(bag,maxvar,(id,lit,vl,p),Subst.concat subst1 subst)
385 with FoUnif.UnificationFailure _ ->
386 match rewrite_eq ~unify l r ty vl table with
387 | Some (id2, dir, subst1) ->
388 let newsubst = Subst.concat subst1 subst in
390 FoSubst.apply_subst newsubst
391 (Terms.Node[Terms.Leaf B.eqP;ty;contextl r;contextr r])
394 build_new_clause bag maxvar (fun _ -> true)
395 Terms.Superposition id_t
396 subst1 id id2 (pos@[2]) dir
398 | Some ((bag, maxvar), c) ->
399 Some(bag,maxvar,c,newsubst)
400 | None -> assert false)
403 | Terms.Node (a::la), Terms.Node (b::lb) when
404 a = b && List.length la = List.length lb ->
407 (fun (acc,pre,postl,postr) a b ->
409 fun x -> contextl(Terms.Node (pre@(x::postl))) in
411 fun x -> contextr(Terms.Node (pre@(x::postr))) in
412 let newpos = List.length pre::pos in
414 if l = [] then [] else List.tl l in
415 (deep_eq ~unify a b ty
416 newpos newcl newcr table acc,pre@[b],
417 footail postl, footail postr))
418 (acc,[a],List.tl la,List.tl lb) la lb
422 let prof_deep_eq = HExtlib.profile ~enable "deep_eq";;
423 let deep_eq ~unify l r ty pos contextl contextr table x =
424 prof_deep_eq.HExtlib.profile (deep_eq ~unify l r ty pos contextl contextr table) x
427 let rec orphan_murder bag acc i =
428 match Terms.get_from_bag i bag with
429 | (_,_,_,Terms.Exact _),discarded,_ -> (discarded,acc)
430 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)),true,_ -> (true,acc)
431 | (_,_,_,Terms.Step (_,i1,i2,_,_,_)),false,_ ->
432 if (List.mem i acc) then (false,acc)
433 else match orphan_murder bag acc i1 with
434 | (true,acc) -> (true,acc)
436 let (res,acc) = orphan_murder bag acc i2 in
437 if res then res,acc else res,i::acc
440 let orphan_murder bag actives cl =
441 let (id,_,_,_) = cl in
442 let actives = List.map (fun (i,_,_,_) -> i) actives in
443 let (res,_) = orphan_murder bag actives id in
444 if res then debug "Orphan murdered"; res
446 let prof_orphan_murder = HExtlib.profile ~enable "orphan_murder";;
447 let orphan_murder bag actives x =
448 prof_orphan_murder.HExtlib.profile (orphan_murder bag actives) x
451 (* demodulate and check for subsumption *)
452 let simplify table maxvar bag clause =
453 if is_identity_clause ~unify:false clause then bag,None
454 (* else if orphan_murder bag actives clause then bag,None *)
455 else let bag, clause = demodulate bag clause table in
456 if is_identity_clause ~unify:false clause then bag,None
458 match is_subsumed ~unify:false bag maxvar clause table with
459 | None -> bag, Some clause
460 | Some _ -> bag, None
463 let simplify table maxvar bag clause =
464 match simplify table maxvar bag clause with
466 let (id,_,_,_) = clause in
467 let (_,_,iter) = Terms.get_from_bag id bag in
468 Terms.replace_in_bag (clause,true,iter) bag, None
469 | bag, Some clause -> bag, Some clause
470 (*let (id,_,_,_) = clause in
471 if orphan_murder bag clause then
472 Terms.M.add id (clause,true) bag, Some clause
473 else bag, Some clause*)
475 let prof_simplify = HExtlib.profile ~enable "simplify";;
476 let simplify table maxvar bag x =
477 prof_simplify.HExtlib.profile (simplify table maxvar bag ) x
480 let one_pass_simplification new_clause (alist,atable) bag maxvar =
481 match simplify atable maxvar bag new_clause with
482 | bag,None -> bag,None (* new_clause has been discarded *)
483 | bag,(Some clause) ->
484 let ctable = IDX.index_unit_clause IDX.DT.empty clause in
485 let bag, alist, atable =
487 (fun (bag, alist, atable) c ->
488 match simplify ctable maxvar bag c with
489 |bag,None -> (bag,alist,atable)
490 (* an active clause as been discarded *)
492 bag, c :: alist, IDX.index_unit_clause atable c)
493 (bag,[],IDX.DT.empty) alist
495 bag, Some (clause, (alist,atable))
497 let prof_one_pass_simplification = HExtlib.profile ~enable "one_pass_simplification";;
498 let one_pass_simplification new_clause t bag x =
499 prof_one_pass_simplification.HExtlib.profile (one_pass_simplification new_clause t bag ) x
502 let simplification_step ~new_cl cl (alist,atable) bag maxvar new_clause =
504 if new_cl then atable else
505 IDX.index_unit_clause atable cl
507 (* Simplification of new_clause with : *
508 * - actives and cl if new_clause is not cl *
509 * - only actives otherwise *)
511 simplify atable1 maxvar bag new_clause with
512 | bag,None -> bag,(Some cl, None) (* new_clause has been discarded *)
514 (* Simplification of each active clause with clause *
515 * which is the simplified form of new_clause *)
516 let ctable = IDX.index_unit_clause IDX.DT.empty clause in
517 let bag, newa, alist, atable =
519 (fun (bag, newa, alist, atable) c ->
520 match simplify ctable maxvar bag c with
521 |bag,None -> (bag, newa, alist, atable)
522 (* an active clause as been discarded *)
525 bag, newa, c :: alist,
526 IDX.index_unit_clause atable c
528 bag, c1 :: newa, alist, atable)
529 (bag,[],[],IDX.DT.empty) alist
532 bag, (Some cl, Some (clause, (alist,atable), newa))
534 (* if new_clause is not cl, we simplify cl with clause *)
535 match simplify ctable maxvar bag cl with
537 (* cl has been discarded *)
538 bag,(None, Some (clause, (alist,atable), newa))
540 bag,(Some cl1, Some (clause, (alist,atable), newa))
542 let prof_simplification_step = HExtlib.profile ~enable "simplification_step";;
543 let simplification_step ~new_cl cl (alist,atable) bag maxvar x =
544 prof_simplification_step.HExtlib.profile (simplification_step ~new_cl cl (alist,atable) bag maxvar) x
547 let keep_simplified cl (alist,atable) bag maxvar =
548 let rec keep_simplified_aux ~new_cl cl (alist,atable) bag newc =
550 match simplification_step ~new_cl cl (alist,atable) bag maxvar cl with
551 | _,(None, _) -> assert false
552 | bag,(Some _, None) -> bag,None
553 | bag,(Some _, Some (clause, (alist,atable), newa)) ->
554 keep_simplified_aux ~new_cl:(cl!=clause) clause (alist,atable)
558 | [] -> bag, Some (cl, (alist,atable))
560 match simplification_step ~new_cl cl
561 (alist,atable) bag maxvar hd with
562 | _,(None,None) -> assert false
563 | bag,(Some _,None) ->
564 keep_simplified_aux ~new_cl cl (alist,atable) bag tl
565 | bag,(None, Some _) -> bag,None
566 | bag,(Some cl1, Some (clause, (alist,atable), newa)) ->
568 (clause::alist, IDX.index_unit_clause atable clause)
570 keep_simplified_aux ~new_cl:(cl!=cl1) cl1 (alist,atable)
573 keep_simplified_aux ~new_cl:true cl (alist,atable) bag []
575 let prof_keep_simplified = HExtlib.profile ~enable "keep_simplified";;
576 let keep_simplified cl t bag x =
577 prof_keep_simplified.HExtlib.profile (keep_simplified cl t bag) x
580 (* this is like simplify but raises Success *)
581 let simplify_goal ~no_demod maxvar table bag g_actives clause =
583 if no_demod then bag, clause else demodulate bag clause table
585 if List.exists (are_alpha_eq clause) g_actives then None else
586 if (is_identity_clause ~unify:true clause)
587 then raise (Success (bag, maxvar, clause))
589 let (id,lit,vl,_) = clause in
590 if vl = [] then Some (bag,clause)
594 | Terms.Equation(l,r,ty,_) -> l,r,ty
597 match deep_eq ~unify:true l r ty [] (fun x -> x) (fun x -> x)
598 table (Some(bag,maxvar,clause,Subst.id_subst)) with
599 | None -> Some (bag,clause)
600 | Some (bag,maxvar,cl,subst) ->
601 prerr_endline "Goal subsumed";
602 raise (Success (bag,maxvar,cl))
604 else match is_subsumed ~unify:true bag maxvar clause table with
605 | None -> Some (bag, clause)
606 | Some ((bag,maxvar),c) ->
607 prerr_endline "Goal subsumed";
608 raise (Success (bag,maxvar,c))
612 let prof_simplify_goal = HExtlib.profile ~enable "simplify_goal";;
613 let simplify_goal ~no_demod maxvar table bag g_actives x =
614 prof_simplify_goal.HExtlib.profile ( simplify_goal ~no_demod maxvar table bag g_actives) x
617 (* =================== inference ===================== *)
619 (* this is OK for both the sup_left and sup_right inference steps *)
620 let superposition table varlist subterm pos context =
621 let cands = IDX.DT.retrieve_unifiables table subterm in
623 (fun (dir, (id,lit,vl,_ (*as uc*))) ->
625 | Terms.Predicate _ -> assert false
626 | Terms.Equation (l,r,_,o) ->
627 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
630 Unif.unification (* (varlist@vl)*) [] subterm side
632 if o = Terms.Incomparable then
633 let side = Subst.apply_subst subst side in
634 let newside = Subst.apply_subst subst newside in
635 let o = Order.compare_terms side newside in
636 (* XXX: check Riazanov p. 33 (iii) *)
637 if o <> Terms.Lt && o <> Terms.Eq then
638 Some (context newside, subst, id, pos, dir)
640 ((*prerr_endline ("Filtering: " ^
641 Pp.pp_foterm side ^ " =(< || =)" ^
642 Pp.pp_foterm newside);*)None)
644 Some (context newside, subst, id, pos, dir)
645 with FoUnif.UnificationFailure _ -> None)
646 (IDX.ClauseSet.elements cands)
649 (* Superposes selected equation with equalities in table *)
650 let superposition_with_table bag maxvar (id,selected,vl,_) table =
652 | Terms.Predicate _ -> assert false
653 | Terms.Equation (l,r,ty,Terms.Lt) ->
654 fold_build_new_clause bag maxvar id Terms.Superposition
657 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
658 r (superposition table vl))
659 | Terms.Equation (l,r,ty,Terms.Gt) ->
660 fold_build_new_clause bag maxvar id Terms.Superposition
663 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ])
664 l (superposition table vl))
665 | Terms.Equation (l,r,ty,Terms.Incomparable) ->
666 let filtering avoid subst = (* Riazanov: p.33 condition (iv) *)
667 let l = Subst.apply_subst subst l in
668 let r = Subst.apply_subst subst r in
669 let o = Order.compare_terms l r in
670 o <> avoid && o <> Terms.Eq
672 let bag, maxvar,r_terms =
673 fold_build_new_clause bag maxvar id Terms.Superposition
676 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
677 r (superposition table vl))
679 let bag, maxvar, l_terms =
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))
686 bag, maxvar, r_terms @ l_terms
690 (* the current equation is normal w.r.t. demodulation with atable
691 * (and is not the identity) *)
692 let infer_right bag maxvar current (alist,atable) =
693 (* We demodulate actives clause with current until all *
694 * active clauses are reduced w.r.t each other *)
695 (* let bag, (alist,atable) = keep_simplified (alist,atable) bag [current] in *)
696 let ctable = IDX.index_unit_clause IDX.DT.empty current in
697 (* let bag, (alist, atable) =
699 HExtlib.filter_map_acc (simplify ctable) bag alist
701 bag, (alist, List.fold_left IDX.index_unit_clause IDX.DT.empty alist)
703 debug "Simplified active clauses with fact";
704 (* We superpose active clauses with current *)
705 let bag, maxvar, new_clauses =
707 (fun (bag, maxvar, acc) active ->
708 let bag, maxvar, newc =
709 superposition_with_table bag maxvar active ctable
711 bag, maxvar, newc @ acc)
712 (bag, maxvar, []) alist
714 debug "First superpositions";
715 (* We add current to active clauses so that it can be *
716 * superposed with itself *)
718 current :: alist, IDX.index_unit_clause atable current
721 let fresh_current, maxvar = Utils.fresh_unit_clause maxvar current in
722 (* We need to put fresh_current into the bag so that all *
723 * variables clauses refer to are known. *)
724 let bag, fresh_current = Terms.add_to_bag fresh_current bag in
725 (* We superpose current with active clauses *)
726 let bag, maxvar, additional_new_clauses =
727 superposition_with_table bag maxvar fresh_current atable
729 debug "Another superposition";
730 let new_clauses = new_clauses @ additional_new_clauses in
731 debug (Printf.sprintf "Demodulating %d clauses"
732 (List.length new_clauses));
733 let bag, new_clauses =
734 HExtlib.filter_map_monad (simplify atable maxvar) bag new_clauses
736 debug "Demodulated new clauses";
737 bag, maxvar, (alist, atable), new_clauses
740 let prof_ir = HExtlib.profile ~enable "infer_right";;
741 let infer_right bag maxvar current t =
742 prof_ir.HExtlib.profile (infer_right bag maxvar current) t
745 let infer_left bag maxvar goal (_alist, atable) =
746 (* We superpose the goal with active clauses *)
747 if (match goal with (_,_,[],_) -> true | _ -> false) then bag, maxvar, []
749 let bag, maxvar, new_goals =
750 superposition_with_table bag maxvar goal atable
752 debug "Superposed goal with active clauses";
753 (* We simplify the new goals with active clauses *)
757 match simplify_goal ~no_demod:false maxvar atable bag [] g with
758 | None -> assert false
759 | Some (bag,g) -> bag,g::acc)
762 debug "Simplified new goals with active clauses";
763 bag, maxvar, List.rev new_goals
766 let prof_il = HExtlib.profile ~enable "infer_left";;
767 let infer_left bag maxvar goal t =
768 prof_il.HExtlib.profile (infer_left bag maxvar goal) t