Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak is_symmetric and is_skew_symmetric #1427

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 12 additions & 17 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/NemoStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Loading