Skip to content

Commit

Permalink
Review: return a single root, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 committed Dec 14, 2023
1 parent 47ff3b0 commit 177ead3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Rings/AbelianClosure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,19 @@ end
# which is already implemented for QQAbElem directly

function Oscar.sqrt(a::QQAbElem)
return Oscar.roots(a, 2)
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)
return Oscar.roots(a, 3)
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
@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)
@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 177ead3

Please sign in to comment.