6
1
Your challenge is to compute the Lambert W function. The W of x is defined to be the real value(s) y such that
y = W(x) if x = y*(e^y)
where e = 2.718281828
is Euler's number.
Sometimes, y
may not be real.
Examples
W(-1) = non-real
W(-0.1) = -0.11183, -3.57715
W(1) = 0.56714
W(2) = 0.85261
Here's a quick graph of what this function looks like.
Rules
Your goal is to take an input and output either nothing, 1 solution, or 2 solutions, out to 5 significant figs. You should expect float inputs within the reasonable range of -100..100
.
This is code-golf, so shortest code wins.
1A note about Lambert W function: there is no solution for
x < -1/e
, two solutions for-1/e < x < 0
, and one solution forx == -1/e
orx >= 0
. – JungHwan Min – 2017-11-23T05:58:34.10315 places after the decimal, or 5 significant figures? Since W^-1(x) tends to negative infinity when x->0-, it is hard to get 5 places after the decimal. – Colera Su – 2017-11-23T08:04:09.377
1If one input should give two values, this is not a function – Luis Mendo – 2017-11-23T10:43:10.293
@Mr.Xcoder Sure, though the
non-real
output should be reasonable. – Simply Beautiful Art – 2017-11-23T12:50:07.837@ColeraSu Fixed. – Simply Beautiful Art – 2017-11-23T12:51:13.283
@LuisMendo It's a multivalued 'function'.
– Simply Beautiful Art – 2017-11-23T12:54:56.9772I think a nice way to handle multiple solutions is the output being a list of reals, containing 0, 1, or 2 values. Would this be allowed? – xnor – 2017-11-23T16:56:59.247
@xnor Sounds like a great idea. Editting. – Simply Beautiful Art – 2017-11-23T17:10:49.983