Average Error: 14.1 → 2.3
Time: 1.3m
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[wj \cdot \left(wj + x \cdot -2\right) + x\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
wj \cdot \left(wj + x \cdot -2\right) + x
double f(double wj, double x) {
        double r60271459 = wj;
        double r60271460 = exp(r60271459);
        double r60271461 = r60271459 * r60271460;
        double r60271462 = x;
        double r60271463 = r60271461 - r60271462;
        double r60271464 = r60271460 + r60271461;
        double r60271465 = r60271463 / r60271464;
        double r60271466 = r60271459 - r60271465;
        return r60271466;
}

double f(double wj, double x) {
        double r60271467 = wj;
        double r60271468 = x;
        double r60271469 = -2.0;
        double r60271470 = r60271468 * r60271469;
        double r60271471 = r60271467 + r60271470;
        double r60271472 = r60271467 * r60271471;
        double r60271473 = r60271472 + r60271468;
        return r60271473;
}

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

Derivation

  1. Initial program 14.1

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

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

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

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

Reproduce

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