-
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b1a500e
add exp(-1) constant
alyst 50056d3
add Lambert's Omega constant
alyst 2552035
add ASCII inve alias
alyst e22a444
LambertW => lambertw, add lambertw_Omega alias
alyst ba45b7b
improve lambertw_Omega docstring
alyst a72e835
lambertw_Omega: better handle BigFloat precision
alyst b4b2908
try to fix Omega precision for Julia 1.0
alyst ee9180e
Omega: remove BigFloat lazy-init to fix Julia 1.0
alyst d5aae00
Omega: ref. for computation method
alyst 3fc6980
Omega: allow 1000 iters, warn if prec not reached
alyst 1ee42a5
rename to LambertW.Omega
alyst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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 lambertw_Omega_BigFloat256 | ||
isassigned(lambertw_Omega_BigFloat256) || | ||
(lambertw_Omega_BigFloat256[] = BigFloat("0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194", 256)) | ||
o = BigFloat(lambertw_Omega_BigFloat256[], precision(BigFloat)) # initial value with current precision | ||
precision(o) <= 256 && return o | ||
# iteratively improve the precision of the constant | ||
myeps = eps(BigFloat) | ||
for _ in 1:100 | ||
o_ = (1 + o) / (1 + exp(o)) | ||
abs(o - o_) <= myeps && break | ||
o = o_ | ||
end | ||
return o | ||
end | ||
|
||
@irrational lambertw_Ω 0.567143290409783872999968662210355 compute_lambertw_Omega() | ||
const lambertw_Omega = lambertw_Ω # ASCII alias | ||
|
||
""" | ||
Lambert's Omega (*Ω*) constant. | ||
|
||
Lambert's *Ω* is the solution to *W(Ω) = 1* equation, | ||
where *W(t) = t exp(t)* is the | ||
[Lambert's *W* function](https://en.wikipedia.org/wiki/Lambert_W_function). | ||
|
||
# See also | ||
* https://en.wikipedia.org/wiki/Omega_constant | ||
* [`lambertw()`][@ref SpecialFunctions.lambertw] | ||
""" | ||
lambertw_Ω |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this enough for higher precision? It seems a bit dangerous to upper bound the number of iterations.
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