Average Error: 13.1 → 2.3
Time: 14.9s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj \cdot x, -2, \mathsf{fma}\left(wj, wj, x\right)\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj \cdot x, -2, \mathsf{fma}\left(wj, wj, x\right)\right)
double f(double wj, double x) {
        double r363440 = wj;
        double r363441 = exp(r363440);
        double r363442 = r363440 * r363441;
        double r363443 = x;
        double r363444 = r363442 - r363443;
        double r363445 = r363441 + r363442;
        double r363446 = r363444 / r363445;
        double r363447 = r363440 - r363446;
        return r363447;
}

double f(double wj, double x) {
        double r363448 = wj;
        double r363449 = x;
        double r363450 = r363448 * r363449;
        double r363451 = -2.0;
        double r363452 = fma(r363448, r363448, r363449);
        double r363453 = fma(r363450, r363451, r363452);
        return r363453;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.1

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

    \[\leadsto \color{blue}{wj - \frac{wj - \frac{x}{e^{wj}}}{1 + wj}}\]
  3. Taylor expanded around 0 2.3

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

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

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

Reproduce

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