Average Error: 13.1 → 2.1
Time: 8.4s
Precision: binary64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)
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) {
	return ((double) (((double) (x + ((double) pow(wj, 2.0)))) - ((double) (2.0 * ((double) (wj * x))))));
}

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.1
Target12.4
Herbie2.1
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Initial program 13.1

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

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

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

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

Reproduce

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