Average Error: 13.9 → 2.2
Time: 24.6s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(x \cdot -2, wj, \mathsf{fma}\left(wj, wj, x\right)\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(x \cdot -2, wj, \mathsf{fma}\left(wj, wj, x\right)\right)
double f(double wj, double x) {
        double r9376558 = wj;
        double r9376559 = exp(r9376558);
        double r9376560 = r9376558 * r9376559;
        double r9376561 = x;
        double r9376562 = r9376560 - r9376561;
        double r9376563 = r9376559 + r9376560;
        double r9376564 = r9376562 / r9376563;
        double r9376565 = r9376558 - r9376564;
        return r9376565;
}

double f(double wj, double x) {
        double r9376566 = x;
        double r9376567 = -2.0;
        double r9376568 = r9376566 * r9376567;
        double r9376569 = wj;
        double r9376570 = fma(r9376569, r9376569, r9376566);
        double r9376571 = fma(r9376568, r9376569, r9376570);
        return r9376571;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.9
Target13.3
Herbie2.2
\[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. Taylor expanded around 0 2.2

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

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

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

Reproduce

herbie shell --seed 2019162 +o rules:numerics
(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))))))