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)
22 module Clauses = Clauses.Clauses(B)
24 exception Success of B.t Terms.bag * int * B.t Terms.clause
26 let debug s = prerr_endline (Lazy.force s);;
30 let rec list_first f = function
32 | x::tl -> match f x with Some _ as x -> x | _ -> list_first f tl
35 let first_position pos ctx t f =
36 let inject_pos pos ctx = function
38 | Some (a,b,c,d) -> Some(ctx a,b,c,d,pos)
40 let rec aux pos ctx = function
41 | Terms.Leaf _ as t -> inject_pos pos ctx (f t)
45 | Some _ as x -> inject_pos pos ctx x
47 let rec first pre post = function
50 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
51 match aux (List.length pre :: pos) newctx t with
54 if post = [] then None (* tl is also empty *)
55 else first (pre @ [t]) (List.tl post) tl
57 first [] (List.tl l) l
62 let all_positions pos ctx t f =
63 let rec aux pos ctx = function
64 | Terms.Leaf _ as t -> f t pos ctx
69 (fun (acc,pre,post) t -> (* Invariant: pre @ [t] @ post = l *)
70 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
71 let acc = aux (List.length pre :: pos) newctx t @ acc in
72 if post = [] then acc, l, []
73 else acc, pre @ [t], List.tl post)
74 (f t pos ctx, [], List.tl l) l
81 let parallel_positions bag pos ctx id t f =
82 let rec aux bag pos ctx id = function
83 | Terms.Leaf _ as t -> f bag t pos ctx id
84 | Terms.Var _ as t -> bag,t,id
85 | Terms.Node (hd::l) as t->
86 let bag,t,id1 = f bag t pos ctx id in
90 (fun (bag,pre,post,id) t ->
91 let newctx = fun x -> ctx (Terms.Node (pre@[x]@post)) in
92 let newpos = (List.length pre)::pos in
93 let bag,newt,id = aux bag newpos newctx id t in
94 if post = [] then bag, pre@[newt], [], id
95 else bag, pre @ [newt], List.tl post, id)
96 (bag, [hd], List.tl l, id) l
105 let build_clause bag filter rule t subst id id2 pos dir =
106 let proof = Terms.Step(rule,id,id2,dir,pos,subst) in
107 let t = Subst.apply_subst subst t in
111 | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq ->
112 let o = Order.compare_terms l r in
113 Terms.Equation (l, r, ty, o)
114 | t -> Terms.Predicate t
117 Terms.add_to_bag (0, [], [literal,true], Terms.vars_of_term t, proof) bag
121 ((*prerr_endline ("Filtering: " ^ Pp.pp_foterm t);*)None)
123 let prof_build_clause = HExtlib.profile ~enable "build_clause";;
124 let build_clause bag filter rule t subst id id2 pos x =
125 prof_build_clause.HExtlib.profile (build_clause bag filter rule t subst id id2 pos) x
129 (* ============ simplification ================= *)
130 let prof_demod_u = HExtlib.profile ~enable "demod.unify";;
131 let prof_demod_r = HExtlib.profile ~enable "demod.retrieve_generalizations";;
132 let prof_demod_o = HExtlib.profile ~enable "demod.compare_terms";;
133 let prof_demod_s = HExtlib.profile ~enable "demod.apply_subst";;
135 let demod table varlist subterm =
137 prof_demod_r.HExtlib.profile
138 (IDX.DT.retrieve_generalizations table) subterm
141 (fun (dir, is_pos, pos, (id,nlit,plit,vl,_)) ->
145 | Terms.Predicate _ -> assert false
146 | Terms.Equation (l,r,_,o) ->
147 let side, newside = if dir=Terms.Left2Right then l,r else r,l in
150 prof_demod_u.HExtlib.profile
151 (Unif.unification (* (varlist@vl) *) varlist subterm) side
154 prof_demod_s.HExtlib.profile
155 (Subst.apply_subst subst) side
158 prof_demod_s.HExtlib.profile
159 (Subst.apply_subst subst) newside
161 if o = Terms.Incomparable || o = Terms.Invertible then
163 prof_demod_o.HExtlib.profile
164 (Order.compare_terms newside) side in
165 (* Riazanov, pp. 45 (ii) *)
167 Some (newside, subst, id, dir)
169 ((*prerr_endline ("Filtering: " ^
170 Pp.pp_foterm side ^ " =(< || =)" ^
171 Pp.pp_foterm newside ^ " coming from " ^
172 Pp.pp_clause uc );*)None)
174 Some (newside, subst, id, dir)
175 with FoUnif.UnificationFailure _ -> None)
177 (IDX.ClauseSet.elements cands)
179 let prof_demod = HExtlib.profile ~enable "demod";;
180 let demod table varlist x =
181 prof_demod.HExtlib.profile (demod table varlist) x
184 let parallel_demod table vl bag t pos ctx id =
185 match demod table vl t with
187 | Some (newside, subst, id2, dir) ->
188 match build_clause bag (fun _ -> true)
189 Terms.Demodulation (ctx newside) subst id id2 pos dir
191 | None -> assert false
192 | Some (bag,(id,_,_,_,_)) ->
196 let demodulate_once ~jump_to_right bag (id, nlit, plit, vl, pr) table =
201 | Terms.Predicate t -> assert false
202 | Terms.Equation (l,r,ty,_) ->
203 let bag,l,id1 = if jump_to_right then (bag,l,id) else
204 parallel_positions bag [2]
205 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ]) id l
206 (parallel_demod table vl)
208 let jump_to_right = id1 = id in
210 parallel_positions bag [3]
211 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ]) id1 r
212 (parallel_demod table vl)
214 if id = id2 then None
216 let cl,_,_ = Terms.get_from_bag id2 bag in
217 Some ((bag,cl),jump_to_right))
221 let rec demodulate ~jump_to_right bag clause table =
222 match demodulate_once ~jump_to_right bag clause table with
223 | None -> bag, clause
224 | Some ((bag, clause),r) -> demodulate ~jump_to_right:r
228 let are_alpha_eq cl1 cl2 =
229 let get_term (_,nlit,plit,_,_) =
231 | [], [Terms.Equation (l,r,ty,_),_] ->
232 Terms.Node [Terms.Leaf B.eqP; ty; l ; r]
235 try ignore(Unif.alpha_eq (get_term cl1) (get_term cl2)) ; true
236 with FoUnif.UnificationFailure _ -> false
239 let demodulate bag clause table =
240 (* let (bag1,c1), (_,c2) =*)
241 demodulate ~jump_to_right:false bag clause table
242 (* demodulate_old ~jump_to_right:false bag clause table *)
244 if are_alpha_eq c1 c2 then bag1,c1
246 prerr_endline (Pp.pp_clause c1);
247 prerr_endline (Pp.pp_clause c2);
248 prerr_endline "Bag :";
249 prerr_endline (Pp.pp_bag bag1);
253 let prof_demodulate = HExtlib.profile ~enable "demodulate";;
254 let demodulate bag clause x =
255 prof_demodulate.HExtlib.profile (demodulate bag clause) x
259 let is_identity_clause ~unify = function
260 | _, [], [Terms.Equation (_,_,_,Terms.Eq),_], _, _ -> true
261 | _, [], [Terms.Equation (l,r,_,_),_], vl, proof when unify ->
262 (try ignore(Unif.unification (* vl *) [] l r); true
263 with FoUnif.UnificationFailure _ -> false)
267 let build_new_clause bag maxvar filter rule t subst id id2 pos dir =
268 let maxvar, _vl, subst = Utils.relocate maxvar (Terms.vars_of_term
269 (Subst.apply_subst subst t)) subst in
270 match build_clause bag filter rule t subst id id2 pos dir with
271 | Some (bag, c) -> Some ((bag, maxvar), c)
274 let prof_build_new_clause = HExtlib.profile ~enable "build_new_clause";;
275 let build_new_clause bag maxvar filter rule t subst id id2 pos x =
276 prof_build_new_clause.HExtlib.profile (build_new_clause bag maxvar filter
277 rule t subst id id2 pos) x
280 let fold_build_new_clause bag maxvar id rule filter res =
281 let (bag, maxvar), res =
282 HExtlib.filter_map_acc
283 (fun (bag, maxvar) (t,subst,id2,pos,dir) ->
284 build_new_clause bag maxvar filter rule t subst id id2 pos dir)
290 (* Tries to rewrite an equality to identity, using unit equalities in table *)
291 let rewrite_eq ~unify l r ty vl table =
292 let retrieve = if unify then IDX.DT.retrieve_unifiables
293 else IDX.DT.retrieve_generalizations in
294 let lcands = retrieve table l in
295 let rcands = retrieve table r in
297 let id, dir, l, r, vl =
299 | (d,_,_, (id,[],[Terms.Equation (l,r,ty,_),_],vl,_))-> id, d, l, r, vl
302 let reverse = (dir = Terms.Left2Right) = b in
303 let l, r, proof_rewrite_dir = if reverse then l,r,Terms.Left2Right
304 else r,l, Terms.Right2Left in
305 (id,proof_rewrite_dir,Terms.Node [ Terms.Leaf B.eqP; ty; l; r ], vl)
307 let cands1 = List.map (f true) (IDX.ClauseSet.elements lcands) in
308 let cands2 = List.map (f false) (IDX.ClauseSet.elements rcands) in
309 let t = Terms.Node [ Terms.Leaf B.eqP; ty; l; r ] in
310 let locked_vars = if unify then [] else vl in
311 let rec aux = function
313 | (id2,dir,c,vl1)::tl ->
315 let subst = Unif.unification (* (vl@vl1) *) locked_vars c t in
316 Some (id2, dir, subst)
317 with FoUnif.UnificationFailure _ -> aux tl
319 aux (cands1 @ cands2)
322 let is_subsumed ~unify bag maxvar (id, nlit, plit, vl, _) table =
324 | [],[Terms.Equation (l,r,ty,_) ,_]->
325 (match rewrite_eq ~unify l r ty vl table with
327 | Some (id2, dir, subst) ->
328 let id_t = Terms.Node [ Terms.Leaf B.eqP; ty; r; r ] in
329 build_new_clause bag maxvar (fun _ -> true)
330 Terms.Superposition id_t subst id id2 [2] dir)
333 let prof_is_subsumed = HExtlib.profile ~enable "is_subsumed";;
334 let is_subsumed ~unify bag maxvar c x =
335 prof_is_subsumed.HExtlib.profile (is_subsumed ~unify bag maxvar c) x
337 (* id refers to a clause proving contextl l = contextr r *)
339 let rec deep_eq ~unify l r ty pos contextl contextr table acc =
342 | Some(bag,maxvar,(id,nlit,plit,vl,p),subst) ->
343 let l = Subst.apply_subst subst l in
344 let r = Subst.apply_subst subst r in
346 let subst1 = Unif.unification (* vl *) [] l r in
349 | [],[Terms.Equation (l,r,ty,o),_] ->
350 Terms.Equation (FoSubst.apply_subst subst1 l,
351 FoSubst.apply_subst subst1 r, ty, o)
354 Some(bag,maxvar,(id,[],[lit,true],vl,p),Subst.concat subst1 subst)
355 with FoUnif.UnificationFailure _ ->
356 match rewrite_eq ~unify l r ty vl table with
357 | Some (id2, dir, subst1) ->
358 let newsubst = Subst.concat subst1 subst in
360 FoSubst.apply_subst newsubst
361 (Terms.Node[Terms.Leaf B.eqP;ty;contextl r;contextr r])
364 build_new_clause bag maxvar (fun _ -> true)
365 Terms.Superposition id_t
366 subst1 id id2 (pos@[2]) dir
368 | Some ((bag, maxvar), c) ->
369 Some(bag,maxvar,c,newsubst)
370 | None -> assert false)
373 | Terms.Node (a::la), Terms.Node (b::lb) when
374 a = b && List.length la = List.length lb ->
377 (fun (acc,pre,postl,postr) a b ->
379 fun x -> contextl(Terms.Node (pre@(x::postl))) in
381 fun x -> contextr(Terms.Node (pre@(x::postr))) in
382 let newpos = List.length pre::pos in
384 if l = [] then [] else List.tl l in
385 (deep_eq ~unify a b ty
386 newpos newcl newcr table acc,pre@[b],
387 footail postl, footail postr))
388 (acc,[a],List.tl la,List.tl lb) la lb
392 let prof_deep_eq = HExtlib.profile ~enable "deep_eq";;
393 let deep_eq ~unify l r ty pos contextl contextr table x =
394 prof_deep_eq.HExtlib.profile (deep_eq ~unify l r ty pos contextl contextr table) x
397 let rec orphan_murder bag acc i =
398 match Terms.get_from_bag i bag with
399 | (_,_,_,_,Terms.Exact _),discarded,_ -> (discarded,acc)
400 | (_,_,_,_,Terms.Step (_,i1,i2,_,_,_)),true,_ -> (true,acc)
401 | (_,_,_,_,Terms.Step (_,i1,i2,_,_,_)),false,_ ->
402 if (List.mem i acc) then (false,acc)
403 else match orphan_murder bag acc i1 with
404 | (true,acc) -> (true,acc)
406 let (res,acc) = orphan_murder bag acc i2 in
407 if res then res,acc else res,i::acc
410 let orphan_murder bag actives cl =
411 let (id,_,_,_,_) = cl in
412 let actives = List.map (fun (i,_,_,_,_) -> i) actives in
413 let (res,_) = orphan_murder bag actives id in
414 if res then debug (lazy "Orphan murdered"); res
416 let prof_orphan_murder = HExtlib.profile ~enable "orphan_murder";;
417 let orphan_murder bag actives x =
418 prof_orphan_murder.HExtlib.profile (orphan_murder bag actives) x
421 (* demodulate and check for subsumption *)
422 let simplify table maxvar bag clause =
423 if is_identity_clause ~unify:false clause then bag,None
424 (* else if orphan_murder bag actives clause then bag,None *)
425 else let bag, clause = demodulate bag clause table in
426 if is_identity_clause ~unify:false clause then bag,None
428 match is_subsumed ~unify:false bag maxvar clause table with
429 | None -> bag, Some clause
430 | Some _ -> bag, None
433 let simplify table maxvar bag clause =
434 match simplify table maxvar bag clause with
436 let (id,_,_,_,_) = clause in
437 let (_,_,iter) = Terms.get_from_bag id bag in
438 Terms.replace_in_bag (clause,true,iter) bag, None
439 | bag, Some clause -> bag, Some clause
440 (*let (id,_,_,_) = clause in
441 if orphan_murder bag clause then
442 Terms.M.add id (clause,true) bag, Some clause
443 else bag, Some clause*)
445 let prof_simplify = HExtlib.profile ~enable "simplify";;
446 let simplify table maxvar bag x =
447 prof_simplify.HExtlib.profile (simplify table maxvar bag ) x
450 let one_pass_simplification new_clause (alist,atable) bag maxvar =
451 match simplify atable maxvar bag new_clause with
452 | bag,None -> bag,None (* new_clause has been discarded *)
453 | bag,(Some clause) ->
454 let ctable = IDX.index_clause IDX.DT.empty clause in
455 let bag, alist, atable =
457 (fun (bag, alist, atable) c ->
458 match simplify ctable maxvar bag c with
459 |bag,None -> (bag,alist,atable)
460 (* an active clause as been discarded *)
462 bag, c :: alist, IDX.index_clause atable c)
463 (bag,[],IDX.DT.empty) alist
465 bag, Some (clause, (alist,atable))
467 let prof_one_pass_simplification = HExtlib.profile ~enable "one_pass_simplification";;
468 let one_pass_simplification new_clause t bag x =
469 prof_one_pass_simplification.HExtlib.profile (one_pass_simplification new_clause t bag ) x
472 let simplification_step ~new_cl cl (alist,atable) bag maxvar new_clause =
474 if new_cl then atable else
475 IDX.index_clause atable cl
477 (* Simplification of new_clause with : *
478 * - actives and cl if new_clause is not cl *
479 * - only actives otherwise *)
481 simplify atable1 maxvar bag new_clause with
482 | bag,None -> bag,(Some cl, None) (* new_clause has been discarded *)
484 (* Simplification of each active clause with clause *
485 * which is the simplified form of new_clause *)
486 let ctable = IDX.index_clause IDX.DT.empty clause in
487 let bag, newa, alist, atable =
489 (fun (bag, newa, alist, atable) c ->
490 match simplify ctable maxvar bag c with
491 |bag,None -> (bag, newa, alist, atable)
492 (* an active clause as been discarded *)
495 bag, newa, c :: alist,
496 IDX.index_clause atable c
498 bag, c1 :: newa, alist, atable)
499 (bag,[],[],IDX.DT.empty) alist
502 bag, (Some cl, Some (clause, (alist,atable), newa))
504 (* if new_clause is not cl, we simplify cl with clause *)
505 match simplify ctable maxvar bag cl with
507 (* cl has been discarded *)
508 bag,(None, Some (clause, (alist,atable), newa))
510 bag,(Some cl1, Some (clause, (alist,atable), newa))
512 let prof_simplification_step = HExtlib.profile ~enable "simplification_step";;
513 let simplification_step ~new_cl cl (alist,atable) bag maxvar x =
514 prof_simplification_step.HExtlib.profile (simplification_step ~new_cl cl (alist,atable) bag maxvar) x
517 let keep_simplified cl (alist,atable) bag maxvar =
518 let rec keep_simplified_aux ~new_cl cl (alist,atable) bag newc =
520 match simplification_step ~new_cl cl (alist,atable) bag maxvar cl with
521 | _,(None, _) -> assert false
522 | bag,(Some _, None) -> bag,None
523 | bag,(Some _, Some (clause, (alist,atable), newa)) ->
524 keep_simplified_aux ~new_cl:(cl!=clause) clause (alist,atable)
528 | [] -> bag, Some (cl, (alist,atable))
530 match simplification_step ~new_cl cl
531 (alist,atable) bag maxvar hd with
532 | _,(None,None) -> assert false
533 | bag,(Some _,None) ->
534 keep_simplified_aux ~new_cl cl (alist,atable) bag tl
535 | bag,(None, Some _) -> bag,None
536 | bag,(Some cl1, Some (clause, (alist,atable), newa)) ->
538 (clause::alist, IDX.index_clause atable clause)
540 keep_simplified_aux ~new_cl:(cl!=cl1) cl1 (alist,atable)
543 keep_simplified_aux ~new_cl:true cl (alist,atable) bag []
545 let prof_keep_simplified = HExtlib.profile ~enable "keep_simplified";;
546 let keep_simplified cl t bag x =
547 prof_keep_simplified.HExtlib.profile (keep_simplified cl t bag) x
550 (* this is like simplify but raises Success *)
551 let simplify_goal ~no_demod maxvar table bag g_actives clause =
553 if no_demod then bag, clause else demodulate bag clause table
555 if List.exists (are_alpha_eq clause) g_actives then None else
556 if (is_identity_clause ~unify:true clause)
557 then raise (Success (bag, maxvar, clause))
559 let (id,nlit,plit,vl,_) = clause in
560 if vl = [] then Some (bag,clause)
564 | [],[Terms.Equation(l,r,ty,_),_] -> l,r,ty
567 match deep_eq ~unify:true l r ty [] (fun x -> x) (fun x -> x)
568 table (Some(bag,maxvar,clause,Subst.id_subst)) with
569 | None -> Some (bag,clause)
570 | Some (bag,maxvar,cl,subst) ->
571 prerr_endline "Goal subsumed";
572 raise (Success (bag,maxvar,cl))
574 else match is_subsumed ~unify:true bag maxvar clause table with
575 | None -> Some (bag, clause)
576 | Some ((bag,maxvar),c) ->
577 prerr_endline "Goal subsumed";
578 raise (Success (bag,maxvar,c))
582 let prof_simplify_goal = HExtlib.profile ~enable "simplify_goal";;
583 let simplify_goal ~no_demod maxvar table bag g_actives x =
584 prof_simplify_goal.HExtlib.profile ( simplify_goal ~no_demod maxvar table bag g_actives) x
587 (* =================== inference ===================== *)
589 (* this is OK for both the sup_left and sup_right inference steps *)
590 let superposition table varlist subterm pos context =
591 let cands = IDX.DT.retrieve_unifiables table subterm in
592 debug (lazy (string_of_int (IDX.ClauseSet.cardinal cands) ^ " candidates found"));
594 (fun (dir, _, _, (id,nlit,plit,vl,_ (*as uc*))) ->
596 | [],[Terms.Equation (l,r,_,o),_] ->
597 (let side, newside = if dir=Terms.Left2Right then l,r else r,l in
600 Unif.unification (* (varlist@vl)*) [] subterm side
602 if o = Terms.Incomparable || o = Terms.Invertible then
603 let side = Subst.apply_subst subst side in
604 let newside = Subst.apply_subst subst newside in
605 let o = Order.compare_terms side newside in
606 (* XXX: check Riazanov p. 33 (iii) *)
607 if o <> Terms.Lt && o <> Terms.Eq then
608 Some (context newside, subst, id, pos, dir)
610 ((*prerr_endline ("Filtering: " ^
611 Pp.pp_foterm side ^ " =(< || =)" ^
612 Pp.pp_foterm newside);*)None)
614 Some (context newside, subst, id, pos, dir)
615 with FoUnif.UnificationFailure _ -> None)
617 (IDX.ClauseSet.elements cands)
620 (* Superposes selected equation with equalities in table *)
621 let superposition_with_table bag maxvar (id,nlit,plit,vl,_) table =
623 | [],[Terms.Equation (l,r,ty,Terms.Lt),_] ->
624 fold_build_new_clause bag maxvar id Terms.Superposition
627 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
628 r (superposition table vl))
629 | [],[Terms.Equation (l,r,ty,Terms.Invertible),_]
630 | [],[Terms.Equation (l,r,ty,Terms.Gt),_] ->
631 fold_build_new_clause bag maxvar id Terms.Superposition
634 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ])
635 l (superposition table vl))
636 | [],[Terms.Equation (l,r,ty,Terms.Incomparable),_] ->
637 let filtering avoid subst = (* Riazanov: p.33 condition (iv) *)
638 let l = Subst.apply_subst subst l in
639 let r = Subst.apply_subst subst r in
640 let o = Order.compare_terms l r in
641 o <> avoid && o <> Terms.Eq
643 let bag, maxvar,r_terms =
644 fold_build_new_clause bag maxvar id Terms.Superposition
647 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; l; x ])
648 r (superposition table vl))
650 let bag, maxvar, l_terms =
651 fold_build_new_clause bag maxvar id Terms.Superposition
654 (fun x -> Terms.Node [ Terms.Leaf B.eqP; ty; x; r ])
655 l (superposition table vl))
657 bag, maxvar, r_terms @ l_terms
661 (* the current equation is normal w.r.t. demodulation with atable
662 * (and is not the identity) *)
663 let infer_right bag maxvar current (alist,atable) =
664 (* We demodulate actives clause with current until all *
665 * active clauses are reduced w.r.t each other *)
666 (* let bag, (alist,atable) = keep_simplified (alist,atable) bag [current] in *)
667 let ctable = IDX.index_clause IDX.DT.empty current in
668 (* let bag, (alist, atable) =
670 HExtlib.filter_map_acc (simplify ctable) bag alist
672 bag, (alist, List.fold_left IDX.index_clause IDX.DT.empty alist)
674 debug (lazy "Simplified active clauses with fact");
675 (* We superpose active clauses with current *)
676 let bag, maxvar, new_clauses =
678 (fun (bag, maxvar, acc) active ->
679 let bag, maxvar, newc =
680 superposition_with_table bag maxvar active ctable
682 bag, maxvar, newc @ acc)
683 (bag, maxvar, []) alist
685 debug (lazy "First superpositions");
686 (* We add current to active clauses so that it can be *
687 * superposed with itself *)
689 current :: alist, IDX.index_clause atable current
691 debug (lazy "Indexed");
692 let fresh_current, maxvar = Clauses.fresh_clause maxvar current in
693 (* We need to put fresh_current into the bag so that all *
694 * variables clauses refer to are known. *)
695 let bag, fresh_current = Terms.add_to_bag fresh_current bag in
696 (* We superpose current with active clauses *)
697 let bag, maxvar, additional_new_clauses =
698 superposition_with_table bag maxvar fresh_current atable
700 debug (lazy "Another superposition");
701 let new_clauses = new_clauses @ additional_new_clauses in
702 debug (lazy (Printf.sprintf "Demodulating %d clauses"
703 (List.length new_clauses)));
704 let bag, new_clauses =
705 HExtlib.filter_map_monad (simplify atable maxvar) bag new_clauses
707 debug (lazy "Demodulated new clauses");
708 bag, maxvar, (alist, atable), new_clauses
711 let prof_ir = HExtlib.profile ~enable "infer_right";;
712 let infer_right bag maxvar current t =
713 prof_ir.HExtlib.profile (infer_right bag maxvar current) t
716 let infer_left bag maxvar goal (_alist, atable) =
717 (* We superpose the goal with active clauses *)
718 if (match goal with (_,_,_,[],_) -> true | _ -> false) then bag, maxvar, []
720 let bag, maxvar, new_goals =
721 superposition_with_table bag maxvar goal atable
723 debug (lazy "Superposed goal with active clauses");
724 (* We simplify the new goals with active clauses *)
728 match simplify_goal ~no_demod:false maxvar atable bag [] g with
729 | None -> assert false
730 | Some (bag,g) -> bag,g::acc)
733 debug (lazy "Simplified new goals with active clauses");
734 bag, maxvar, List.rev new_goals
737 let prof_il = HExtlib.profile ~enable "infer_left";;
738 let infer_left bag maxvar goal t =
739 prof_il.HExtlib.profile (infer_left bag maxvar goal) t