Skip to content

Commit

Permalink
Add tr shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Sep 6, 2024
1 parent 28f6068 commit 553bb9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/Matrix-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 553bb9b

Please sign in to comment.