From 3a613836e74ecf970fccd1ed74d1e6634bf2b893 Mon Sep 17 00:00:00 2001 From: varuntrehan7 Date: Mon, 1 Dec 2025 08:37:16 +0530 Subject: [PATCH 1/4] Clean up sqrt docs in manual --- docs/src/fraction.md | 4 +--- docs/src/function_field.md | 4 +--- docs/src/polynomial.md | 4 +--- docs/src/puiseux.md | 6 +----- docs/src/residue.md | 4 +--- docs/src/series.md | 5 +---- 6 files changed, 6 insertions(+), 21 deletions(-) diff --git a/docs/src/fraction.md b/docs/src/fraction.md index 67a08d15bd..ffce261580 100644 --- a/docs/src/fraction.md +++ b/docs/src/fraction.md @@ -301,9 +301,7 @@ julia> h = gcd(f, g) ### Square root -```@docs -Base.sqrt(::FracElem{T}) where {T <: RingElem} -``` +Methods for `is_square` and `sqrt` are provided for inputs of type `FracElem`. **Examples** diff --git a/docs/src/function_field.md b/docs/src/function_field.md index 9d4a015a2e..0d1c100687 100644 --- a/docs/src/function_field.md +++ b/docs/src/function_field.md @@ -162,9 +162,7 @@ julia> h = gcd(f, g) ### Square root -```@docs -Base.sqrt(::Generic.RationalFunctionFieldElem{T, U}) where {T <: FieldElem, U <: Union{PolyRingElem, MPolyRingElem}} -``` +Methods for `is_square` and `sqrt` are provided for inputs of type `RationalFunctionFieldElem`. **Examples** diff --git a/docs/src/polynomial.md b/docs/src/polynomial.md index 5609d909ee..a49922fb75 100644 --- a/docs/src/polynomial.md +++ b/docs/src/polynomial.md @@ -674,9 +674,7 @@ deflate(::PolyRingElem) ### Square root -```@docs -Base.sqrt(::PolyRingElem{T}; check::Bool) where T <: RingElement -``` +Methods for `is_square` and `sqrt` are provided for inputs of type `PolyRingElem`. **Examples** diff --git a/docs/src/puiseux.md b/docs/src/puiseux.md index 75b2c529de..7676d81401 100644 --- a/docs/src/puiseux.md +++ b/docs/src/puiseux.md @@ -328,11 +328,7 @@ true Base.log(a::Generic.PuiseuxSeriesElem) Base.exp(a::Generic.PuiseuxSeriesElem) ``` - -```@docs -Base.sqrt(a::Generic.PuiseuxSeriesElem) -``` - +Methods for `is_square` and `sqrt` are provided for inputs of type `PuiseuxSeriesElem`. **Examples** diff --git a/docs/src/residue.md b/docs/src/residue.md index 842faefd64..849d578835 100644 --- a/docs/src/residue.md +++ b/docs/src/residue.md @@ -264,9 +264,7 @@ julia> h = gcd(f, g) ### Square Root -```@docs -Base.sqrt{T <: Integer}(::ResFieldElem{T}) -``` +Methods for `is_square` and `sqrt` are provided for inputs of type `ResFieldElem`. **Examples** diff --git a/docs/src/series.md b/docs/src/series.md index 2d051bb760..f368d08693 100644 --- a/docs/src/series.md +++ b/docs/src/series.md @@ -686,10 +686,7 @@ Base.log(a::SeriesElem{T}) where T <: FieldElem ```@docs Base.exp(a::RelPowerSeriesRingElem) ``` - -```@docs -Base.sqrt(a::RelPowerSeriesRingElem) -``` +Methods for `is_square` and `sqrt` are provided for inputs of type `RelPowerSeriesRingElem`. **Examples** From 1466006083eb8db629928ecfe21f1e559f7e83bf Mon Sep 17 00:00:00 2001 From: varuntrehan7 Date: Mon, 1 Dec 2025 21:05:32 +0530 Subject: [PATCH 2/4] Remove sqrt docs; add generic sqrt interface docstring --- src/AbsSeries.jl | 7 ------- src/Fraction.jl | 6 ------ src/NCRings.jl | 11 +++++++++++ src/Poly.jl | 6 ------ src/RelSeries.jl | 7 ------- src/ResidueField.jl | 6 ------ src/Rings.jl | 7 ------- src/generic/LaurentSeries.jl | 7 ------- src/generic/PuiseuxSeries.jl | 7 ------- src/generic/RationalFunctionField.jl | 6 ------ temp/Project.toml | 3 +++ 11 files changed, 14 insertions(+), 59 deletions(-) create mode 100644 temp/Project.toml diff --git a/src/AbsSeries.jl b/src/AbsSeries.jl index d875c5e409..791c463c36 100644 --- a/src/AbsSeries.jl +++ b/src/AbsSeries.jl @@ -905,13 +905,6 @@ function sqrt_classical(a::AbsPowerSeriesRingElem; check::Bool=true) return true, asqrt end -@doc raw""" - sqrt(a::AbsPowerSeriesRingElem; check::Bool=true) - -Return the square root of the power series $a$. By default the function will -throw an exception if the input is not square. If `check=false` this test is -omitted. -""" function Base.sqrt(a::AbsPowerSeriesRingElem; check::Bool=true) flag, q = sqrt_classical(a; check=check) if check && !flag diff --git a/src/Fraction.jl b/src/Fraction.jl index 85cc369424..6c70158a94 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -697,12 +697,6 @@ function is_square(a::FracElem{T}) where T <: RingElem return is_square(numerator(a)) && is_square(denominator(a)) end -@doc raw""" - Base.sqrt(a::FracElem{T}; check::Bool=true) where T <: RingElem - -Return the square root of $a$. By default the function will throw an -exception if the input is not square. If `check=false` this test is omitted. -""" function Base.sqrt(a::FracElem{T}; check::Bool=true) where T <: RingElem return parent(a)(sqrt(numerator(a); check=check), sqrt(denominator(a); check=check)) end diff --git a/src/NCRings.jl b/src/NCRings.jl index f9feafac7b..a2a65140b0 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -184,6 +184,17 @@ See also `is_square(M::MatElem)` which tests whether a matrix has square shape. """ function is_square end +@doc raw""" + sqrt(a::T; check::Bool=true) where {T <: NCRingElement} + +Return a square root of `a`, if it exists. By default (`check=true`), +implementations should raise an exception if `a` is not a square in its ring. +If `check=false`, implementations may skip this verification. + +See also `is_square` and `is_square_with_sqrt`. +""" +sqrt + ############################################################################### # # Characteristic diff --git a/src/Poly.jl b/src/Poly.jl index ad1ae5115d..76630c99ad 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -1825,12 +1825,6 @@ function sqrt_classical(f::PolyRingElem{T}; check::Bool=true) where T <: RingEle return true, q end -@doc raw""" - Base.sqrt(f::PolyRingElem{T}; check::Bool=true) where T <: RingElement - -Return the square root of $f$. By default the function checks the input is -square and raises an exception if not. If `check=false` this check is omitted. -""" function Base.sqrt(f::PolyRingElem{T}; check::Bool=true) where T <: RingElement flag, q = sqrt_classical(f; check=check) check && !flag && error("Not a square in sqrt") diff --git a/src/RelSeries.jl b/src/RelSeries.jl index fd9370a060..9b3119242a 100644 --- a/src/RelSeries.jl +++ b/src/RelSeries.jl @@ -1172,13 +1172,6 @@ function sqrt_classical(a::RelPowerSeriesRingElem; check::Bool=true) return true, asqrt end -@doc raw""" - sqrt(a::RelPowerSeriesRingElem) - -Return the square root of the power series $a$. By default the function raises -an exception if the input is not a square. If `check=false` this check is -omitted. -""" function Base.sqrt(a::RelPowerSeriesRingElem; check::Bool=true) flag, q = sqrt_classical(a; check=check) if check && !flag diff --git a/src/ResidueField.jl b/src/ResidueField.jl index a454024b42..76ab69176a 100644 --- a/src/ResidueField.jl +++ b/src/ResidueField.jl @@ -349,12 +349,6 @@ function is_square(a::ResFieldElem{T}) where T <: Integer return isone(a^pm1div2) end -@doc raw""" - sqrt(a::ResFieldElem{T}; check::Bool=true) where T <: Integer - -Return the square root of $a$. By default the function will throw an exception -if the input is not square. If `check=false` this test is omitted. -""" function Base.sqrt(a::ResFieldElem{T}; check::Bool=true) where T <: Integer U = parent(a) p = modulus(a) diff --git a/src/Rings.jl b/src/Rings.jl index b6b2041243..c8594a5fa3 100644 --- a/src/Rings.jl +++ b/src/Rings.jl @@ -160,13 +160,6 @@ end # ################################################################################ -@doc raw""" - sqrt(a::FieldElem) - -Return the square root of the element `a`. By default the function will -throw an exception if the input is not square. If `check=false` this test is -omitted. -""" function Base.sqrt(a::FieldElem; check::Bool=true) R = parent(a) R, t = polynomial_ring(R, :t; cached = false) diff --git a/src/generic/LaurentSeries.jl b/src/generic/LaurentSeries.jl index ff51d6031e..a06dcd0d85 100644 --- a/src/generic/LaurentSeries.jl +++ b/src/generic/LaurentSeries.jl @@ -1395,13 +1395,6 @@ function sqrt_classical(a::LaurentSeriesElem; check::Bool=true) return true, asqrt end -@doc raw""" - sqrt(a::Generic.LaurentSeriesElem; check::Bool=true) - -Return the square root of the power series $a$. By default the function will -throw an exception if the input is not square. If `check=false` this test is -omitted. -""" function Base.sqrt(a::LaurentSeriesElem; check::Bool=true) flag, s = sqrt_classical(a, check=check) check && !flag && error("Not a square in sqrt") diff --git a/src/generic/PuiseuxSeries.jl b/src/generic/PuiseuxSeries.jl index 6e71d2fe78..5bc6e0ec73 100644 --- a/src/generic/PuiseuxSeries.jl +++ b/src/generic/PuiseuxSeries.jl @@ -613,13 +613,6 @@ function sqrt_classical(a::PuiseuxSeriesElem{T}; check::Bool=true) where T <: Ri return true, S(s, sscale) end -@doc raw""" - sqrt(a::Generic.PuiseuxSeriesElem{T}; check::Bool=true) where T <: RingElement - -Return the square root of the given Puiseux series $a$. By default the function -will throw an exception if the input is not square. If `check=false` this test -is omitted. -""" function Base.sqrt(a::PuiseuxSeriesElem{T}; check::Bool=true) where T <: RingElement flag, s = sqrt_classical(a; check=check) check && !flag && error("Not a square in sqrt") diff --git a/src/generic/RationalFunctionField.jl b/src/generic/RationalFunctionField.jl index 49d9b8b104..41defbe5df 100644 --- a/src/generic/RationalFunctionField.jl +++ b/src/generic/RationalFunctionField.jl @@ -455,12 +455,6 @@ function is_square(a::RationalFunctionFieldElem) return is_square(data(a)) end -@doc raw""" - Base.sqrt(a::RationalFunctionFieldElem; check::Bool=true) - -Return the square root of $a$. By default the function will throw an exception -if the input is not square. If `check=false` this test is omitted. -""" function Base.sqrt(a::RationalFunctionFieldElem; check::Bool=true) R = parent(a) return R(sqrt(data(a); check=check)) diff --git a/temp/Project.toml b/temp/Project.toml new file mode 100644 index 0000000000..bef9dc5df0 --- /dev/null +++ b/temp/Project.toml @@ -0,0 +1,3 @@ +[deps] +Hecke = "3e1990a7-5d81-5526-99ce-9ba3ff248f21" +Oscar = "f1435218-dba5-11e9-1e4d-f1a5fab5fc13" From d4eecc6c8cc7b98dac603dc595bb24a9859f5736 Mon Sep 17 00:00:00 2001 From: varuntrehan7 Date: Mon, 1 Dec 2025 22:05:30 +0530 Subject: [PATCH 3/4] Cleanup sqrt docs and add unified documentation. --- docs/src/ring.md | 18 ++++++++++++++++++ src/NCRings.jl | 4 ++-- temp/Project.toml | 3 --- 3 files changed, 20 insertions(+), 5 deletions(-) delete mode 100644 temp/Project.toml diff --git a/docs/src/ring.md b/docs/src/ring.md index dfcd078a50..fbc904fa9d 100644 --- a/docs/src/ring.md +++ b/docs/src/ring.md @@ -252,6 +252,24 @@ evaluate(a::Fac) getindex(a::Fac, b) setindex!(a::Fac{Int}, c::Int, b::Int) ``` +## Square root + +Many rings in AbstractAlgebra provide functionality for detecting and computing +square roots. Two functions form the basic interface: + +- `is_square(a)` – return `true` if the element `a` is a square in its ring. +- `sqrt(a; check=true)` – return a square root of `a`, when available. + +The exact behaviour depends on the ring. Some rings provide both operations, +while others only implement `is_square`. If `check=false`, the square root +check may be omitted. + +The following entries link to the generic interface documentation: + +```@docs +is_square +sqrt(::NCRingElem) +``` ## Miscellaneous diff --git a/src/NCRings.jl b/src/NCRings.jl index a2a65140b0..866cac5f03 100644 --- a/src/NCRings.jl +++ b/src/NCRings.jl @@ -185,7 +185,7 @@ See also `is_square(M::MatElem)` which tests whether a matrix has square shape. function is_square end @doc raw""" - sqrt(a::T; check::Bool=true) where {T <: NCRingElement} + sqrt(a::NCRingElem; check::Bool=true) Return a square root of `a`, if it exists. By default (`check=true`), implementations should raise an exception if `a` is not a square in its ring. @@ -193,7 +193,7 @@ If `check=false`, implementations may skip this verification. See also `is_square` and `is_square_with_sqrt`. """ -sqrt +sqrt(::NCRingElem) ############################################################################### # diff --git a/temp/Project.toml b/temp/Project.toml deleted file mode 100644 index bef9dc5df0..0000000000 --- a/temp/Project.toml +++ /dev/null @@ -1,3 +0,0 @@ -[deps] -Hecke = "3e1990a7-5d81-5526-99ce-9ba3ff248f21" -Oscar = "f1435218-dba5-11e9-1e4d-f1a5fab5fc13" From 314d84246f1ebbd65534c8e2a1a7f2bdc9fd7259 Mon Sep 17 00:00:00 2001 From: varuntrehan7 Date: Wed, 3 Dec 2025 17:46:19 +0530 Subject: [PATCH 4/4] fix the manual for is_square and sqrt --- docs/src/ring.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/docs/src/ring.md b/docs/src/ring.md index fbc904fa9d..52d82c2884 100644 --- a/docs/src/ring.md +++ b/docs/src/ring.md @@ -254,17 +254,10 @@ setindex!(a::Fac{Int}, c::Int, b::Int) ``` ## Square root -Many rings in AbstractAlgebra provide functionality for detecting and computing -square roots. Two functions form the basic interface: - -- `is_square(a)` – return `true` if the element `a` is a square in its ring. -- `sqrt(a; check=true)` – return a square root of `a`, when available. +Rings may implement functionality for detecting and computing square roots. The exact behaviour depends on the ring. Some rings provide both operations, -while others only implement `is_square`. If `check=false`, the square root -check may be omitted. - -The following entries link to the generic interface documentation: +while others only implement `is_square`. ```@docs is_square