Average Error: 13.7 → 2.2
Time: 20.8s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\left(wj \cdot x\right) \cdot -2 + \mathsf{fma}\left(wj, wj, x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\left(wj \cdot x\right) \cdot -2 + \mathsf{fma}\left(wj, wj, x\right)
double f(double wj, double x) {
        double r2510465 = wj;
        double r2510466 = exp(r2510465);
        double r2510467 = r2510465 * r2510466;
        double r2510468 = x;
        double r2510469 = r2510467 - r2510468;
        double r2510470 = r2510466 + r2510467;
        double r2510471 = r2510469 / r2510470;
        double r2510472 = r2510465 - r2510471;
        return r2510472;
}

double f(double wj, double x) {
        double r2510473 = wj;
        double r2510474 = x;
        double r2510475 = r2510473 * r2510474;
        double r2510476 = -2.0;
        double r2510477 = r2510475 * r2510476;
        double r2510478 = fma(r2510473, r2510473, r2510474);
        double r2510479 = r2510477 + r2510478;
        return r2510479;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.7

    \[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(wj, wj, x\right) + \left(x \cdot wj\right) \cdot -2}\]
  4. Final simplification2.2

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

Reproduce

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