Average Error: 13.8 → 2.0
Time: 24.5s
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 r9962547 = wj;
        double r9962548 = exp(r9962547);
        double r9962549 = r9962547 * r9962548;
        double r9962550 = x;
        double r9962551 = r9962549 - r9962550;
        double r9962552 = r9962548 + r9962549;
        double r9962553 = r9962551 / r9962552;
        double r9962554 = r9962547 - r9962553;
        return r9962554;
}

double f(double wj, double x) {
        double r9962555 = wj;
        double r9962556 = x;
        double r9962557 = r9962555 * r9962556;
        double r9962558 = -2.0;
        double r9962559 = r9962557 * r9962558;
        double r9962560 = fma(r9962555, r9962555, r9962556);
        double r9962561 = r9962559 + r9962560;
        return r9962561;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.8
Target13.2
Herbie2.0
\[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. Taylor expanded around 0 2.0

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

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

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

Reproduce

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