Average Error: 13.3 → 1.4
Time: 9.3s
Precision: binary64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le -3.868446554170448 \cdot 10^{-310}:\\ \;\;\;\;x + \left({\left(\sqrt[3]{-1}\right)}^{2} \cdot {\left(\frac{-1}{wj}\right)}^{\frac{-2}{3}}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\ \mathbf{elif}\;wj \le 9.93050096655964495 \cdot 10^{-9}:\\ \;\;\;\;x + \left({\left({\left(\sqrt[3]{\sqrt[3]{wj}}\right)}^{\left(\sqrt[3]{4} \cdot \sqrt[3]{4}\right)}\right)}^{\left(\sqrt[3]{4}\right)} \cdot \left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(wj - \frac{wj}{wj + 1}\right) + \frac{\frac{x}{e^{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 -3.868446554170448 \cdot 10^{-310}:\\
\;\;\;\;x + \left({\left(\sqrt[3]{-1}\right)}^{2} \cdot {\left(\frac{-1}{wj}\right)}^{\frac{-2}{3}}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\

\mathbf{elif}\;wj \le 9.93050096655964495 \cdot 10^{-9}:\\
\;\;\;\;x + \left({\left({\left(\sqrt[3]{\sqrt[3]{wj}}\right)}^{\left(\sqrt[3]{4} \cdot \sqrt[3]{4}\right)}\right)}^{\left(\sqrt[3]{4}\right)} \cdot \left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\

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

\end{array}
double code(double wj, double x) {
	return ((double) (wj - (((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 <= -3.86844655417045e-310)) {
		VAR = ((double) (x + ((double) (((double) (((double) pow(((double) cbrt(-1.0)), 2.0)) * ((double) pow((-1.0 / wj), -0.6666666666666666)))) * ((double) (((double) cbrt(wj)) * ((double) (wj - ((double) (2.0 * x))))))))));
	} else {
		double VAR_1;
		if ((wj <= 9.930500966559645e-09)) {
			VAR_1 = ((double) (x + ((double) (((double) (((double) pow(((double) pow(((double) cbrt(((double) cbrt(wj)))), ((double) (((double) cbrt(4.0)) * ((double) cbrt(4.0)))))), ((double) cbrt(4.0)))) * ((double) (((double) cbrt(((double) cbrt(wj)))) * ((double) cbrt(((double) cbrt(wj)))))))) * ((double) (((double) cbrt(wj)) * ((double) (wj - ((double) (2.0 * x))))))))));
		} else {
			VAR_1 = ((double) (((double) (wj - (wj / ((double) (wj + 1.0))))) + ((x / ((double) exp(wj))) / ((double) (wj + 1.0)))));
		}
		VAR = VAR_1;
	}
	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

Original13.3
Target12.6
Herbie1.4
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 3 regimes
  2. if wj < -3.868446554170448e-310

    1. Initial program 13.2

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

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

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

      \[\leadsto \color{blue}{x + wj \cdot \left(wj - 2 \cdot x\right)}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt1.5

      \[\leadsto x + \color{blue}{\left(\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \sqrt[3]{wj}\right)} \cdot \left(wj - 2 \cdot x\right)\]
    7. Applied associate-*l*1.6

      \[\leadsto x + \color{blue}{\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)}\]
    8. Taylor expanded around -inf 1.9

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

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

    if -3.868446554170448e-310 < wj < 9.93050096655964495e-9

    1. Initial program 12.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified12.6

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

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

      \[\leadsto \color{blue}{x + wj \cdot \left(wj - 2 \cdot x\right)}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.3

      \[\leadsto x + \color{blue}{\left(\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \sqrt[3]{wj}\right)} \cdot \left(wj - 2 \cdot x\right)\]
    7. Applied associate-*l*0.3

      \[\leadsto x + \color{blue}{\left(\sqrt[3]{wj} \cdot \sqrt[3]{wj}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt0.4

      \[\leadsto x + \left(\sqrt[3]{wj} \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right) \cdot \sqrt[3]{\sqrt[3]{wj}}\right)}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\]
    10. Applied add-cube-cbrt0.4

      \[\leadsto x + \left(\color{blue}{\left(\left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right) \cdot \sqrt[3]{\sqrt[3]{wj}}\right)} \cdot \left(\left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right) \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\]
    11. Applied swap-sqr0.4

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

      \[\leadsto x + \left(\color{blue}{{\left(\sqrt[3]{\sqrt[3]{wj}}\right)}^{4}} \cdot \left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\]
    13. Using strategy rm
    14. Applied add-cube-cbrt0.8

      \[\leadsto x + \left({\left(\sqrt[3]{\sqrt[3]{wj}}\right)}^{\color{blue}{\left(\left(\sqrt[3]{4} \cdot \sqrt[3]{4}\right) \cdot \sqrt[3]{4}\right)}} \cdot \left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\]
    15. Applied pow-unpow0.8

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

    if 9.93050096655964495e-9 < wj

    1. Initial program 27.2

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

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

      \[\leadsto wj - \color{blue}{\left(\frac{wj}{wj + 1} - \frac{\frac{x}{e^{wj}}}{wj + 1}\right)}\]
    5. Applied associate--r-2.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le -3.868446554170448 \cdot 10^{-310}:\\ \;\;\;\;x + \left({\left(\sqrt[3]{-1}\right)}^{2} \cdot {\left(\frac{-1}{wj}\right)}^{\frac{-2}{3}}\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\ \mathbf{elif}\;wj \le 9.93050096655964495 \cdot 10^{-9}:\\ \;\;\;\;x + \left({\left({\left(\sqrt[3]{\sqrt[3]{wj}}\right)}^{\left(\sqrt[3]{4} \cdot \sqrt[3]{4}\right)}\right)}^{\left(\sqrt[3]{4}\right)} \cdot \left(\sqrt[3]{\sqrt[3]{wj}} \cdot \sqrt[3]{\sqrt[3]{wj}}\right)\right) \cdot \left(\sqrt[3]{wj} \cdot \left(wj - 2 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(wj - \frac{wj}{wj + 1}\right) + \frac{\frac{x}{e^{wj}}}{wj + 1}\\ \end{array}\]

Reproduce

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