From 553bb9bbaf8cb11afbcc3f8b3751c078f110e747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 6 Sep 2024 17:00:34 +0200 Subject: [PATCH] Add tr shortcut --- src/Matrix.jl | 3 ++- test/Matrix-test.jl | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Matrix.jl b/src/Matrix.jl index b52390798..08f4eb49e 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -3700,8 +3700,9 @@ such that $A^k = 0$. If `A` is not square an exception is raised. """ function is_nilpotent(A::MatrixElem{T}) where {T <: RingElement} !is_square(A) && error("Dimensions don't match in is_nilpotent") - A = deepcopy(A) + is_zero(tr(A)) || return false n = nrows(A) + A = deepcopy(A) i = 1 is_zero(A) && return true while i < n diff --git a/test/Matrix-test.jl b/test/Matrix-test.jl index 5f5776699..dd206c611 100644 --- a/test/Matrix-test.jl +++ b/test/Matrix-test.jl @@ -66,8 +66,9 @@ end @testset "Matrix.is_nilpotent" begin @test is_nilpotent(zero_matrix(QQ, 3, 3)) - @test !is_nilpotent(identity_matrix(QQ, 3)) @test is_nilpotent(upper_triangular_matrix(QQ.([0,1,1,0,1,0]))) + @test !is_nilpotent(identity_matrix(QQ, 3)) + @test !is_nilpotent(diagonal_matrix(QQ, [1,-1,0])) end @testset "Matrix.concat" begin