+ let simplify table maxvar bag clause =
+ match simplify table maxvar bag clause with
+ | bag, None ->
+ let (id,_,_,_) = clause in
+ let (_,_,iter) = Terms.get_from_bag id bag in
+ Terms.replace_in_bag (clause,true,iter) bag, None
+ | bag, Some clause -> bag, Some clause
+ (*let (id,_,_,_) = clause in
+ if orphan_murder bag clause then
+ Terms.M.add id (clause,true) bag, Some clause
+ else bag, Some clause*)
+ ;;
+ let prof_simplify = HExtlib.profile ~enable "simplify";;
+ let simplify table maxvar bag x =
+ prof_simplify.HExtlib.profile (simplify table maxvar bag ) x
+ ;;
+
+ let one_pass_simplification new_clause (alist,atable) bag maxvar =
+ match simplify atable maxvar bag new_clause with
+ | bag,None -> bag,None (* new_clause has been discarded *)
+ | bag,(Some clause) ->
+ let ctable = IDX.index_unit_clause IDX.DT.empty clause in
+ let bag, alist, atable =
+ List.fold_left
+ (fun (bag, alist, atable) c ->
+ match simplify ctable maxvar bag c with
+ |bag,None -> (bag,alist,atable)
+ (* an active clause as been discarded *)
+ |bag,Some c1 ->
+ bag, c :: alist, IDX.index_unit_clause atable c)
+ (bag,[],IDX.DT.empty) alist
+ in
+ bag, Some (clause, (alist,atable))
+ ;;
+ let prof_one_pass_simplification = HExtlib.profile ~enable "one_pass_simplification";;
+ let one_pass_simplification new_clause t bag x =
+ prof_one_pass_simplification.HExtlib.profile (one_pass_simplification new_clause t bag ) x
+ ;;
+
+ let simplification_step ~new_cl cl (alist,atable) bag maxvar new_clause =
+ let atable1 =
+ if new_cl then atable else
+ IDX.index_unit_clause atable cl
+ in
+ (* 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 -> bag,(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) c ->
+ match simplify ctable maxvar bag c with
+ |bag,None -> (bag, newa, alist, atable)
+ (* 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
+ bag, (Some cl, Some (clause, (alist,atable), newa))
+ 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 *)
+ bag,(None, Some (clause, (alist,atable), newa))
+ | bag,Some cl1 ->
+ bag,(Some cl1, Some (clause, (alist,atable), newa))
+ ;;
+ let prof_simplification_step = HExtlib.profile ~enable "simplification_step";;
+ let simplification_step ~new_cl cl (alist,atable) bag maxvar x =
+ prof_simplification_step.HExtlib.profile (simplification_step ~new_cl cl (alist,atable) bag maxvar) x
+ ;;
+
+ 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
+ | bag,(Some _, None) -> bag,None
+ | bag,(Some _, Some (clause, (alist,atable), newa)) ->
+ keep_simplified_aux ~new_cl:(cl!=clause) clause (alist,atable)
+ bag (newa@newc)
+ else
+ match newc with
+ | [] -> bag, Some (cl, (alist,atable))
+ | hd::tl ->
+ match simplification_step ~new_cl cl
+ (alist,atable) bag maxvar hd with
+ | _,(None,None) -> assert false
+ | bag,(Some _,None) ->
+ keep_simplified_aux ~new_cl cl (alist,atable) bag tl
+ | bag,(None, Some _) -> bag,None
+ | bag,(Some cl1, Some (clause, (alist,atable), newa)) ->
+ 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 prof_keep_simplified = HExtlib.profile ~enable "keep_simplified";;
+ let keep_simplified cl t bag x =
+ prof_keep_simplified.HExtlib.profile (keep_simplified cl t bag) x
+ ;;
+
+ (* this is like simplify but raises Success *)
+ let simplify_goal ~no_demod maxvar table bag g_actives clause =
+ let bag, clause =
+ if no_demod then bag, clause else demodulate bag clause table
+ in
+ if List.exists (are_alpha_eq clause) g_actives then None
+ else match (is_identity_goal clause) with
+ | Some subst -> raise (Success (bag,maxvar,clause,subst))
+ | None ->
+ let (id,lit,vl,_) = clause in
+ (* this optimization makes sense only if we demodulated, since in
+ that case the clause should have been turned into an identity *)
+ if (vl = [] && not(no_demod))
+ then Some (bag,clause)
+ else
+ 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 -> Some (bag,clause)
+ | Some (bag,maxvar,cl,subst) ->
+ debug (lazy "Goal subsumed");
+ raise (Success (bag,maxvar,cl,subst))
+(*
+ match is_subsumed ~unify:true bag maxvar clause table with
+ | None -> Some (bag, clause)
+ | Some ((bag,maxvar),c) ->
+ prerr_endline "Goal subsumed";
+ raise (Success (bag,maxvar,c))
+*)
+ ;;
+
+ let prof_simplify_goal = HExtlib.profile ~enable "simplify_goal";;
+ let simplify_goal ~no_demod maxvar table bag g_actives x =
+ prof_simplify_goal.HExtlib.profile ( simplify_goal ~no_demod maxvar table bag g_actives) x