mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 19:25:36 -05:00
Avoid unnecessary atoms array to list conversions
This commit is contained in:
parent
38b4fde5c1
commit
d1ebc59856
1 changed files with 24 additions and 15 deletions
|
|
@ -342,40 +342,50 @@ module Make
|
||||||
a::atoms, history
|
a::atoms, history
|
||||||
(* General case, we do not know the truth value of a, just let it be. *)
|
(* General case, we do not know the truth value of a, just let it be. *)
|
||||||
in
|
in
|
||||||
let atoms, init = List.fold_left aux ([], []) atoms in
|
let atoms, init = Array.fold_left aux ([], []) atoms in
|
||||||
(* TODO: Why do we sort the atoms here ? *)
|
(* TODO: Why do we sort the atoms here ? *)
|
||||||
List.fast_sort (fun a b -> a.var.vid - b.var.vid) atoms, init
|
List.fast_sort (fun a b -> a.var.vid - b.var.vid) atoms, init
|
||||||
|
|
||||||
|
let arr_to_list arr i =
|
||||||
|
if i >= Array.length arr then []
|
||||||
|
else Array.to_list (Array.sub arr i (Array.length arr - i))
|
||||||
|
|
||||||
let partition atoms =
|
let partition atoms =
|
||||||
(* Parittion litterals for new clauses *)
|
(* Parittion litterals for new clauses *)
|
||||||
let rec partition_aux trues unassigned falses history = function
|
let rec partition_aux trues unassigned falses history i =
|
||||||
| [] -> trues @ unassigned @ falses, history
|
if i >= Array.length atoms then
|
||||||
| a :: r ->
|
trues @ unassigned @ falses, history
|
||||||
|
else begin
|
||||||
|
let a = atoms.(i) in
|
||||||
if a.is_true then
|
if a.is_true then
|
||||||
if a.var.v_level = 0 then raise Trivial
|
if a.var.v_level = 0 then
|
||||||
(* Same as before, a var true at level 0 gives a trivially true clause *)
|
raise Trivial
|
||||||
else (a::trues) @ unassigned @ falses @ r, history
|
(* A var true at level 0 gives a trivially true clause *)
|
||||||
|
else
|
||||||
|
(a :: trues) @ unassigned @ falses @
|
||||||
|
(arr_to_list atoms (i + 1)), history
|
||||||
(* A var true at level > 0 does not change anything, but is unlikely
|
(* A var true at level > 0 does not change anything, but is unlikely
|
||||||
to be watched, so we put prefer to put them at the end. *)
|
to be watched, so we put prefer to put them at the end. *)
|
||||||
else if a.neg.is_true then
|
else if a.neg.is_true then
|
||||||
if a.var.v_level = 0 then begin
|
if a.var.v_level = 0 then begin
|
||||||
match a.var.reason with
|
match a.var.reason with
|
||||||
| Some (Bcp cl) ->
|
| Some (Bcp cl) ->
|
||||||
partition_aux trues unassigned falses (cl :: history) r
|
partition_aux trues unassigned falses (cl :: history) (i + 1)
|
||||||
(* Same as before, a var false at level 0 can be eliminated from the clause,
|
(* Same as before, a var false at level 0 can be eliminated from the clause,
|
||||||
but we need to kepp in mind that we used another clause to simplify it. *)
|
but we need to kepp in mind that we used another clause to simplify it. *)
|
||||||
| Some (Semantic 0) ->
|
| Some (Semantic 0) ->
|
||||||
partition_aux trues unassigned falses history r
|
partition_aux trues unassigned falses history (i + 1)
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
end else
|
end else
|
||||||
partition_aux trues unassigned (a::falses) history r
|
partition_aux trues unassigned (a::falses) history (i + 1)
|
||||||
else
|
else
|
||||||
partition_aux trues (a::unassigned) falses history r
|
partition_aux trues (a::unassigned) falses history (i + 1)
|
||||||
|
end
|
||||||
in
|
in
|
||||||
if decision_level () = 0 then
|
if decision_level () = 0 then
|
||||||
simplify_zero atoms
|
simplify_zero atoms
|
||||||
else
|
else
|
||||||
partition_aux [] [] [] [] atoms
|
partition_aux [] [] [] [] 0
|
||||||
|
|
||||||
(* Compute a progess estimate.
|
(* Compute a progess estimate.
|
||||||
TODO: remove it or use it ? *)
|
TODO: remove it or use it ? *)
|
||||||
|
|
@ -494,8 +504,7 @@ module Make
|
||||||
be able to build a correct proof at the end of proof search. *)
|
be able to build a correct proof at the end of proof search. *)
|
||||||
let simpl_reason = function
|
let simpl_reason = function
|
||||||
| (Bcp cl) as r ->
|
| (Bcp cl) as r ->
|
||||||
let atoms = Array.to_list cl.atoms in
|
let l, history = partition cl.atoms in
|
||||||
let l, history = partition atoms in
|
|
||||||
begin match l with
|
begin match l with
|
||||||
| [ a ] ->
|
| [ a ] ->
|
||||||
if history = [] then r
|
if history = [] then r
|
||||||
|
|
@ -723,7 +732,7 @@ module Make
|
||||||
| History _ -> assert false
|
| History _ -> assert false
|
||||||
in
|
in
|
||||||
try
|
try
|
||||||
let atoms, history = partition (Array.to_list init.atoms) in
|
let atoms, history = partition init.atoms in
|
||||||
let clause =
|
let clause =
|
||||||
if history = [] then init
|
if history = [] then init
|
||||||
else make_clause ?tag:init.tag (fresh_name ()) atoms (History (init :: history))
|
else make_clause ?tag:init.tag (fresh_name ()) atoms (History (init :: history))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue