Skip to content

Commit 315dac6

Browse files
appending and normalizing in is_covered_by - all tests pass
1 parent db97f30 commit 315dac6

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/cdomains/affineEquality/arrayImplementation/arrayMatrix.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ module ArrayMatrix: AbstractMatrix =
5757
let add_empty_columns m cols = Timing.wrap "add_empty_cols" (add_empty_columns m) cols
5858

5959
let append_row m row =
60-
let () = Printf.printf "Before append_row m:\n%s\n" (show m) in
6160
let size = num_rows m in
6261
let new_matrix = Array.make_matrix (size + 1) (num_cols m) A.zero in
6362
for i = 0 to size - 1 do
6463
new_matrix.(i) <- m.(i)
6564
done;
6665
new_matrix.(size) <- V.to_array row;
67-
let () = Printf.printf "After append_row m:\n%s\n" (show new_matrix) in
6866
new_matrix
6967

7068
let get_row m n =
@@ -319,12 +317,12 @@ module ArrayMatrix: AbstractMatrix =
319317
let is_covered_by m1 m2 =
320318
(*Performs a partial rref reduction to check if concatenating both matrices and afterwards normalizing them would yield a matrix <> m2 *)
321319
(*Both input matrices must be in rref form!*)
320+
let () = Printf.printf "Is m1 covered by m2?\n m1:\n%sm2:\n%s" (show m1) (show m2) in
322321
if num_rows m1 > num_rows m2 then false else
323-
let m1' = copy m1 in
324-
let m2' = copy m2 in
325322
let p2 = lazy (get_pivot_positions m2) in
326323
try (
327324
for i = 0 to num_rows m1 - 1 do
325+
(* check if there are rows in m1 and m2 that aren't equal *)
328326
if Array.exists2 (<>:) m1.(i) m2.(i) then
329327
let m1_i = Array.copy m1.(i) in
330328
for j = 0 to Array.length m1_i - 2 do

src/cdomains/affineEquality/sparseImplementation/listMatrix.ml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ module ListMatrix: AbstractMatrix =
8787
Timing.wrap "add_empty_cols" (add_empty_columns m) cols
8888

8989
let append_row m row =
90-
let () = Printf.printf "Before append_row m:\n%s\n" (show m) in
91-
let () = Printf.printf "After append_row m:\n%s\n" (show ( m @ [row])) in
9290
m @ [row]
9391

9492
let get_row m n =
@@ -305,23 +303,28 @@ module ListMatrix: AbstractMatrix =
305303
is_linearly_independent_rref new_v xs
306304

307305
let is_covered_by m1 m2 =
306+
Printf.printf "Is m1 covered by m2?\n m1:\n%sm2:\n%s" (show m1) (show m2);
307+
match normalize @@ append_matrices m2 m1 with
308+
| None -> false
309+
| Some m -> let m2' = remove_zero_rows m in List.for_all2 (fun x y -> V.equal x y) m2 m2'
310+
(*let () = Printf.printf "Is m1 covered by m2?\n m1:\n%sm2:\n%s" (show m1) (show m2) in
308311
if num_rows m1 > num_rows m2 then false else
309-
let rec is_covered_by_helper m1 m2 =
310-
match m1 with
311-
| [] -> true
312-
| v1::vs1 ->
313-
let first_non_zero = V.findi_val_opt ((<>:) A.zero) v1 in
314-
match first_non_zero with
315-
| None -> true (* vs1 must also be zero-vectors because of rref *)
316-
| Some (idx, _) ->
317-
let m' = List.drop_while (fun v2 ->
318-
match V.findi_val_opt ((<>:) A.zero) v2 with
319-
| None -> true (* In this case, m2 only has zero rows after that *)
320-
| Some (idx', _) -> idx' < idx
321-
) m2 in (* Only consider the part of m2 where the pivot is at a position useful for deleting first_non_zero of v1*)
322-
let linearly_indep = is_linearly_independent_rref v1 m' in
323-
if linearly_indep then false else is_covered_by_helper vs1 m'
324-
in is_covered_by_helper m1 m2
312+
let rec is_covered_by_helper m1 m2 =
313+
match m1 with
314+
| [] -> true
315+
| v1::vs1 ->
316+
let first_non_zero = V.findi_val_opt ((<>:) A.zero) v1 in
317+
match first_non_zero with
318+
| None -> true (* vs1 must also be zero-vectors because of rref *)
319+
| Some (idx, _) ->
320+
let m' = List.drop_while (fun v2 ->
321+
match V.findi_val_opt ((<>:) A.zero) v2 with
322+
| None -> true (* In this case, m2 only has zero rows after that *)
323+
| Some (idx', _) -> idx' < idx
324+
) m2 in (* Only consider the part of m2 where the pivot is at a position useful for deleting first_non_zero of v1*)
325+
let linearly_indep = is_linearly_independent_rref v1 m' in
326+
if linearly_indep then false else is_covered_by_helper vs1 m'
327+
in is_covered_by_helper m1 m2*)
325328

326329
let is_covered_by m1 m2 = Timing.wrap "is_covered_by" (is_covered_by m1) m2
327330

0 commit comments

Comments
 (0)