Average Error: 13.7 → 1.2
Time: 6.7s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le 1.0018755083909558 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj - x \cdot 2, x\right) + \left(wj \cdot x\right) \cdot \left(\left(-2\right) + 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) \cdot \left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1} \cdot \frac{wj}{wj + 1}}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) + \frac{wj}{wj + 1}}\\ \end{array}\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj \le 1.0018755083909558 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj - x \cdot 2, x\right) + \left(wj \cdot x\right) \cdot \left(\left(-2\right) + 2\right)\\

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

\end{array}
double code(double wj, double x) {
	return (wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj)))));
}
double code(double wj, double x) {
	double temp;
	if ((wj <= 1.0018755083909558e-09)) {
		temp = (fma(wj, (wj - (x * 2.0)), x) + ((wj * x) * (-2.0 + 2.0)));
	} else {
		temp = ((((((x / (wj + 1.0)) / exp(wj)) + wj) * (((x / (wj + 1.0)) / exp(wj)) + wj)) - ((wj / (wj + 1.0)) * (wj / (wj + 1.0)))) / ((((x / (wj + 1.0)) / exp(wj)) + wj) + (wj / (wj + 1.0))));
	}
	return temp;
}

Error

Bits error versus wj

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.7
Target13.1
Herbie1.2
\[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.0018755083909558e-09

    1. Initial program 13.4

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

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

      \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt29.3

      \[\leadsto \color{blue}{\sqrt{x + {wj}^{2}} \cdot \sqrt{x + {wj}^{2}}} - 2 \cdot \left(wj \cdot x\right)\]
    6. Applied prod-diff29.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x + {wj}^{2}}, \sqrt{x + {wj}^{2}}, -\left(wj \cdot x\right) \cdot 2\right) + \mathsf{fma}\left(-wj \cdot x, 2, \left(wj \cdot x\right) \cdot 2\right)}\]
    7. Simplified0.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj - x \cdot 2, x\right)} + \mathsf{fma}\left(-wj \cdot x, 2, \left(wj \cdot x\right) \cdot 2\right)\]
    8. Simplified0.9

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

    if 1.0018755083909558e-09 < wj

    1. Initial program 25.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 1.0018755083909558 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj - x \cdot 2, x\right) + \left(wj \cdot x\right) \cdot \left(\left(-2\right) + 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) \cdot \left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1} \cdot \frac{wj}{wj + 1}}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) + \frac{wj}{wj + 1}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020049 +o rules:numerics
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"
  :precision binary64

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

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