From 12717eb9bfc467b0a361b93e78dface48c31366e Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 7 Feb 2024 17:30:19 +0100 Subject: [PATCH] Don't call `nullspace` for `RingElem` and add a deepcopy --- src/Solve.jl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Solve.jl b/src/Solve.jl index 6004e82b1d..bab3230dbe 100644 --- a/src/Solve.jl +++ b/src/Solve.jl @@ -294,7 +294,7 @@ is, $KA$ is the zero matrix. If a context object `C` is supplied, then the above applies for `A = matrix(C)`. """ -function kernel(A::MatElem; side::Symbol = :right) +function kernel(A::MatElem{<:FieldElement}; side::Symbol = :right) check_option(side, [:right, :left], "side") if side === :left @@ -310,6 +310,21 @@ function kernel(A::MatElem; side::Symbol = :right) return K end +function kernel(A::MatElem{<:RingElement}; side::Symbol = :right) + check_option(side, [:right, :left], "side") + + R, U = hnf_with_transform(lazy_transpose(A)) + if side === :right + R, U = hnf_with_transform(lazy_transpose(A)) + return _kernel_of_hnf(A, R, U)[2] + else + R, U = hnf_with_transform(A) + _, X = _kernel_of_hnf(lazy_transpose(A), R, U) + # X is of type LazyTransposeMatElem + return data(X) + end +end + function kernel(C::SolveCtx{<:FieldElement}; side::Symbol = :right) check_option(side, [:right, :left], "side") @@ -432,7 +447,7 @@ function _can_solve_internal_no_check(A::MatElem{T}, b::MatElem{T}, task::Symbol return fl, data(sol), data(K) end - mu = hcat(A, b) + mu = hcat(deepcopy(A), deepcopy(b)) rk = rref!(mu) p = pivot_and_non_pivot_cols(mu, rk) @@ -621,7 +636,7 @@ end # Copied from Hecke, to be replaced with echelon_form_with_transformation eventually function _rref_with_transformation(M::MatElem{T}) where T <: FieldElement - n = hcat(M, identity_matrix(base_ring(M), nrows(M))) + n = hcat(deepcopy(M), identity_matrix(base_ring(M), nrows(M))) rref!(n) s = nrows(n) while s > 0 && iszero(sub(n, s:s, 1:ncols(M)))