Skip to content

Commit

Permalink
Add sqrt and cbrt functions for QQAbElem (#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 authored Dec 15, 2023
1 parent f7cfd66 commit 4bbbef4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


###############################################################################
#
Expand Down
7 changes: 7 additions & 0 deletions test/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bbbef4

Please sign in to comment.