From 42fd431f308d4b3cb890186bf4d474d8493ad33c Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 23 Feb 2024 14:16:05 +0100 Subject: [PATCH] Remove outdated linear solving methods --- src/arb/ComplexMat.jl | 8 --- src/arb/RealMat.jl | 8 --- src/arb/acb_mat.jl | 8 --- src/arb/arb_mat.jl | 8 --- src/flint/fmpq_mat.jl | 28 --------- src/flint/fmpz_mat.jl | 25 -------- src/flint/fmpz_mod_mat.jl | 16 +---- src/flint/fq_default_mat.jl | 35 ----------- src/flint/fq_mat.jl | 35 ----------- src/flint/fq_nmod_mat.jl | 35 ----------- src/flint/gfp_fmpz_mat.jl | 22 +++++++ src/flint/gfp_mat.jl | 22 ------- src/flint/nmod_mat.jl | 29 +++++---- test/arb/ComplexMat-test.jl | 6 -- test/arb/RealMat-test.jl | 6 -- test/arb/acb_mat-test.jl | 6 -- test/arb/arb_mat-test.jl | 6 -- test/flint/fmpq_mat-test.jl | 97 +------------------------------ test/flint/fmpz_mat-test.jl | 12 ---- test/flint/fmpz_mod_mat-test.jl | 24 -------- test/flint/fq_default_mat-test.jl | 91 +---------------------------- test/flint/fq_mat-test.jl | 89 ---------------------------- test/flint/fq_nmod_mat-test.jl | 89 ---------------------------- test/flint/gfp_fmpz_mat-test.jl | 2 +- test/flint/gfp_mat-test.jl | 89 ---------------------------- test/flint/nmod_mat-test.jl | 77 +++++++++++++++++++++++- 26 files changed, 119 insertions(+), 754 deletions(-) diff --git a/src/arb/ComplexMat.jl b/src/arb/ComplexMat.jl index 36b06f3597..dc70245376 100644 --- a/src/arb/ComplexMat.jl +++ b/src/arb/ComplexMat.jl @@ -574,14 +574,6 @@ function _solve!(z::ComplexMat, x::ComplexMat, y::ComplexMat) nothing end -function _solve(x::ComplexMat, y::ComplexMat) - ncols(x) != nrows(x) && error("First argument must be square") - ncols(x) != nrows(y) && error("Matrix dimensions are wrong") - z = similar(y) - _solve!(z, x, y) - return z -end - function _solve_lu_precomp!(z::ComplexMat, P::Generic.Perm, LU::ComplexMat, y::ComplexMat) Q = inv(P) ccall((:acb_mat_solve_lu_precomp, libarb), Nothing, diff --git a/src/arb/RealMat.jl b/src/arb/RealMat.jl index 0a3925c59b..c90deef2a0 100644 --- a/src/arb/RealMat.jl +++ b/src/arb/RealMat.jl @@ -516,14 +516,6 @@ function _solve!(z::RealMat, x::RealMat, y::RealMat) nothing end -function _solve(x::RealMat, y::RealMat) - ncols(x) != nrows(x) && error("First argument must be square") - ncols(x) != nrows(y) && error("Matrix dimensions are wrong") - z = similar(y) - _solve!(z, x, y) - return z -end - function _solve_lu_precomp!(z::RealMat, P::Generic.Perm, LU::RealMat, y::RealMat) Q = inv(P) ccall((:arb_mat_solve_lu_precomp, libarb), Nothing, diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index feba685718..cc3d49e186 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -577,14 +577,6 @@ function _solve!(z::AcbMatrix, x::AcbMatrix, y::AcbMatrix) nothing end -function _solve(x::AcbMatrix, y::AcbMatrix) - ncols(x) != nrows(x) && error("First argument must be square") - ncols(x) != nrows(y) && error("Matrix dimensions are wrong") - z = similar(y) - _solve!(z, x, y) - return z -end - function _solve_lu_precomp!(z::AcbMatrix, P::Generic.Perm, LU::AcbMatrix, y::AcbMatrix) Q = inv(P) ccall((:acb_mat_solve_lu_precomp, libarb), Nothing, diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index 416bd0968c..8ae338f966 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -529,14 +529,6 @@ function _solve!(z::ArbMatrix, x::ArbMatrix, y::ArbMatrix) nothing end -function _solve(x::ArbMatrix, y::ArbMatrix) - ncols(x) != nrows(x) && error("First argument must be square") - ncols(x) != nrows(y) && error("Matrix dimensions are wrong") - z = similar(y) - _solve!(z, x, y) - return z -end - function _solve_lu_precomp!(z::ArbMatrix, P::Generic.Perm, LU::ArbMatrix, y::ArbMatrix) Q = inv(P) ccall((:arb_mat_solve_lu_precomp, libarb), Nothing, diff --git a/src/flint/fmpq_mat.jl b/src/flint/fmpq_mat.jl index e2acaf689a..3e437561f8 100644 --- a/src/flint/fmpq_mat.jl +++ b/src/flint/fmpq_mat.jl @@ -660,13 +660,6 @@ end # ############################################################################### -function _solve(a::QQMatrix, b::QQMatrix) - nrows(b) != nrows(a) && error("Incompatible dimensions in solve") - fl, z = _can_solve_with_solution(a, b) - !fl && error("System is inconsistent") - return z -end - @doc raw""" _solve_dixon(a::QQMatrix, b::QQMatrix) @@ -683,27 +676,6 @@ function _solve_dixon(a::QQMatrix, b::QQMatrix) return z end -function _can_solve_with_solution(a::QQMatrix, b::QQMatrix; side::Symbol = :right) - if side == :left - (ncols(a) != ncols(b)) && error("Matrices must have same number of columns") - (f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right) - return (f, transpose(x)) - elseif side == :right - (nrows(a) != nrows(b)) && error("Matrices must have same number of rows") - x = similar(a, ncols(a), ncols(b)) - r = ccall((:fmpq_mat_can_solve_multi_mod, libflint), Cint, - (Ref{QQMatrix}, Ref{QQMatrix}, Ref{QQMatrix}), x, a, b) - return Bool(r), x - else - error("Unsupported argument :$side for side: Must be :left or :right.") - end -end - -function _can_solve(a::QQMatrix, b::QQMatrix; side::Symbol = :right) - fl, _ = _can_solve_with_solution(a, b, side = side) - return fl -end - function Solve._can_solve_internal_no_check(A::QQMatrix, b::QQMatrix, task::Symbol; side::Symbol = :left) if side === :left fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right) diff --git a/src/flint/fmpz_mat.jl b/src/flint/fmpz_mat.jl index 5bce25b40c..301f30a4a4 100644 --- a/src/flint/fmpz_mat.jl +++ b/src/flint/fmpz_mat.jl @@ -1250,21 +1250,6 @@ end # ############################################################################### -@doc raw""" - _solve(a::ZZMatrix, b::ZZMatrix) -> ZZMatrix - -Return a matrix $x$ such that $ax = b$. An exception is raised -if this is not possible. -""" -function _solve(a::ZZMatrix, b::ZZMatrix) - nrows(b) != nrows(a) && error("Incompatible dimensions in solve") - fl, z = _cansolve(a, b) - if !fl - error("system is inconsistent") - end - return z -end - @doc raw""" _cansolve(a::ZZMatrix, b::ZZMatrix) -> Bool, ZZMatrix @@ -1443,16 +1428,6 @@ function AbstractAlgebra._hcat(A::AbstractVector{ZZMatrix}) return M end -#to override the generic one in AA -function _can_solve_with_solution(a::ZZMatrix, b::ZZMatrix; side::Symbol = :right) - if side == :left - fl, x = Nemo._cansolve(transpose(a), transpose(b)) - return fl, transpose(x) - end - return Nemo._cansolve(a, b) -end - - @doc raw""" _cansolve_with_nullspace(a::ZZMatrix, b::ZZMatrix) -> Bool, ZZMatrix, ZZMatrix diff --git a/src/flint/fmpz_mod_mat.jl b/src/flint/fmpz_mod_mat.jl index 8e873378f2..b089a3437b 100644 --- a/src/flint/fmpz_mod_mat.jl +++ b/src/flint/fmpz_mod_mat.jl @@ -485,21 +485,6 @@ end # ################################################################################ -#= Not implemented in Flint yet - -function _solve(x::T, y::T) where T <: Zmod_fmpz_mat - (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") - !is_square(x)&& error("First argument not a square matrix in solve") - (y.r != x.r) || y.c != 1 && ("Not a column vector in solve") - z = similar(y) - r = ccall((:fmpz_mod_mat_solve, libflint), Int, - (Ref{T}, Ref{T}, Ref{T}), z, x, y) - !Bool(r) && error("Singular matrix in solve") - return z -end - -=# - function Solve._can_solve_internal_no_check(A::ZZModMatrix, b::ZZModMatrix, task::Symbol; side::Symbol = :left) check_parent(A, b) if side === :left @@ -508,6 +493,7 @@ function Solve._can_solve_internal_no_check(A::ZZModMatrix, b::ZZModMatrix, task end x = similar(A, ncols(A), ncols(b)) + # This is probably only correct if the characteristic is prime fl = ccall((:fmpz_mod_mat_can_solve, libflint), Cint, (Ref{ZZModMatrix}, Ref{ZZModMatrix}, Ref{ZZModMatrix}), x, A, b) if task === :only_check || task === :with_solution diff --git a/src/flint/fq_default_mat.jl b/src/flint/fq_default_mat.jl index 79b3b52686..33e5227c75 100644 --- a/src/flint/fq_default_mat.jl +++ b/src/flint/fq_default_mat.jl @@ -415,41 +415,6 @@ end # ################################################################################ -function _solve(x::FqMatrix, y::FqMatrix) - (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") - !is_square(x)&& error("First argument not a square matrix in _solve") - (nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve") - z = similar(y) - r = ccall((:fq_default_mat_solve, libflint), Int, - (Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqField}), - z, x, y, base_ring(x)) - !Bool(r) && error("Singular matrix in _solve") - return z -end - -function _can_solve_with_solution(a::FqMatrix, b::FqMatrix; side::Symbol = :right) - (base_ring(a) != base_ring(b)) && error("Matrices must have same base ring") - if side == :left - (ncols(a) != ncols(b)) && error("Matrices must have same number of columns") - (f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right) - return (f, transpose(x)) - elseif side == :right - (nrows(a) != nrows(b)) && error("Matrices must have same number of rows") - x = similar(a, ncols(a), ncols(b)) - r = ccall((:fq_default_mat_can_solve, libflint), Cint, - (Ref{FqMatrix}, Ref{FqMatrix}, Ref{FqMatrix}, - Ref{FqField}), x, a, b, base_ring(a)) - return Bool(r), x - else - error("Unsupported argument :$side for side: Must be :left or :right.") - end -end - -function _can_solve(a::FqMatrix, b::FqMatrix; side::Symbol = :right) - fl, _ = _can_solve_with_solution(a, b, side = side) - return fl -end - function Solve._can_solve_internal_no_check(A::FqMatrix, b::FqMatrix, task::Symbol; side::Symbol = :left) check_parent(A, b) if side === :left diff --git a/src/flint/fq_mat.jl b/src/flint/fq_mat.jl index b1b13a5a57..051e52aa66 100644 --- a/src/flint/fq_mat.jl +++ b/src/flint/fq_mat.jl @@ -422,41 +422,6 @@ end # ################################################################################ -function _solve(x::FqPolyRepMatrix, y::FqPolyRepMatrix) - (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") - !is_square(x)&& error("First argument not a square matrix in _solve") - (nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve") - z = similar(y) - r = ccall((:fq_mat_solve, libflint), Int, - (Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepField}), - z, x, y, base_ring(x)) - !Bool(r) && error("Singular matrix in _solve") - return z -end - -function _can_solve_with_solution(a::FqPolyRepMatrix, b::FqPolyRepMatrix; side::Symbol = :right) - (base_ring(a) != base_ring(b)) && error("Matrices must have same base ring") - if side == :left - (ncols(a) != ncols(b)) && error("Matrices must have same number of columns") - (f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right) - return (f, transpose(x)) - elseif side == :right - (nrows(a) != nrows(b)) && error("Matrices must have same number of rows") - x = similar(a, ncols(a), ncols(b)) - r = ccall((:fq_mat_can_solve, libflint), Cint, - (Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, Ref{FqPolyRepMatrix}, - Ref{FqPolyRepField}), x, a, b, base_ring(a)) - return Bool(r), x - else - error("Unsupported argument :$side for side: Must be :left or :right.") - end -end - -function _can_solve(a::FqPolyRepMatrix, b::FqPolyRepMatrix; side::Symbol = :right) - fl, _ = _can_solve_with_solution(a, b, side = side) - return fl -end - function Solve._can_solve_internal_no_check(A::FqPolyRepMatrix, b::FqPolyRepMatrix, task::Symbol; side::Symbol = :left) check_parent(A, b) if side === :left diff --git a/src/flint/fq_nmod_mat.jl b/src/flint/fq_nmod_mat.jl index 71b677bdf0..1650684f5a 100644 --- a/src/flint/fq_nmod_mat.jl +++ b/src/flint/fq_nmod_mat.jl @@ -410,41 +410,6 @@ end # ################################################################################ -function _solve(x::fqPolyRepMatrix, y::fqPolyRepMatrix) - (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") - !is_square(x)&& error("First argument not a square matrix in _solve") - (nrows(y) != nrows(x)) || ncols(y) != 1 && ("Not a column vector in _solve") - z = similar(y) - r = ccall((:fq_nmod_mat_solve, libflint), Int, - (Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepField}), - z, x, y, base_ring(x)) - !Bool(r) && error("Singular matrix in _solve") - return z -end - -function _can_solve_with_solution(a::fqPolyRepMatrix, b::fqPolyRepMatrix; side::Symbol = :right) - (base_ring(a) != base_ring(b)) && error("Matrices must have same base ring") - if side == :left - (ncols(a) != ncols(b)) && error("Matrices must have same number of columns") - (f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right) - return (f, transpose(x)) - elseif side == :right - (nrows(a) != nrows(b)) && error("Matrices must have same number of rows") - x = similar(a, ncols(a), ncols(b)) - r = ccall((:fq_nmod_mat_can_solve, libflint), Cint, - (Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, Ref{fqPolyRepMatrix}, - Ref{fqPolyRepField}), x, a, b, base_ring(a)) - return Bool(r), x - else - error("Only side = :right or :left is supported (:$side)") - end -end - -function _can_solve(a::fqPolyRepMatrix, b::fqPolyRepMatrix; side::Symbol = :right) - fl, _ = _can_solve_with_solution(a, b, side = side) - return fl -end - function Solve._can_solve_internal_no_check(A::fqPolyRepMatrix, b::fqPolyRepMatrix, task::Symbol; side::Symbol = :left) check_parent(A, b) if side === :left diff --git a/src/flint/gfp_fmpz_mat.jl b/src/flint/gfp_fmpz_mat.jl index e0acebbcfe..9771a31edd 100644 --- a/src/flint/gfp_fmpz_mat.jl +++ b/src/flint/gfp_fmpz_mat.jl @@ -376,3 +376,25 @@ function nullspace(M::FpMatrix) (Ref{FpMatrix}, Ref{FpMatrix}, Ref{FpField}), N, M, base_ring(M)) return nullity, view(N, 1:nrows(N), 1:nullity) end + +################################################################################ +# +# Linear solving +# +################################################################################ + +function Solve._can_solve_internal_no_check(A::FpMatrix, b::FpMatrix, task::Symbol; side::Symbol = :left) + check_parent(A, b) + if side === :left + fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right) + return fl, transpose(sol), transpose(K) + end + + x = similar(A, ncols(A), ncols(b)) + fl = ccall((:fmpz_mod_mat_can_solve, libflint), Cint, + (Ref{FpMatrix}, Ref{FpMatrix}, Ref{FpMatrix}), x, A, b) + if task === :only_check || task === :with_solution + return Bool(fl), x, zero(A, 0, 0) + end + return Bool(fl), x, kernel(A, side = :right) +end diff --git a/src/flint/gfp_mat.jl b/src/flint/gfp_mat.jl index 3b2f898e51..0972feaed8 100644 --- a/src/flint/gfp_mat.jl +++ b/src/flint/gfp_mat.jl @@ -290,28 +290,6 @@ end # ################################################################################ -function _can_solve_with_solution(a::fpMatrix, b::fpMatrix; side::Symbol = :right) - (base_ring(a) != base_ring(b)) && error("Matrices must have same base ring") - if side == :left - (ncols(a) != ncols(b)) && error("Matrices must have same number of columns") - (f, x) = _can_solve_with_solution(transpose(a), transpose(b); side=:right) - return (f, transpose(x)) - elseif side == :right - (nrows(a) != nrows(b)) && error("Matrices must have same number of rows") - x = similar(a, ncols(a), ncols(b)) - r = ccall((:nmod_mat_can_solve, libflint), Cint, - (Ref{fpMatrix}, Ref{fpMatrix}, Ref{fpMatrix}), x, a, b) - return Bool(r), x - else - error("Unsupported argument :$side for side: Must be :left or :right.") - end -end - -function _can_solve(a::fpMatrix, b::fpMatrix; side::Symbol = :right) - fl, _ = _can_solve_with_solution(a, b, side = side) - return fl -end - function Solve._can_solve_internal_no_check(A::fpMatrix, b::fpMatrix, task::Symbol; side::Symbol = :left) check_parent(A, b) if side === :left diff --git a/src/flint/nmod_mat.jl b/src/flint/nmod_mat.jl index c5b749b5f2..dc448c91cd 100644 --- a/src/flint/nmod_mat.jl +++ b/src/flint/nmod_mat.jl @@ -486,17 +486,6 @@ end # ################################################################################ -function _solve(x::T, y::T) where T <: Zmodn_mat - (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") - !is_square(x)&& error("First argument not a square matrix in _solve") - (y.r != x.r) || y.c != 1 && ("Not a column vector in _solve") - z = similar(y) - r = ccall((:nmod_mat_solve, libflint), Int, - (Ref{T}, Ref{T}, Ref{T}), z, x, y) - !Bool(r) && error("Singular matrix in _solve") - return z -end - function AbstractAlgebra._solve_triu(x::T, y::T) where T <: Zmodn_mat (base_ring(x) != base_ring(y)) && error("Matrices must have same base ring") is_upper_trangular(x) || error("Matrix must be upper triangular") @@ -523,6 +512,24 @@ function AbstractAlgebra._solve_tril!(A::T, B::T, C::T, unit::Int = 0) where T < ccall((:nmod_mat_solve_tril, Nemo.libflint), Cvoid, (Ref{T}, Ref{T}, Ref{T}, Cint), A, B, C, unit) end +function Solve._can_solve_internal_no_check(A::zzModMatrix, b::zzModMatrix, task::Symbol; side::Symbol = :left) + check_parent(A, b) + if side === :left + fl, sol, K = Solve._can_solve_internal_no_check(transpose(A), transpose(b), task, side = :right) + return fl, transpose(sol), transpose(K) + end + + x = similar(A, ncols(A), ncols(b)) + # This is probably only correct if the characteristic is prime + fl = ccall((:nmod_mat_can_solve, libflint), Cint, + (Ref{zzModMatrix}, Ref{zzModMatrix}, Ref{zzModMatrix}), + x, A, b) + if task === :only_check || task === :with_solution + return Bool(fl), x, zero(A, 0, 0) + end + return Bool(fl), x, kernel(A, side = :right) +end + ################################################################################ # # LU decomposition diff --git a/test/arb/ComplexMat-test.jl b/test/arb/ComplexMat-test.jl index 48b42d22cd..dd70d12652 100644 --- a/test/arb/ComplexMat-test.jl +++ b/test/arb/ComplexMat-test.jl @@ -432,12 +432,6 @@ end @test overlaps(L*U, p*A) @test r == 3 - y = Nemo._solve(A, transpose(b)) - - @test overlaps(A * y, transpose(b)) - - @test contains(transpose(y), ZZ[1 1 1]) - Nemo.lu!(p, A) y = Nemo._solve_lu_precomp(p, A, transpose(b)) diff --git a/test/arb/RealMat-test.jl b/test/arb/RealMat-test.jl index e9abf98f0e..56e6051e67 100644 --- a/test/arb/RealMat-test.jl +++ b/test/arb/RealMat-test.jl @@ -398,12 +398,6 @@ end @test overlaps(L*U, p*A) @test r == 3 - y = Nemo._solve(A, transpose(b)) - - @test overlaps(A*y, transpose(b)) - - @test contains(transpose(y), ZZ[1 1 1]) - Nemo.lu!(p, A) y = Nemo._solve_lu_precomp(p, A, transpose(b)) diff --git a/test/arb/acb_mat-test.jl b/test/arb/acb_mat-test.jl index f1d034438b..25a1e92025 100644 --- a/test/arb/acb_mat-test.jl +++ b/test/arb/acb_mat-test.jl @@ -432,12 +432,6 @@ end @test overlaps(L*U, p*A) @test r == 3 - y = Nemo._solve(A, transpose(b)) - - @test overlaps(A * y, transpose(b)) - - @test contains(transpose(y), ZZ[1 1 1]) - Nemo.lu!(p, A) y = Nemo._solve_lu_precomp(p, A, transpose(b)) diff --git a/test/arb/arb_mat-test.jl b/test/arb/arb_mat-test.jl index bc167bffe0..1c295c9cc0 100644 --- a/test/arb/arb_mat-test.jl +++ b/test/arb/arb_mat-test.jl @@ -418,12 +418,6 @@ end @test overlaps(L*U, p*A) @test r == 3 - y = Nemo._solve(A, transpose(b)) - - @test overlaps(A*y, transpose(b)) - - @test contains(transpose(y), ZZ[1 1 1]) - Nemo.lu!(p, A) y = Nemo._solve_lu_precomp(p, A, transpose(b)) diff --git a/test/flint/fmpq_mat-test.jl b/test/flint/fmpq_mat-test.jl index 24ca3834b2..0cc5cd3fde 100644 --- a/test/flint/fmpq_mat-test.jl +++ b/test/flint/fmpq_mat-test.jl @@ -553,106 +553,13 @@ end B = T([QQFieldElem(4), 5, 7]) - X = Nemo._solve(A, B) + X = solve(A, B, side = :right) @test X == T([3, -24, 14]) @test A*X == B - Y = Nemo._solve_dixon(A, B) - - @test X == Y - - m1 = [1 1; 1 0; 1 0] - m2 = [ 1 0 ; 0 1; 0 1 ] - m1Q = matrix(QQ, m1) - m2Q = matrix(QQ, m2); - - N = Nemo._solve(m1Q, m2Q) - - @test N == matrix(QQ, 2, 2, [0 1; 1 -1]) - - for i in 1:10 - m = rand(0:10) - n = rand(0:10) - k = rand(0:10) - - M = matrix_space(QQ, n, k) - N = matrix_space(QQ, n, m) - - A = rand(M, -10:10) - B = rand(N, -10:10) - - fl, X = Nemo._can_solve_with_solution(A, B) - - if fl - @test A * X == B - end - end - - A = matrix(QQ, 2, 2, [1, 2, 2, 5]) - B = matrix(QQ, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(QQ, 2, 2, [1, 2, 2, 4]) - B = matrix(QQ, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(QQ, 2, 2, [1, 2, 2, 4]) - B = matrix(QQ, 2, 1, [1, 3]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - @test !Nemo._can_solve(A, B) - - A = zero_matrix(QQ, 2, 3) - B = identity_matrix(QQ, 3) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B) - - # Transpose - A = transpose(matrix(QQ, 2, 2, [1, 2, 2, 5])) - B = transpose(matrix(QQ, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(QQ, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(QQ, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(QQ, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(QQ, 2, 1, [1, 3])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl - @test !Nemo._can_solve(A, B, side = :left) - - A = transpose(zero_matrix(QQ, 2, 3)) - B = transpose(identity_matrix(QQ, 3)) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :left) - - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :garbage) - @test_throws ErrorException Nemo._can_solve(A, B, side = :garbage) -end - -@testset "QQMatrix.Solve.solve" begin - S = matrix_space(QQ, 3, 3) - - A = S([QQFieldElem(2) 3 5; 1 4 7; 9 2 2]) - - T = matrix_space(QQ, 3, 1) - - B = T([QQFieldElem(4), 5, 7]) - - X = solve(A, B, side = :right) + X = Nemo._solve_dixon(A, B) @test X == T([3, -24, 14]) diff --git a/test/flint/fmpz_mat-test.jl b/test/flint/fmpz_mat-test.jl index fc83e98f4f..0e20206894 100644 --- a/test/flint/fmpz_mat-test.jl +++ b/test/flint/fmpz_mat-test.jl @@ -663,20 +663,8 @@ end B = T([ZZRingElem(4), 5, 7]) - X = Nemo._solve(A, B) - - @test X == T([3, -24, 14]) - @test A*X == B - - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl && A * X == B - A = matrix(ZZ, 2, 2, [1, 0, 0, 0]) B = matrix(ZZ, 2, 2, [0, 0, 0, 1]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl fl, X = Nemo._cansolve_with_nullspace(A, B) @test !fl diff --git a/test/flint/fmpz_mod_mat-test.jl b/test/flint/fmpz_mod_mat-test.jl index 9a91fc5ab1..deeab7e547 100644 --- a/test/flint/fmpz_mod_mat-test.jl +++ b/test/flint/fmpz_mod_mat-test.jl @@ -563,31 +563,7 @@ end @test_throws ErrorException inv(matrix(R, 2, 1, [1, 1])) end -#= Not implemented in Flint yet - @testset "ZZModMatrix.solve" begin - Z17, = residue_ring(ZZ, ZZ(17)) - R = matrix_space(Z17, 3, 3) - S = matrix_space(Z17, 3, 4) - - a = R([ 1 2 3 ; 3 2 1 ; 0 0 2 ]) - - b = S([ 2 1 0 1; 0 0 0 0; 0 1 2 0 ]) - - c = a*b - - d = Nemo._solve(a,c) - - @test d == b - - a = zero(R) - - @test_throws ErrorException Nemo._solve(a,c) -end - -=# - -@testset "ZZModMatrix.Solve.solve" begin Z17, = residue_ring(ZZ, ZZ(17)) a = matrix(Z17, [1 2 3; 3 2 1; 0 0 2]) b = matrix(Z17, [2 1 0 1; 0 0 0 0; 0 1 2 0]) diff --git a/test/flint/fq_default_mat-test.jl b/test/flint/fq_default_mat-test.jl index b2216f49c7..e8013dc7eb 100644 --- a/test/flint/fq_default_mat-test.jl +++ b/test/flint/fq_default_mat-test.jl @@ -564,95 +564,6 @@ end c = a*b - d = Nemo._solve(a,c) - - @test d == b - - a = zero(R) - - @test_throws ErrorException Nemo._solve(a,c) - - for i in 1:10 - m = rand(0:10) - n = rand(0:10) - k = rand(0:10) - - M = matrix_space(F17, n, k) - N = matrix_space(F17, n, m) - - A = rand(M) - B = rand(N) - - fl, X = Nemo._can_solve_with_solution(A, B) - - if fl - @test A * X == B - end - end - - A = matrix(F17, 2, 2, [1, 2, 2, 5]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 3]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - @test !Nemo._can_solve(A, B) - - A = zero_matrix(F17, 2, 3) - B = identity_matrix(F17, 3) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 5])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 3])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl - @test !Nemo._can_solve(A, B, side = :left) - - A = transpose(zero_matrix(F17, 2, 3)) - B = transpose(identity_matrix(F17, 3)) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :left) - - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :garbage) - @test_throws ErrorException Nemo._can_solve(A, B, side = :garbage) -end - -@testset "FqMatrix.Solve.solve" begin - F17, _ = finite_field(ZZRingElem(17), 1, "a") - R = matrix_space(F17, 3, 3) - S = matrix_space(F17, 3, 4) - - a = R([ 1 2 3 ; 3 2 1 ; 0 0 2 ]) - - b = S([ 2 1 0 1; 0 0 0 0; 0 1 2 0 ]) - - c = a*b - d = solve(a, c, side = :right) @test d == b @@ -699,7 +610,7 @@ end B = matrix(F17, 2, 1, [1, 3]) fl, X = can_solve_with_solution(A, B, side = :right) @test !fl - @test !Nemo._can_solve(A, B) + @test !can_solve(A, B, side = :right) A = zero_matrix(F17, 2, 3) B = identity_matrix(F17, 3) diff --git a/test/flint/fq_mat-test.jl b/test/flint/fq_mat-test.jl index 522ddb8a38..f847acf55f 100644 --- a/test/flint/fq_mat-test.jl +++ b/test/flint/fq_mat-test.jl @@ -552,95 +552,6 @@ end c = a*b - d = Nemo._solve(a,c) - - @test d == b - - a = zero(R) - - @test_throws ErrorException Nemo._solve(a,c) - - for i in 1:10 - m = rand(0:10) - n = rand(0:10) - k = rand(0:10) - - M = matrix_space(F17, n, k) - N = matrix_space(F17, n, m) - - A = rand(M) - B = rand(N) - - fl, X = Nemo._can_solve_with_solution(A, B) - - if fl - @test A * X == B - end - end - - A = matrix(F17, 2, 2, [1, 2, 2, 5]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 3]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - @test !Nemo._can_solve(A, B) - - A = zero_matrix(F17, 2, 3) - B = identity_matrix(F17, 3) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 5])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 3])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl - @test !Nemo._can_solve(A, B, side = :left) - - A = transpose(zero_matrix(F17, 2, 3)) - B = transpose(identity_matrix(F17, 3)) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :left) - - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :garbage) - @test_throws ErrorException Nemo._can_solve(A, B, side = :garbage) -end - -@testset "FqPolyRepMatrix.Solve.solve" begin - F17, _ = Native.finite_field(ZZRingElem(17), 1, "a") - R = matrix_space(F17, 3, 3) - S = matrix_space(F17, 3, 4) - - a = R([ 1 2 3 ; 3 2 1 ; 0 0 2 ]) - - b = S([ 2 1 0 1; 0 0 0 0; 0 1 2 0 ]) - - c = a*b - d = solve(a, c, side = :right) @test d == b diff --git a/test/flint/fq_nmod_mat-test.jl b/test/flint/fq_nmod_mat-test.jl index 2148f71ae8..1d17b9b542 100644 --- a/test/flint/fq_nmod_mat-test.jl +++ b/test/flint/fq_nmod_mat-test.jl @@ -552,95 +552,6 @@ end c = a*b - d = Nemo._solve(a,c) - - @test d == b - - a = zero(R) - - @test_throws ErrorException Nemo._solve(a,c) - - for i in 1:10 - m = rand(0:10) - n = rand(0:10) - k = rand(0:10) - - M = matrix_space(F17, n, k) - N = matrix_space(F17, n, m) - - A = rand(M) - B = rand(N) - - fl, X = Nemo._can_solve_with_solution(A, B) - - if fl - @test A * X == B - end - end - - A = matrix(F17, 2, 2, [1, 2, 2, 5]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(F17, 2, 2, [1, 2, 2, 4]) - B = matrix(F17, 2, 1, [1, 3]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - @test !Nemo._can_solve(A, B) - - A = zero_matrix(F17, 2, 3) - B = identity_matrix(F17, 3) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 5])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(F17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(F17, 2, 1, [1, 3])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl - @test !Nemo._can_solve(A, B, side = :left) - - A = transpose(zero_matrix(F17, 2, 3)) - B = transpose(identity_matrix(F17, 3)) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :left) - - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :garbage) - @test_throws ErrorException Nemo._can_solve(A, B, side = :garbage) -end - -@testset "fqPolyRepMatrix.Solve.solve" begin - F17, _ = Native.finite_field(17, 1, "a") - R = matrix_space(F17, 3, 3) - S = matrix_space(F17, 3, 4) - - a = R([ 1 2 3 ; 3 2 1 ; 0 0 2 ]) - - b = S([ 2 1 0 1; 0 0 0 0; 0 1 2 0 ]) - - c = a*b - d = solve(a, c, side = :right) @test d == b diff --git a/test/flint/gfp_fmpz_mat-test.jl b/test/flint/gfp_fmpz_mat-test.jl index 451b14e676..8d97940d34 100644 --- a/test/flint/gfp_fmpz_mat-test.jl +++ b/test/flint/gfp_fmpz_mat-test.jl @@ -760,7 +760,7 @@ end @test nrows(K) == 1 end -@testset "FpMatrix.Solve.solve" begin +@testset "FpMatrix.solve" begin F17, _ = Native.finite_field(ZZRingElem(17)) R = matrix_space(F17, 3, 3) S = matrix_space(F17, 3, 4) diff --git a/test/flint/gfp_mat-test.jl b/test/flint/gfp_mat-test.jl index ca7fc29acd..5cf067e806 100644 --- a/test/flint/gfp_mat-test.jl +++ b/test/flint/gfp_mat-test.jl @@ -603,95 +603,6 @@ end c = a*b - d = Nemo._solve(a,c) - - @test d == b - - a = zero(R) - - @test_throws ErrorException Nemo._solve(a,c) - - for i in 1:10 - m = rand(0:10) - n = rand(0:10) - k = rand(0:10) - - M = matrix_space(Z17, n, k) - N = matrix_space(Z17, n, m) - - A = rand(M) - B = rand(N) - - fl, X = Nemo._can_solve_with_solution(A, B) - - if fl - @test A * X == B - end - end - - A = matrix(Z17, 2, 2, [1, 2, 2, 5]) - B = matrix(Z17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(Z17, 2, 2, [1, 2, 2, 4]) - B = matrix(Z17, 2, 1, [1, 2]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test fl - @test A * X == B - @test Nemo._can_solve(A, B) - - A = matrix(Z17, 2, 2, [1, 2, 2, 4]) - B = matrix(Z17, 2, 1, [1, 3]) - fl, X = Nemo._can_solve_with_solution(A, B) - @test !fl - @test !Nemo._can_solve(A, B) - - A = zero_matrix(Z17, 2, 3) - B = identity_matrix(Z17, 3) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B) - - A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 5])) - B = transpose(matrix(Z17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(Z17, 2, 1, [1, 2])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test fl - @test X * A == B - @test Nemo._can_solve(A, B, side = :left) - - A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 4])) - B = transpose(matrix(Z17, 2, 1, [1, 3])) - fl, X = Nemo._can_solve_with_solution(A, B, side = :left) - @test !fl - @test !Nemo._can_solve(A, B, side = :left) - - A = transpose(zero_matrix(Z17, 2, 3)) - B = transpose(identity_matrix(Z17, 3)) - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :left) - - @test_throws ErrorException Nemo._can_solve_with_solution(A, B, side = :garbage) - @test_throws ErrorException Nemo._can_solve(A, B, side = :garbage) -end - -@testset "fpMatrix.Solve.solve" begin - Z17 = Native.GF(17) - R = matrix_space(Z17, 3, 3) - S = matrix_space(Z17, 3, 4) - - a = R([ 1 2 3 ; 3 2 1 ; 0 0 2 ]) - - b = S([ 2 1 0 1; 0 0 0 0; 0 1 2 0 ]) - - c = a*b - d = solve(a, c, side = :right) @test d == b diff --git a/test/flint/nmod_mat-test.jl b/test/flint/nmod_mat-test.jl index 3adcfd1c82..f194a8b290 100644 --- a/test/flint/nmod_mat-test.jl +++ b/test/flint/nmod_mat-test.jl @@ -596,7 +596,7 @@ end end @testset "zzModMatrix.solve" begin - Z17, = residue_ring(ZZ,17) + Z17, = residue_ring(ZZ, 17) R = matrix_space(Z17, 3, 3) S = matrix_space(Z17, 3, 4) @@ -606,13 +606,84 @@ end c = a*b - d = Nemo._solve(a,c) + d = solve(a, c, side = :right) @test d == b a = zero(R) - @test_throws ErrorException Nemo._solve(a,c) + @test_throws ArgumentError solve(a, c, side = :right) + + for i in 1:10 + m = rand(0:10) + n = rand(0:10) + k = rand(0:10) + + M = matrix_space(Z17, n, k) + N = matrix_space(Z17, n, m) + + A = rand(M) + B = rand(N) + + fl, X, K = can_solve_with_solution_and_kernel(A, B, side = :right) + + if fl + @test A * X == B + @test is_zero(A*K) + @test rank(A) + ncols(K) == ncols(A) + end + end + + A = matrix(Z17, 2, 2, [1, 2, 2, 5]) + B = matrix(Z17, 2, 1, [1, 2]) + fl, X = can_solve_with_solution(A, B, side = :right) + @test fl + @test A * X == B + @test can_solve(A, B, side = :right) + + A = matrix(Z17, 2, 2, [1, 2, 2, 4]) + B = matrix(Z17, 2, 1, [1, 2]) + fl, X = can_solve_with_solution(A, B, side = :right) + @test fl + @test A * X == B + @test can_solve(A, B, side = :right) + + A = matrix(Z17, 2, 2, [1, 2, 2, 4]) + B = matrix(Z17, 2, 1, [1, 3]) + fl, X = can_solve_with_solution(A, B, side = :right) + @test !fl + @test !can_solve(A, B, side = :right) + + A = zero_matrix(Z17, 2, 3) + B = identity_matrix(Z17, 3) + @test_throws ErrorException can_solve_with_solution(A, B, side = :right) + + A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 5])) + B = transpose(matrix(Z17, 2, 1, [1, 2])) + fl, X = can_solve_with_solution(A, B) + @test fl + @test X * A == B + @test can_solve(A, B) + + A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 4])) + B = transpose(matrix(Z17, 2, 1, [1, 2])) + fl, X = can_solve_with_solution(A, B) + @test fl + @test X * A == B + @test can_solve(A, B) + + A = transpose(matrix(Z17, 2, 2, [1, 2, 2, 4])) + B = transpose(matrix(Z17, 2, 1, [1, 3])) + fl, X = can_solve_with_solution(A, B) + @test !fl + @test !can_solve(A, B) + + A = transpose(zero_matrix(Z17, 2, 3)) + B = transpose(identity_matrix(Z17, 3)) + @test_throws ErrorException can_solve_with_solution(A, B) + + @test_throws ArgumentError can_solve_with_solution(A, B, side = :garbage) + @test_throws ArgumentError can_solve(A, B, side = :garbage) end @testset "zzModMatrix.lu" begin