+ (* Simplification of new_clause with : *
+ * - actives and cl if new_clause is not cl *
+ * - only actives otherwise *)
+ match simplify atable1 maxvar bag new_clause with
+ | bag,None -> (Some cl, None) (* new_clause has been discarded *)
+ | bag,Some clause ->
+ (* Simplification of each active clause with clause *
+ * which is the simplified form of new_clause *)
+ let ctable = IDX.index_unit_clause IDX.DT.empty clause in
+ let bag, newa, alist, atable =
+ List.fold_left
+ (fun (bag, newa, alist, atable as acc) c ->
+ match simplify ctable maxvar bag c with
+ |bag,None -> acc (* an active clause as been discarded *)
+ |bag,Some c1 ->
+ if (c1 == c) then
+ bag, newa, c :: alist,
+ IDX.index_unit_clause atable c
+ else
+ bag, c1 :: newa, alist, atable)
+ (bag,[],[],IDX.DT.empty) alist
+ in
+ if new_cl then
+ (Some cl, Some (clause, (alist,atable), newa, bag))
+ else
+ (* if new_clause is not cl, we simplify cl with clause *)
+ match simplify ctable maxvar bag cl with
+ | bag,None ->
+ (* cl has been discarded *)
+ (None, Some (clause, (alist,atable), newa, bag))
+ | bag,Some cl1 ->
+ (Some cl1, Some (clause, (alist,atable), newa, bag))
+ ;;
+
+ 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
+ let (id,lit,vl,_) = clause in
+ let l,r,ty =
+ match lit with
+ | Terms.Equation(l,r,ty,_) -> l,r,ty
+ | _ -> assert false
+ in
+ match deep_eq ~unify:true l r ty [] (fun x -> x) (fun x -> x)
+ table (Some(bag,maxvar,[clause],Subst.id_subst)) with
+ | None ->
+ if List.exists (are_alpha_eq clause) g_actives then None
+ else Some (bag, clause)
+ | Some (bag,maxvar,cl,subst) ->
+ debug "Goal subsumed";
+ raise (Success (bag,maxvar,List.hd cl))
+*)
+ 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)