Average Error: 13.5 → 2.1
Time: 24.3s
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 r7581354 = wj;
        double r7581355 = exp(r7581354);
        double r7581356 = r7581354 * r7581355;
        double r7581357 = x;
        double r7581358 = r7581356 - r7581357;
        double r7581359 = r7581355 + r7581356;
        double r7581360 = r7581358 / r7581359;
        double r7581361 = r7581354 - r7581360;
        return r7581361;
}

double f(double wj, double x) {
        double r7581362 = x;
        double r7581363 = -2.0;
        double r7581364 = r7581362 * r7581363;
        double r7581365 = wj;
        double r7581366 = fma(r7581365, r7581365, r7581362);
        double r7581367 = fma(r7581364, r7581365, r7581366);
        return r7581367;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target12.8
Herbie2.1
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Initial program 13.5

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

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

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

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

Reproduce

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