Average Error: 13.9 → 2.3
Time: 7.7s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj - x \cdot 2, x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj - x \cdot 2, x\right)
double f(double wj, double x) {
        double r188432 = wj;
        double r188433 = exp(r188432);
        double r188434 = r188432 * r188433;
        double r188435 = x;
        double r188436 = r188434 - r188435;
        double r188437 = r188433 + r188434;
        double r188438 = r188436 / r188437;
        double r188439 = r188432 - r188438;
        return r188439;
}

double f(double wj, double x) {
        double r188440 = wj;
        double r188441 = x;
        double r188442 = 2.0;
        double r188443 = r188441 * r188442;
        double r188444 = r188440 - r188443;
        double r188445 = fma(r188440, r188444, r188441);
        return r188445;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.9
Target13.2
Herbie2.3
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Initial program 13.9

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

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

    \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
  4. Taylor expanded around 0 2.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj - x \cdot 2, x\right)}\]
  6. Final simplification2.3

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

Reproduce

herbie shell --seed 2020025 +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))))))