Average Error: 13.4 → 2.0
Time: 4.0s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj, x - 2 \cdot \left(wj \cdot x\right)\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj, x - 2 \cdot \left(wj \cdot x\right)\right)
double f(double wj, double x) {
        double r249941 = wj;
        double r249942 = exp(r249941);
        double r249943 = r249941 * r249942;
        double r249944 = x;
        double r249945 = r249943 - r249944;
        double r249946 = r249942 + r249943;
        double r249947 = r249945 / r249946;
        double r249948 = r249941 - r249947;
        return r249948;
}

double f(double wj, double x) {
        double r249949 = wj;
        double r249950 = x;
        double r249951 = 2.0;
        double r249952 = r249949 * r249950;
        double r249953 = r249951 * r249952;
        double r249954 = r249950 - r249953;
        double r249955 = fma(r249949, r249949, r249954);
        return r249955;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.4

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

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

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

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

Reproduce

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