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

Add sqrt and cbrt functions for QQAbElem #3096

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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)) == 2
aaruni96 marked this conversation as resolved.
Show resolved Hide resolved
@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)) == -z(8)^3 + z(8)
aaruni96 marked this conversation as resolved.
Show resolved Hide resolved
@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
Loading