From ef0183924ce1dc7f81bc2d649bb371b3ac493890 Mon Sep 17 00:00:00 2001 From: Thomas Zdyrski <6127807+TomJohnZ@users.noreply.github.com> Date: Fri, 19 Dec 2025 14:16:18 -0500 Subject: [PATCH] Replace `Nothing` return value with `nothing` Return the singleton instance `nothing` instead of the type `Nothing` from the inverse trigonometric functions. This allows using the `isnothing` check. --- README.md | 6 +++--- src/trig.jl | 4 ++-- test/runtests.jl | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 918cb4b..dd4eef5 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ 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) @@ -106,7 +106,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 @@ -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. \ No newline at end of file +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. diff --git a/src/trig.jl b/src/trig.jl index 5b19e6a..147f934 100644 --- a/src/trig.jl +++ b/src/trig.jl @@ -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") @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index d06da26..1a73689 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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() @@ -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