Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ y = (sqrt(AlgebraicNumber(5))-1)/4
assert(x == y)
```

The inverse of these functions also exist. `log_alg(x)` returns log(x)/iπ, which, assuming x is a root of unity, is rational. If x is not a root of unity, this function returns `Nothing`.
The inverse of these functions also exist. `log_alg(x)` returns log(x)/iπ, which, assuming x is a root of unity, is rational. If x is not a root of unity, this function returns `nothing`.

```julia
x = exp_alg(3//7)
y = log_alg(x)
assert(y == 3//7)
```

There are also inverse trigonometric functions `acos_alg` and `asin_alg`. If the input is a trigonometric number, the output will be a rational fraction of π, otherwise the return value will be `Nothing`. These functions are useful when doing various geometric computations.
There are also inverse trigonometric functions `acos_alg` and `asin_alg`. If the input is a trigonometric number, the output will be a rational fraction of π, otherwise the return value will be `nothing`. These functions are useful when doing various geometric computations.

```julia
x = sqrt(AlgebraicNumber(3))/2
Expand All @@ -119,4 +119,4 @@ assert(acos_alg(x) == 1//10)
assert(asin_alg(x) == 4//10)
```

Internally, these functions work by calling `log_alg`. `log_alg` then checks if the polynomial coefficients for the algebraic number are cyclotomic. If this polynomial is the nth cyclotomic polynomial, then the denominator of the result is simply n. The numerator can be calculated by taking the approximate floating-point log of the number and then multiplying by the denominator and rounding to the nearest integer.
Internally, these functions work by calling `log_alg`. `log_alg` then checks if the polynomial coefficients for the algebraic number are cyclotomic. If this polynomial is the nth cyclotomic polynomial, then the denominator of the result is simply n. The numerator can be calculated by taking the approximate floating-point log of the number and then multiplying by the denominator and rounding to the nearest integer.
4 changes: 2 additions & 2 deletions src/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

# compute log(a)/(pi*i),
# which is rational if a is a root of unity.
# If a is not a root of unity, returns Nothing
# If a is not a root of unity, returns nothing
function log_alg(a::AlgebraicNumber)
s, x = polynomial_ring(Nemo.ZZ, "x")

Expand All @@ -45,7 +45,7 @@ function log_alg(a::AlgebraicNumber)
num = round(Int, denom*imag(log(a.apprx)/pi))
return num//denom
else
return Nothing
return nothing
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ end
function test_log_alg()
@test log_alg(exp_alg(1//9)) == 1//9

@test log_alg(AlgebraicNumber(2)) == Nothing
@test isnothing(log_alg(AlgebraicNumber(2)))
end

function test_trig_alg()
Expand All @@ -122,8 +122,8 @@ function test_trig_alg()
@test acos_alg(AlgebraicNumber(1)) == 0//1
@test asin_alg(AlgebraicNumber(1)) == 1//2

@test asin_alg(AlgebraicNumber(3//2)) == Nothing
@test acos_alg(AlgebraicNumber(3//2)) == Nothing
@test isnothing(asin_alg(AlgebraicNumber(3//2)))
@test isnothing(acos_alg(AlgebraicNumber(3//2)))
end

function totient(x::T) where T <: Integer
Expand Down