From 238c3c8a4ae6777583aadd0bc6c818c609684462 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Thu, 8 Feb 2024 13:37:55 +0100 Subject: [PATCH] Rearrange `kernel` a bit Now `kernel(zero_matrix(ZZ, 2, 2))` gives ``` [1 0] [0 1] ``` which certainly looks nicer than ``` [0 1] [1 0] ``` --- src/Solve.jl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Solve.jl b/src/Solve.jl index 18bbf4eec6..87016fb56e 100644 --- a/src/Solve.jl +++ b/src/Solve.jl @@ -617,17 +617,15 @@ end # and H = U*transpose(A) is in HNF. # The matrix A is only needed to get the return type right (MatElem vs LazyTransposeMatElem) function _kernel_of_hnf(A::MatElem{T}, H::MatElem{T}, U::MatElem{T}) where T <: RingElement - nullity = nrows(H) - for i = nrows(H):-1:1 - if !is_zero_row(H, i) - nullity = nrows(H) - i - break - end + r = nrows(H) + while r > 0 && is_zero_row(H, r) + r -= 1 end + nullity = nrows(H) - r N = zero(A, nrows(H), nullity) for i = 1:nrows(N) for j = 1:ncols(N) - N[i, j] = U[nrows(U) - j + 1, i] + N[i, j] = U[r + j, i] end end return nullity, N