-
Notifications
You must be signed in to change notification settings - Fork 9
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
Lambert's Omega constant #12
Conversation
useful in many situations, also -exp(-1) is the branching point of Lambert's W_0(t) and W_{-1}(t)
Codecov Report
@@ Coverage Diff @@
## main #12 +/- ##
=========================================
+ Coverage 0 80.00% +80.00%
=========================================
Files 0 1 +1
Lines 0 10 +10
=========================================
+ Hits 0 8 +8
- Misses 0 2 +2
Continue to review full report at Codecov.
|
Pull Request Test Coverage Report for Build 1481553290Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
3c4cdef
to
dcc33d3
Compare
dcc33d3
to
50056d3
Compare
src/IrrationalConstants.jl
Outdated
log4π, # log(4π) | ||
invℯ, # 1 / ℯ | ||
|
||
LambertW_Ω # Ω exp(Ω) = 1 |
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.
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. lambertwω
or just ω
. Again, also we might want to replace it with or at least add an ASCII alias.
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 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 Π).
I also prefer Julian convention to avoid underscore in the names, but in this case mixing latin and greek wω
doesn't contribute to readability. What about lambertw_Ω
?
I also think ASCII alias (lambertw_Omega
) would be very useful, what's the conventional way to define it?
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.
Since it is called "Omega constant" I think we should just use Ω
(or ω
if we want to stick with the convention in Base and this package of only using lowercase names). And correspondingly, the ASCII alias would just be Omega
or omega
.
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.
In the revised version it's called lambertw_Ω
and lambertw_Omega
alias is added. I think plain Ω
would be confusing, since it's less well known and/or may interfere with variable name in the user code.
lambertwΩ
IMO is quite unreadable.
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.
All of the constants in MathConstants
and IrrationalConstants
follow a naming convention. The omega constant should follow the same convention. None of your proposals follow this convention. But, in any case, it should stay in LambertW.jl
.
src/lambertw_omega.jl
Outdated
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 | ||
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 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
src/lambertw_omega.jl
Outdated
""" | ||
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 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.
https://en.wikipedia.org/wiki/Omega_constant | ||
""" | ||
LambertW_Ω | ||
|
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.
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.
Can you remind me why this constant should be added to IrrationalConstants? Isn't it sufficient to add it to SpecialFunctions where it is needed?
src/lambertw_omega.jl
Outdated
precision(o) <= 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 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.
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
I guess it's optional to add it to IrrationalConstants, but isn't it the exact purpose of this package to have all well-accepted constants here? (given that the code to calculate them is simple enough and doesn't introduce additional dependencies) I don't have any real use-cases in mind (besides some educational), but MathWorld page shows that the constant possesses the properties outside of the scope of Lambert's W (golden ratio of exponents, power tower). |
The purpose is to avoid duplicate definitions in multiple packages by defining commonly used constants in a lightweight package. If a constant is only used in a single package there is no need to add it to IrrationalConstants - there is no benefit over defining them in the package where it is used but it might increase compilation and loading times for all other packages that depend on IrrationalConstants. I think we need at least 2, better 3, packages that would make use of it. |
I think I'm repeating myself, but
Do you think being so conservative about this package is the right thing for the Julia ecosystem? |
Yes. I'm fine with adding new constants (proposed and added some myself) if they are used in multiple downstream packages. The package is used by large parts of the Julia ecosystem, both directly and indirectly, so I don't think increased compilation and load times are acceptable if it is only used in a single package.
Are there any concrete packages in addition to SpecialFunctions where you plan to use it?
You would want to use these improvements in any case, regardless of whether the code ends up in SpecialFunctions or IrrationalConstants. I don't think it was a waste of time to improve it. |
I agree with @devmotion . This constant belongs in If LambertW.jl is moved to SpecialFunctions, I'm not sure how to organize the name. Currently, I'd recommend |
....
export LambertW
module LambertW
@irrational Omega ....
....
end
.... |
|
ah, true. My bad |
then it could be something like ....
@irrational lambertw_Omega .... # private declaration
export LambertW
module LambertW
const Omega = ..lambertw_Omega # public alias
....
end
.... |
|
Sure. My idea is that with the suggested scheme the identifier used by |
Since the discussion about Lambert W function has been reactivated (JuliaMath/SpecialFunctions.jl/issues/84), and I have prepared an updated version of that PR (JuliaMath/SpecialFunctions.jl/issues/371) that expects Omega in IrrationalConstants.jl, I think we need to make a decision rather soon. I am fine with moving Omega to SpecialFunctions.jl or LambertW.jl, I just find that the admittance bar (several packages depending on the constant) is quite high, so only the constants that are transformations of Pi or Euler would make it here. cc @ViralBShah |
My stance is clear: I'm fine with adding the constant if it is used by other packages apart from LambertW/SpecialFunctions (which obviously don't depend on these packages). Otherwise there is no need to add them to IrrationalConstants since the purpose of this package is not to define all irrational constants used in Julia packages but to avoid redundant definitions in independent packages. (BTW I also don't think there's a need to rush this PR or the ones in SpecialFunctions since there is no missing functionality or bugs addressed by them - one can use the Lambert W function with the LambertW package without any issues as far as I know.) |
I don't have a strong view one way or another. I was mainly going through old issues and PRs and seeing what could be closed, salvaged, etc. It seems like the preference is to have a separate package. |
I prefer packages to be in orgs, so that more people can help with ongoing maintenance tasks. Naturally, the package does need the original author's energy and contributions for the most part. |
Ok, I'm closing this PR and opening the one for adding just |
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
using the code from JuliaMath/IrrationalConstants.jl/issues/12 No __init__() section is required
Add Lambert's Omega constant as a part of moving LambertW.jl into SpecialFunctions.jl (see JuliaMath/SpecialFunctions.jl/pull/84).
Also add the related
inve = exp(-1)
constant, since-exp(-1)
is the branching point for W_0(t) and W_{-1}(t).cc @jlapeyre