-
Notifications
You must be signed in to change notification settings - Fork 8
Lambert's Omega constant #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b1a500e
50056d3
2552035
e22a444
ba45b7b
a72e835
b4b2908
ee9180e
d5aae00
3fc6980
1ee42a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,12 @@ export | |
logten, # log(10) | ||
logπ, # log(π) | ||
log2π, # log(2π) | ||
log4π # log(4π) | ||
log4π, # log(4π) | ||
invℯ, # 1 / ℯ | ||
|
||
LambertW_Ω # Ω exp(Ω) = 1 | ||
|
||
|
||
include("stats.jl") | ||
include("lambertw_omega.jl") | ||
|
||
end # module |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||
# lazy-initialized LambertW Omega at 256-bit precision | ||||||
const LambertW_Omega_BigFloat256 = Ref{BigFloat}() | ||||||
|
||||||
# compute BigFloat Omega constant at arbitrary precision | ||||||
function compute_LambertW_Omega() | ||||||
# initialize Omega_BigFloat256 | ||||||
isassigned(LambertW_Omega_BigFloat256) || | ||||||
(LambertW_Omega_BigFloat256[] = BigFloat("0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194")) | ||||||
o = LambertW_Omega_BigFloat256[] # initial value | ||||||
precision(BigFloat) <= 256 && return o | ||||||
# iteratively improve the precision of the constant | ||||||
myeps = eps(BigFloat) | ||||||
for _ in 1:100 | ||||||
|
for _ in 1:100 | |
while true |
or alternatively move the stopping criterion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wiki says (I've just added the reference) that this is the quadratic method, the number of correct digits is doubled at each iteration. So 100 should be safe for any reasonable precision.
while true
sounds a bit dangerous.
I can increase it to 1000 and add a warning that the precision was not reached.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just use the stopping criterion, i.e., while abs(next_o - o) > eps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to avoid dead loop if there's some subtle bug in BigFloat
implementation or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What bug could cause a dead loop? Generally, we should assume that BigFloat
does not contain any bugs - and if we notice any, they should be fixed upstream.
BTW just came across the following while true
loop, I still think it would be a simple and straightforward implementation here as well: https://github.com/JuliaLang/julia/blob/3d11f7db65a3461320542aee3b0f26619c4e65e3/base/irrationals.jl#L54
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's worth caching the value in LambertW_Omega_BigFloat256
. I don't think this is done for other constants? Also it seems it would return a value of a different precision than requested in the case precision(BigFloat) < 256
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other constants either have corresponding mpfr_const_xxx()
functions or simple formulas.
But I agree it would be more straightforward to have just
o = BigFloat("0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194") # initial value with 256-bit precision
precision(BigFloat) <= 256 && return o
if BigFloat("...")
is fast enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the returned BigFloat constant should respect the current precision better, and the appropriate tests were added.
I still have kept the lambertw_Omega_BigFloat256
as I assume it's faster to reuse the initialized BigFloat than parse it each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much slower than the code in LambertW.jl. The two should be benchmarked explicitly before a PR would be accepted.
But, I agree with the others that it does not make sense to move the omega constant out of LambertW.jl. It should stay in LambertW.jl and the latter should be moved into SpecialFuncions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring should follow the conventions and recommendations in the Julia documentation: https://docs.julialang.org/en/v1/manual/documentation/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please suggest your variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have improved the docstring. But if you think it does not conform to the guidelines, please let me know of the specific changes you want to implement or just fix it yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.