Skip to content

Commit 50056d3

Browse files
committed
add Lambert's Omega constant
1 parent b1a500e commit 50056d3

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/IrrationalConstants.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export
2727
logπ, # log(π)
2828
log2π, # log(2π)
2929
log4π, # log(4π)
30-
invℯ # 1 / ℯ
30+
invℯ, # 1 / ℯ
31+
32+
LambertW_Ω # Ω exp(Ω) = 1
3133

3234
include("stats.jl")
35+
include("lambertw_omega.jl")
3336

3437
end # module

src/lambertw_omega.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# lazy-initialized LambertW Omega at 256-bit precision
2+
const LambertW_Omega_BigFloat256 = Ref{BigFloat}()
3+
4+
# compute BigFloat Omega constant at arbitrary precision
5+
function compute_LambertW_Omega()
6+
# initialize Omega_BigFloat256
7+
isassigned(LambertW_Omega_BigFloat256) ||
8+
(LambertW_Omega_BigFloat256[] = BigFloat("0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194"))
9+
o = LambertW_Omega_BigFloat256[] # initial value
10+
precision(BigFloat) <= 256 && return o
11+
# iteratively improve the precision of the constant
12+
myeps = eps(BigFloat)
13+
for _ in 1:100
14+
o_ = (1 + o) / (1 + exp(o))
15+
abs(o - o_) <= myeps && break
16+
o = o_
17+
end
18+
return o
19+
end
20+
21+
@irrational LambertW_Ω 0.567143290409783872999968662210355 compute_LambertW_Omega()
22+
23+
"""
24+
Lambert's Omega (Ω) constant, such that Ω exp(Ω) = 1.
25+
26+
*W(Ω) = 1*, where *W(t) = t exp(t)* is the *Lambert's W function*.
27+
28+
# See
29+
https://en.wikipedia.org/wiki/Omega_constant
30+
"""
31+
LambertW_Ω
32+

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ end
4343
@testset "1/e" begin
4444
@test isapprox(invℯ, exp(-1))
4545
end
46+
47+
@testset "LambertW_Omega" begin
48+
@test isapprox(LambertW_Ω * exp(LambertW_Ω), 1)
49+
setprecision(BigFloat, 2048) do
50+
o = big(LambertW_Ω)
51+
@test isapprox(o * exp(o), 1, atol=eps(BigFloat))
52+
end
53+
end

0 commit comments

Comments
 (0)