@@ -521,39 +521,29 @@ struct
521521 let i, (x, y) = Vector. find2i (fun i x y -> x <> y) a_rev b_rev in
522522 let r, diff = Vector. length a_rev - (i + 1 ), x -: y in
523523 let a_r, b_r = Matrix. get_row a r, Matrix. get_row b r in
524- let multiply_by_t' m col_v t i =
525- let zero_vec = Vector. of_list @@ List. init (Matrix. num_rows m - Vector. length col_v) (fun x -> of_int 0 ) in
526- let cs = Vector. append col_v zero_vec in
527- Matrix. map2i (fun i' x c -> if i' < = i then let beta = c /: diff in
524+ let sub_col = Vector. map2 (fun x y -> x -: y) col_a col_b in
525+ let multiply_by_t m t =
526+ let zero_vec = Vector. of_list @@ List. init (Matrix. num_rows m - Vector. length sub_col) (fun x -> of_int 0 ) in
527+ let cs = Vector. append sub_col zero_vec in
528+ Matrix. map2i (fun i' x c -> if i' < = max then let beta = c /: diff in
528529 let mul_t = Vector. apply_with_c ( *: ) beta t in Vector. map2 (-: ) x mul_t else x) m cs
529530 in
530- let sub_col = Vector. map2 (fun x y -> x -: y) col_a col_b in
531- Matrix. remove_row (multiply_by_t' a sub_col a_r max) r, Matrix. remove_row (multiply_by_t' b sub_col b_r max) r, (max - 1 )
531+ Matrix. remove_row (multiply_by_t a a_r) r, Matrix. remove_row (multiply_by_t b b_r) r, (max - 1 )
532532 in
533533 let col_a, col_b = Matrix. get_col a s, Matrix. get_col b s in
534- match Int. compare (Matrix. num_rows a) r, Int. compare (Matrix. num_rows b) r with
535- | 1 , 1 ->
536- let a_rs, b_rs = Vector. nth col_a r, Vector. nth col_b r in
537- if Mpqf. get_den a_rs <> (Mpzf. of_int 1 ) || Mpqf. get_den b_rs <> (Mpzf. of_int 1 ) then failwith " Matrix not normalized" else
538- begin match Int. of_float @@ Mpqf. to_float @@ a_rs, Int. of_float @@ Mpqf. to_float @@ b_rs with
539- | 1 , 1 -> lin_disjunc (r + 1 ) (s + 1 ) a b
540- | 1 , 0 -> lin_disjunc r (s + 1 ) (case_two a r col_b) b
541- | 0 , 1 -> lin_disjunc r (s + 1 ) a (case_two b r col_a)
542- | 0 , 0 -> let new_a, new_b, new_r = case_three a b col_a col_b r in
543- lin_disjunc new_r (s + 1 ) new_a new_b
544- | _ -> failwith " Matrix not normalized" end
545- | 1 , _ -> let a_rs = Vector. nth col_a r in
546- if a_rs = (of_int 1 ) then lin_disjunc r (s + 1 ) (case_two a r col_b) b
547- else
548- let new_a, new_b, new_r = case_three a b col_a col_b r in
549- lin_disjunc new_r (s + 1 ) new_a new_b
550- | _ , 1 -> let b_rs = Vector. nth col_b r in
551- if b_rs = (of_int 1 ) then lin_disjunc r (s + 1 ) a (case_two b r col_a)
552- else
553- let new_a, new_b, new_r = case_three a b col_a col_b r in
554- lin_disjunc new_r (s + 1 ) new_a new_b
555- | _ -> let new_a, new_b, new_r = case_three a b col_a col_b r in
556- lin_disjunc new_r (s + 1 ) new_a new_b
534+ let nth_zero v i = match Vector. nth v i with
535+ | exception Invalid_argument _ -> of_int 0
536+ | x -> x
537+ in
538+ let a_rs, b_rs = nth_zero col_a r, nth_zero col_b r in
539+ if Mpqf. get_den a_rs <> (Mpzf. of_int 1 ) || Mpqf. get_den b_rs <> (Mpzf. of_int 1 ) then failwith " Matrix not normalized" else
540+ begin match Int. of_float @@ Mpqf. to_float @@ a_rs, Int. of_float @@ Mpqf. to_float @@ b_rs with
541+ | 1 , 1 -> lin_disjunc (r + 1 ) (s + 1 ) a b
542+ | 1 , 0 -> lin_disjunc r (s + 1 ) (case_two a r col_b) b
543+ | 0 , 1 -> lin_disjunc r (s + 1 ) a (case_two b r col_a)
544+ | 0 , 0 -> let new_a, new_b, new_r = case_three a b col_a col_b r in
545+ lin_disjunc new_r (s + 1 ) new_a new_b
546+ | _ -> failwith " Matrix not normalized" end
557547 in
558548 match a.d, b.d with
559549 | None , m -> b
0 commit comments