Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cfdcd27

Browse files
authoredSep 11, 2024··
Add is_nilpotent(::MatrixElem) (Nemocas#1783)
1 parent 025eabc commit cfdcd27

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed
 

‎Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AbstractAlgebra"
22
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
3-
version = "0.42.4"
3+
version = "0.42.5"
44

55
[deps]
66
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

‎docs/src/matrix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,12 @@ det{T <: RingElem}(::MatElem{T})
916916
rank{T <: RingElem}(::MatElem{T})
917917
```
918918

919+
### Nilpotency
920+
921+
```@docs
922+
is_nilpotent(::MatrixElem{T}) where {T <: RingElement}
923+
```
924+
919925
### Minors
920926

921927
```@docs

‎src/Matrix.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,34 @@ function nullspace(M::MatElem{T}) where {T <: FieldElement}
36863686
return nullity, X
36873687
end
36883688

3689+
###############################################################################
3690+
#
3691+
# Nilpotency
3692+
#
3693+
###############################################################################
3694+
3695+
@doc raw"""
3696+
is_nilpotent(A::MatrixElem{T}) where {T <: RingElement}
3697+
3698+
Return if `A` is nilpotent, i.e. if there exists a natural number $k$
3699+
such that $A^k = 0$. If `A` is not square an exception is raised.
3700+
"""
3701+
function is_nilpotent(A::MatrixElem{T}) where {T <: RingElement}
3702+
is_domain_type(T) || error("Only supported over integral domains")
3703+
!is_square(A) && error("Dimensions don't match in is_nilpotent")
3704+
is_zero(tr(A)) || return false
3705+
n = nrows(A)
3706+
A = deepcopy(A)
3707+
i = 1
3708+
is_zero(A) && return true
3709+
while i < n
3710+
i *= 2
3711+
A = mul!(A, A, A)
3712+
is_zero(A) && return true
3713+
end
3714+
return false
3715+
end
3716+
36893717
###############################################################################
36903718
#
36913719
# Hessenberg form

‎src/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export is_monic
294294
export is_monomial
295295
export is_monomial_recursive
296296
export is_negative
297+
export is_nilpotent
297298
export is_odd
298299
export is_one
299300
export is_perfect

‎test/Matrix-test.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ end
6464
@test is_upper_triangular(matrix(ZZ, A))
6565
end
6666

67+
@testset "Matrix.is_nilpotent" begin
68+
@test is_nilpotent(zero_matrix(QQ, 3, 3))
69+
@test is_nilpotent(upper_triangular_matrix(QQ.([0,1,1,0,1,0])))
70+
@test !is_nilpotent(identity_matrix(QQ, 3))
71+
@test !is_nilpotent(diagonal_matrix(QQ, [1,-1,0]))
72+
end
73+
6774
@testset "Matrix.concat" begin
6875
for R in [ZZ, QQ, polynomial_ring(QQ, [:x, :y])[1]]
6976
S = matrix_space(R, 3, 3)

0 commit comments

Comments
 (0)
Please sign in to comment.