diff --git a/src/Rings/AbelianClosure.jl b/src/Rings/AbelianClosure.jl index 2d731873c69c..be7fb5bf18d4 100644 --- a/src/Rings/AbelianClosure.jl +++ b/src/Rings/AbelianClosure.jl @@ -846,6 +846,25 @@ function Oscar.order(a::QQAbElem) return o end +# Convenient sqrt and cbrt functions as simple wrappers around the roots function, +# which is already implemented for QQAbElem directly + +function Oscar.sqrt(a::QQAbElem) + sqrt = Oscar.roots(a, 2) + if is_empty(sqrt) + error("Element $a does not have a square root") + end + return sqrt[1] +end + +function Oscar.cbrt(a::QQAbElem) + cbrt = Oscar.roots(a,3) + if is_empty(cbrt) + error("Element $a does not have a cube root") + end + return cbrt[1] +end + ############################################################################### # diff --git a/test/Rings/AbelianClosure.jl b/test/Rings/AbelianClosure.jl index d40d5ec3a562..3b2b9225ee5b 100644 --- a/test/Rings/AbelianClosure.jl +++ b/test/Rings/AbelianClosure.jl @@ -264,6 +264,10 @@ end @test length(roots(x^15-2^15)) == 15 @test order(z(5)) == 5 + + @test cbrt(K(8))^3 == K(8) + @test_throws ErrorException("Element 4 does not have a cube root") cbrt(K(4)) + end @testset "Automorphism" begin @@ -292,6 +296,9 @@ end @test ((a - x)//y)^2 == n end + @test sqrt(K(2))^2 == K(2) + @test_throws ErrorException("Element zeta(4) + 1 does not have a square root") sqrt(z(4)+1) + @test Oscar.AbelianClosure.quadratic_irrationality_info(z(5)) === nothing @testset for d in -50:50