diff --git a/docs/src/matrix.md b/docs/src/matrix.md index 643d8b7d50..5abfc9af5f 100644 --- a/docs/src/matrix.md +++ b/docs/src/matrix.md @@ -739,11 +739,11 @@ Rationals ### Symmetry testing ```@docs -is_symmetric(a::MatrixElem{T}) where T <: RingElement +is_symmetric(::MatrixElem) ``` ```@docs -is_skew_symmetric(::MatElem) +is_skew_symmetric(::MatrixElem) ``` ### Powering diff --git a/src/Matrix.jl b/src/Matrix.jl index 7541cafb58..36b3608f99 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -1272,10 +1272,10 @@ end ############################################################################### """ - is_symmetric(a::MatrixElem{T}) where T <: RingElement + is_symmetric(M::MatrixElem) Return `true` if the given matrix is symmetric with respect to its main -diagonal, i.e., `tr(M) == M`, otherwise return `false`. +diagonal, i.e., `transpose(M) == M`, otherwise return `false`. Alias for `LinearAlgebra.issymmetric`. @@ -1299,18 +1299,13 @@ julia> is_symmetric(N) false ``` """ -function is_symmetric(a::MatrixElem{T}) where T <: NCRingElement - if !is_square(a) - return false - end - for row in 2:nrows(a) - for col in 1:(row - 1) - if a[row, col] != a[col, row] - return false - end - end - end - return true +function is_symmetric(M::MatrixElem) + n = nrows(M) + n == ncols(M) || return false + for i in 2:n, j in 1:i-1 + M[i, j] == M[j, i] || return false + end + return true end @@ -2406,10 +2401,10 @@ end ############################################################################### """ - is_skew_symmetric(M::MatElem) + is_skew_symmetric(M::MatrixElem) Return `true` if the given matrix is skew symmetric with respect to its main -diagonal, i.e., `tr(M) == -M`, otherwise return `false`. +diagonal, i.e., `transpose(M) == -M`, otherwise return `false`. # Examples ```jldoctest; setup = :(using AbstractAlgebra) @@ -2423,7 +2418,7 @@ true ``` """ -function is_skew_symmetric(M::MatElem) +function is_skew_symmetric(M::MatrixElem) n = nrows(M) n == ncols(M) || return false for i in 1:n, j in 1:i diff --git a/src/NemoStuff.jl b/src/NemoStuff.jl index 4bae890de4..82855637f0 100644 --- a/src/NemoStuff.jl +++ b/src/NemoStuff.jl @@ -136,17 +136,6 @@ end base_ring(::Vector{Int}) = Int -function is_symmetric(M::MatElem) - for i in 1:nrows(M) - for j in i:ncols(M) - if M[i, j] != M[j, i] - return false - end - end - end - return true -end - nrows(A::Matrix{T}) where {T} = size(A)[1] ncols(A::Matrix{T}) where {T} = size(A)[2]