+ let keep_simplified cl (alist,atable) bag maxvar =
+ let rec keep_simplified_aux ~new_cl cl (alist,atable) bag newc =
+ if new_cl then
+ match simplification_step ~new_cl cl (alist,atable) bag maxvar cl with
+ | (None, _) -> assert false
+ | (Some _, None) -> None
+ | (Some _, Some (clause, (alist,atable), newa, bag)) ->
+ keep_simplified_aux ~new_cl:(cl!=clause) clause (alist,atable)
+ bag (newa@newc)
+ else
+ match newc with
+ | [] -> Some (cl, bag, (alist,atable))
+ | hd::tl ->
+ match simplification_step ~new_cl cl
+ (alist,atable) bag maxvar hd with
+ | (None,None) -> assert false
+ | (Some _,None) ->
+ keep_simplified_aux ~new_cl cl (alist,atable) bag tl
+ | (None, Some _) -> None
+ | (Some cl1, Some (clause, (alist,atable), newa, bag)) ->
+ let alist,atable =
+ (clause::alist, IDX.index_unit_clause atable clause)
+ in
+ keep_simplified_aux ~new_cl:(cl!=cl1) cl1 (alist,atable)
+ bag (newa@tl)
+ in
+ keep_simplified_aux ~new_cl:true cl (alist,atable) bag []
+ ;;
+
+ let are_alpha_eq cl1 cl2 =
+ let get_term (_,lit,_,_) =
+ match lit with
+ | Terms.Predicate _ -> assert false
+ | Terms.Equation (l,r,ty,_) ->
+ Terms.Node [Terms.Leaf B.eqP; ty; l ; r]
+ in
+ try ignore(Unif.alpha_eq (get_term cl1) (get_term cl2)) ; true
+ with FoUnif.UnificationFailure _ -> false
+;;
+
+ (* this is like simplify but raises Success *)
+ let simplify_goal maxvar table bag g_actives clause =
+ let bag, clause = demodulate bag clause table in
+ if (is_identity_clause ~unify:true clause)
+ then raise (Success (bag, maxvar, clause))
+ else match is_subsumed ~unify:true bag maxvar clause table with
+ | None ->
+ if List.exists (are_alpha_eq clause) g_actives then None
+ else Some (bag, clause)
+ | Some ((bag,maxvar),c) ->
+ debug "Goal subsumed";
+ raise (Success (bag,maxvar,c))
+ ;;
+
+ (* =================== inference ===================== *)
+
+ (* this is OK for both the sup_left and sup_right inference steps *)
+ let superposition table varlist subterm pos context =
+ let cands = IDX.DT.retrieve_unifiables table subterm in
+ HExtlib.filter_map
+ (fun (dir, (id,lit,vl,_ (*as uc*))) ->
+ match lit with
+ | Terms.Predicate _ -> assert false
+ | Terms.Equation (l,r,_,o) ->
+ let side, newside = if dir=Terms.Left2Right then l,r else r,l in
+ try
+ let subst, varlist =
+ Unif.unification (varlist@vl) [] subterm side
+ in
+ if o = Terms.Incomparable then
+ let side = Subst.apply_subst subst side in
+ let newside = Subst.apply_subst subst newside in
+ let o = Order.compare_terms side newside in
+ (* XXX: check Riazanov p. 33 (iii) *)
+ if o <> Terms.Lt && o <> Terms.Eq then
+ Some (context newside, subst, varlist, id, pos, dir)
+ else
+ ((*prerr_endline ("Filtering: " ^
+ Pp.pp_foterm side ^ " =(< || =)" ^
+ Pp.pp_foterm newside ^ " coming from " ^
+ Pp.pp_unit_clause uc );*)None)
+ else
+ Some (context newside, subst, varlist, id, pos, dir)
+ with FoUnif.UnificationFailure _ -> None)
+ (IDX.ClauseSet.elements cands)
+ ;;
+
+ (* Superposes selected equation with equalities in table *)
+ let superposition_with_table bag maxvar (id,selected,vl,_) table =