Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/AbsSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ function Base.sqrt(a::AbsPowerSeriesRingElem; check::Bool=true)
return q
end

# See generic documentation in NCRings.jl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand the intention, I note that we do not have such comments in front of the many other methods that implement ring interfaces, so it seems odd to have the comment added to just is_square. I'd rather not add this everywhere at all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - removed. Will push shortly.

function is_square(a::AbsPowerSeriesRingElem)
flag, q = sqrt_classical(a; check=true)
return flag
Expand Down
6 changes: 1 addition & 5 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,7 @@ end
#
###############################################################################

@doc raw"""
is_square(a::FracElem{T}) where T <: RingElem

Return `true` if $a$ is a square.
"""
# See generic documentation in NCRings.jl
function is_square(a::FracElem{T}) where T <: RingElem
return is_square(numerator(a)) && is_square(denominator(a))
end
Expand Down
1 change: 1 addition & 0 deletions src/MatRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ end
#
################################################################################

# See generic documentation in NCRings.jl
is_square(a::MatRingElem) = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but this is wrong now: according to what we discussed, MatRingElem are always square matrices "on the inside", but since they are NCRingElem, the meaning of is_square here now should be "is there some b such that b^2 == a ?", and that won't always be true.

So this needs to be removed, including the block comment mentioning is_square above it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing. Your suggestion is that for matrices (not of type MatRingElem) the function is_square checks the shape of the matrix. But if the matrix happens to be of type MatRingElem then is_square should behave differently? Well, of course, if one knows that the matrix is of type MatRingElem then there's no point in checking whether it is square...
So should is_square applied to a MatRingElem produce a not implemented error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A MatRingElem is not a matrix, i.e., not a MatElem (similar for MatrixGroupElem). Rather it is a NCRingElem. That was a major point in this discussion and explicitly discussed during the relevant triage discussion.

But "luckily" we have no general algorithm for computing square roots of matrices (I think) so by simply not implementing this method for MatRingElem all is well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function definition commented out and pushed. If the tests pass, I can delete the function definition.


###############################################################################
Expand Down
11 changes: 11 additions & 0 deletions src/NCRings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ function is_nilpotent(a::T) where {T <: NCRingElement}
end


@doc raw"""
is_square(a::T) where {T <: NCRingElement}
is_square(M::MatElem)
is_square(M::MatRingElem)

There are two distinct situations:
(1) if the argument is matrix then check whether the matrix **shape** is square
(2) if the argument is not a matrix then check whether the **value** is a square (in the same ring)
"""
function is_square end
Comment on lines 179 to 185
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this really should be two docstrings:

  • one for is_square(a::NCRingElement)
  • one for is_square(M::MatElem)

Both then can be included in different parts of the manual (one in the ring interface section, one in matrix interface section).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently already done. I'll un-draft-ify the PR.


###############################################################################
#
# Characteristic
Expand Down
6 changes: 1 addition & 5 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1837,11 +1837,7 @@ function Base.sqrt(f::PolyRingElem{T}; check::Bool=true) where T <: RingElement
return q
end

@doc raw"""
is_square(f::PolyRingElem{T}) where T <: RingElement

Return `true` if $f$ is a perfect square.
"""
# See generic documentation in NCRings.jl
function is_square(f::PolyRingElem{T}) where T <: RingElement
flag, q = sqrt_classical(f)
return flag
Expand Down
1 change: 1 addition & 0 deletions src/RelSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ function Base.sqrt(a::RelPowerSeriesRingElem; check::Bool=true)
return q
end

# See generic documentation in NCRings.jl
function is_square(a::RelPowerSeriesRingElem)
flag, q = sqrt_classical(a; check=true)
return flag
Expand Down
6 changes: 1 addition & 5 deletions src/ResidueField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ end
#
###############################################################################

@doc raw"""
is_square(a::ResFieldElem{T}) where T <: Integer

Return `true` if $a$ is a square.
"""
# See generic documentation in NCRings.jl
function is_square(a::ResFieldElem{T}) where T <: Integer
if iszero(a)
return true
Expand Down
1 change: 1 addition & 0 deletions src/generic/LaurentSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ function Base.sqrt(a::LaurentSeriesElem; check::Bool=true)
return s
end

# See generic documentation in NCRings.jl
function is_square(a::LaurentSeriesElem)
flag, q = sqrt_classical(a; check=true)
return flag
Expand Down
1 change: 1 addition & 0 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,7 @@ function Base.sqrt(a::MPoly{T}; check::Bool=true) where {T <: RingElement}
return q
end

# See generic documentation in NCRings.jl
function is_square(a::MPoly{T}) where {T <: RingElement}
flag, q = sqrt_heap(a; check=true)
return flag
Expand Down
1 change: 1 addition & 0 deletions src/generic/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ end
#
################################################################################

# See generic documentation in NCRings.jl
is_square(a::MatElem) = (nrows(a) == ncols(a))

###############################################################################
Expand Down
1 change: 1 addition & 0 deletions src/generic/PuiseuxSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ function Base.sqrt(a::PuiseuxSeriesElem{T}; check::Bool=true) where T <: RingEle
return s
end

# See generic documentation in NCRings.jl
function is_square(a::PuiseuxSeriesElem{T}) where T <: RingElement
flag, s = sqrt_classical(a; check=true)
return flag
Expand Down
6 changes: 1 addition & 5 deletions src/generic/RationalFunctionField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,7 @@ end
#
###############################################################################

@doc raw"""
is_square(a::RationalFunctionFieldElem)

Return `true` if $a$ is a square.
"""
# See generic documentation in NCRings.jl
function is_square(a::RationalFunctionFieldElem)
return is_square(data(a))
end
Expand Down
1 change: 1 addition & 0 deletions src/generic/UnivPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ function Base.sqrt(p::UnivPoly{T}; check::Bool=true) where {T}
return UnivPoly{T}(s, S)
end

# See generic documentation in NCRings.jl
function is_square(p::UnivPoly)
return is_square(data(p))
end
Expand Down
5 changes: 3 additions & 2 deletions src/julia/Float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ function Base.sqrt(a::AbstractFloat; check::Bool=true)
return Base.sqrt(a)
end

# See generic documentation in NCRings.jl
function is_square(a::AbstractFloat)
return a > 0
return a >= 0
end

function is_square_with_sqrt(a::T) where T <: AbstractFloat
if a > 0
if a >= 0
return true, Base.sqrt(a)
else
return false, zero(T)
Expand Down
1 change: 1 addition & 0 deletions src/julia/GF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ function Base.sqrt(a::GFElem{T}; check::Bool=true) where T <: Integer
return s1
end

# See generic documentation in NCRings.jl
function is_square(a::GFElem{T}) where T <: Integer
f1, s1 = sqrt_tonelli_shanks(a; check=true)
return f1
Expand Down
7 changes: 2 additions & 5 deletions src/julia/Integer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,7 @@ function is_square_with_sqrt(a::BigInt)
end
end

@doc raw"""
is_square(a::T) where T <: Integer

Return true if $a$ is a square.
"""
# See generic documentation in NCRings.jl
function is_square(a::T) where T <: Integer
if a < 0
return false
Expand All @@ -324,6 +320,7 @@ function is_square(a::T) where T <: Integer
return a == s*s
end

# See generic documentation in NCRings.jl
function is_square(a::BigInt)
if a < 0
return false
Expand Down
1 change: 1 addition & 0 deletions src/julia/Rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function sqrt(a::Rational{T}; check::Bool=true) where T <: Integer
return sqrt(numerator(a, false); check=check)//sqrt(denominator(a, false); check=check)
end

# See generic documentation in NCRings.jl
function is_square(a::Rational{T}) where T <: Integer
return is_square(numerator(a)) && is_square(denominator(a))
end
Expand Down
Loading