Average Error: 14.4 → 0.9
Time: 3.6s
Precision: binary64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \leq 7.616267884561549 \cdot 10^{-09}:\\ \;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\ \end{array}\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj \leq 7.616267884561549 \cdot 10^{-09}:\\
\;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\

\mathbf{else}:\\
\;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\

\end{array}
(FPCore (wj x)
 :precision binary64
 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x)
 :precision binary64
 (if (<= wj 7.616267884561549e-09)
   (+ x (* wj (+ wj (* x -2.0))))
   (+ wj (/ (- (* x (exp (- wj))) wj) (+ wj 1.0)))))
double code(double wj, double x) {
	return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
	double tmp;
	if (wj <= 7.616267884561549e-09) {
		tmp = x + (wj * (wj + (x * -2.0)));
	} else {
		tmp = wj + (((x * exp(-wj)) - wj) / (wj + 1.0));
	}
	return tmp;
}

Error

Bits error versus wj

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.4
Target13.7
Herbie0.9
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if wj < 7.6162678845615486e-9

    1. Initial program 14.0

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified14.0

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}}\]
    3. Taylor expanded around 0 0.8

      \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
    4. Simplified0.8

      \[\leadsto \color{blue}{x + wj \cdot \left(wj + x \cdot -2\right)}\]

    if 7.6162678845615486e-9 < wj

    1. Initial program 27.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified2.1

      \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}}\]
    3. Using strategy rm
    4. Applied div-inv_binary642.2

      \[\leadsto wj + \frac{\color{blue}{x \cdot \frac{1}{e^{wj}}} - wj}{wj + 1}\]
    5. Simplified2.1

      \[\leadsto wj + \frac{x \cdot \color{blue}{e^{-wj}} - wj}{wj + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \leq 7.616267884561549 \cdot 10^{-09}:\\ \;\;\;\;x + wj \cdot \left(wj + x \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \frac{x \cdot e^{-wj} - wj}{wj + 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020224 
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"
  :precision binary64

  :herbie-target
  (- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))