Average Error: 14.0 → 0.4
Time: 5.4s
Precision: binary64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le -1.41206892865688415 \cdot 10^{-8} \lor \neg \left(wj \le 9.022428011286162 \cdot 10^{-9}\right):\\ \;\;\;\;\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \left(\sqrt[3]{\frac{wj}{wj + 1}} \cdot \sqrt[3]{\frac{wj}{wj + 1}}\right) \cdot \sqrt[3]{\frac{wj}{wj + 1}}\\ \mathbf{else}:\\ \;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)\\ \end{array}\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj \le -1.41206892865688415 \cdot 10^{-8} \lor \neg \left(wj \le 9.022428011286162 \cdot 10^{-9}\right):\\
\;\;\;\;\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \left(\sqrt[3]{\frac{wj}{wj + 1}} \cdot \sqrt[3]{\frac{wj}{wj + 1}}\right) \cdot \sqrt[3]{\frac{wj}{wj + 1}}\\

\mathbf{else}:\\
\;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)\\

\end{array}
double code(double wj, double x) {
	return ((double) (wj - ((double) (((double) (((double) (wj * ((double) exp(wj)))) - x)) / ((double) (((double) exp(wj)) + ((double) (wj * ((double) exp(wj))))))))));
}
double code(double wj, double x) {
	double VAR;
	if (((wj <= -1.4120689286568841e-08) || !(wj <= 9.022428011286162e-09))) {
		VAR = ((double) (((double) (((double) (((double) (x / ((double) (wj + 1.0)))) / ((double) exp(wj)))) + wj)) - ((double) (((double) (((double) cbrt(((double) (wj / ((double) (wj + 1.0)))))) * ((double) cbrt(((double) (wj / ((double) (wj + 1.0)))))))) * ((double) cbrt(((double) (wj / ((double) (wj + 1.0))))))))));
	} else {
		VAR = ((double) (((double) (x + ((double) pow(wj, 2.0)))) - ((double) (2.0 * ((double) (wj * x))))));
	}
	return VAR;
}

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.0
Target13.4
Herbie0.4
\[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 < -1.41206892865688415e-8 or 9.022428011286162e-9 < wj

    1. Initial program 18.3

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified3.8

      \[\leadsto \color{blue}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt4.5

      \[\leadsto \left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \color{blue}{\left(\sqrt[3]{\frac{wj}{wj + 1}} \cdot \sqrt[3]{\frac{wj}{wj + 1}}\right) \cdot \sqrt[3]{\frac{wj}{wj + 1}}}\]

    if -1.41206892865688415e-8 < wj < 9.022428011286162e-9

    1. Initial program 13.8

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified13.8

      \[\leadsto \color{blue}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1}}\]
    3. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le -1.41206892865688415 \cdot 10^{-8} \lor \neg \left(wj \le 9.022428011286162 \cdot 10^{-9}\right):\\ \;\;\;\;\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \left(\sqrt[3]{\frac{wj}{wj + 1}} \cdot \sqrt[3]{\frac{wj}{wj + 1}}\right) \cdot \sqrt[3]{\frac{wj}{wj + 1}}\\ \mathbf{else}:\\ \;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020152 
(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))))))