@@ -37,7 +37,7 @@ _lambertw(x::Irrational, k::Integer, maxits::Integer) = _lambertw(float(x), k, m
37
37
function _lambertw (x:: Union{Integer, Rational} , k:: Integer , maxits:: Integer )
38
38
if k == 0
39
39
x == 0 && return float (zero (x))
40
- x == 1 && return convert (typeof (float (x)), omega ) # must be a more efficient way
40
+ x == 1 && return convert (typeof (float (x)), LambertW . Omega ) # must be a more efficient way
41
41
end
42
42
return _lambertw (float (x), k, maxits)
43
43
end
@@ -141,54 +141,44 @@ function lambertw_root_finding(z::T, x0::T, maxits::Integer) where T <: Number
141
141
return x
142
142
end
143
143
144
- # ## omega constant
144
+ # ## Lambert's Omega constant
145
145
146
- const _omega_const = 0.567143290409783872999968662210355
147
-
148
- # The BigFloat `omega_const_bf_` is set via a literal in the function __init__ to prevent a segfault
149
-
150
- # compute omega constant via root finding
151
- # We could compute higher precision. This converges very quickly.
152
- function omega_const (:: Type{BigFloat} )
153
- precision (BigFloat) <= 256 && return omega_const_bf_[]
146
+ # compute BigFloat Omega constant at arbitrary precision
147
+ function compute_lambertw_Omega ()
148
+ oc = BigFloat (" 0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194" )
149
+ precision (oc) <= 256 && return oc
150
+ # iteratively improve the precision
151
+ # see https://en.wikipedia.org/wiki/Omega_constant#Computation
154
152
myeps = eps (BigFloat)
155
- oc = omega_const_bf_[]
156
- for i in 1 : 100
153
+ for _ in 1 : 1000
157
154
nextoc = (1 + oc) / (1 + exp (oc))
158
- abs (oc - nextoc) <= myeps && break
155
+ abs (oc - nextoc) <= myeps && return oc
159
156
oc = nextoc
160
157
end
158
+ @warn " Omega precision is less than current BigFloat precision ($(precision (BigFloat)) )"
161
159
return oc
162
160
end
163
161
164
- """
165
- omega
166
- ω
162
+ # "private" declaration of Omega constant
163
+ Base. @irrational lambertw_Omega 0.567143290409783872999968662210355 compute_lambertw_Omega ()
167
164
168
- The constant defined by `ω exp(ω) = 1`.
165
+ module LambertW
169
166
170
- # Example
171
- ```jldoctest
172
- julia> ω
173
- ω = 0.5671432904097...
174
-
175
- julia> omega
176
- ω = 0.5671432904097...
167
+ """
168
+ Lambert's Omega (*Ω*) constant.
177
169
178
- julia> ω * exp(ω)
179
- 1.0
170
+ Lambert's *Ω* is the solution to *W(Ω) = 1* equation,
171
+ where *W(t) = t exp(t)* is the
172
+ [Lambert's *W* function](https://en.wikipedia.org/wiki/Lambert_W_function).
180
173
181
- julia> big(omega)
182
- 5.67143290409783872999968662210355549753815787186512508135131079223045793086683e-01
183
- ```
174
+ # See also
175
+ * https://en.wikipedia.org/wiki/Omega_constant
176
+ * [`lambertw()`][@ref SpecialFunctions.lambertw]
184
177
"""
185
- const ω = Irrational {:ω } ()
186
- @doc ( @doc ω) omega = ω
178
+ const Ω = Irrational {:lambertw_Omega } ()
179
+ const Omega = Ω # ASCII alias
187
180
188
- Base. Float64 (:: Irrational{:ω} ) = _omega_const
189
- Base. Float32 (:: Irrational{:ω} ) = Float32 (_omega_const)
190
- Base. Float16 (:: Irrational{:ω} ) = Float16 (_omega_const)
191
- Base. BigFloat (:: Irrational{:ω} ) = omega_const (BigFloat)
181
+ end
192
182
193
183
# ## Expansion about branch point x = -1/e
194
184
0 commit comments