-
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should stick with the convention in this package and in base, and use lowercase names and in particular no camel case. I.e., e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it "ω" or "Ω" (I've taken the latter from https://en.wikipedia.org/wiki/Omega_constant)? I think upper/lowercase for constants has a difference (π vs Π). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it is called "Omega constant" I think we should just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the revised version it's called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the constants in |
||
|
||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Suggested change
or alternatively move the stopping criterion here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just use the stopping criterion, i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What bug could cause a dead loop? Generally, we should assume that BTW just came across the following |
||||||
o_ = (1 + o) / (1 + exp(o)) | ||||||
abs(o - o_) <= myeps && break | ||||||
o = o_ | ||||||
end | ||||||
return o | ||||||
end | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's worth caching the value in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other constants either have corresponding o = BigFloat("0.5671432904097838729999686622103555497538157871865125081351310792230457930866845666932194") # initial value with 256-bit precision
precision(BigFloat) <= 256 && return o if There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
|
||||||
@irrational LambertW_Ω 0.567143290409783872999968662210355 compute_LambertW_Omega() | ||||||
|
||||||
""" | ||||||
Lambert's Omega (Ω) constant, such that Ω exp(Ω) = 1. | ||||||
|
||||||
*W(Ω) = 1*, where *W(t) = t exp(t)* is the *Lambert's W function*. | ||||||
|
||||||
# See | ||||||
https://en.wikipedia.org/wiki/Omega_constant | ||||||
""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||||||
LambertW_Ω | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Uh oh!
There was an error while loading. Please reload this page.