Average Error: 13.8 → 2.1
Time: 17.6s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)
double f(double wj, double x) {
        double r120518 = wj;
        double r120519 = exp(r120518);
        double r120520 = r120518 * r120519;
        double r120521 = x;
        double r120522 = r120520 - r120521;
        double r120523 = r120519 + r120520;
        double r120524 = r120522 / r120523;
        double r120525 = r120518 - r120524;
        return r120525;
}

double f(double wj, double x) {
        double r120526 = wj;
        double r120527 = x;
        double r120528 = fma(r120526, r120526, r120527);
        double r120529 = 2.0;
        double r120530 = r120526 * r120527;
        double r120531 = r120529 * r120530;
        double r120532 = r120528 - r120531;
        return r120532;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.8

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

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

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

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"

  :herbie-target
  (- wj (- (/ wj (+ wj 1.0)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))