Average Error: 13.7 → 2.1
Time: 36.8s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj, x - \left(wj + wj\right) \cdot x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj, x - \left(wj + wj\right) \cdot x\right)
double f(double wj, double x) {
        double r6995929 = wj;
        double r6995930 = exp(r6995929);
        double r6995931 = r6995929 * r6995930;
        double r6995932 = x;
        double r6995933 = r6995931 - r6995932;
        double r6995934 = r6995930 + r6995931;
        double r6995935 = r6995933 / r6995934;
        double r6995936 = r6995929 - r6995935;
        return r6995936;
}

double f(double wj, double x) {
        double r6995937 = wj;
        double r6995938 = x;
        double r6995939 = r6995937 + r6995937;
        double r6995940 = r6995939 * r6995938;
        double r6995941 = r6995938 - r6995940;
        double r6995942 = fma(r6995937, r6995937, r6995941);
        return r6995942;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.7

    \[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(wj, wj, x - \left(wj + wj\right) \cdot x\right)}\]
  4. Final simplification2.1

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

Reproduce

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