Average Error: 13.6 → 2.3
Time: 35.8s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\left(wj - x \cdot 2\right) \cdot wj + x\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\left(wj - x \cdot 2\right) \cdot wj + x
double f(double wj, double x) {
        double r7836425 = wj;
        double r7836426 = exp(r7836425);
        double r7836427 = r7836425 * r7836426;
        double r7836428 = x;
        double r7836429 = r7836427 - r7836428;
        double r7836430 = r7836426 + r7836427;
        double r7836431 = r7836429 / r7836430;
        double r7836432 = r7836425 - r7836431;
        return r7836432;
}

double f(double wj, double x) {
        double r7836433 = wj;
        double r7836434 = x;
        double r7836435 = 2.0;
        double r7836436 = r7836434 * r7836435;
        double r7836437 = r7836433 - r7836436;
        double r7836438 = r7836437 * r7836433;
        double r7836439 = r7836438 + r7836434;
        return r7836439;
}

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

Derivation

  1. Initial program 13.6

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
  2. Taylor expanded around 0 2.2

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

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

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

Reproduce

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

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

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