Average Error: 13.5 → 2.1
Time: 27.6s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(x \cdot wj, -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(x \cdot wj, -2, \mathsf{fma}\left(wj, wj, x\right)\right)
double f(double wj, double x) {
        double r9249735 = wj;
        double r9249736 = exp(r9249735);
        double r9249737 = r9249735 * r9249736;
        double r9249738 = x;
        double r9249739 = r9249737 - r9249738;
        double r9249740 = r9249736 + r9249737;
        double r9249741 = r9249739 / r9249740;
        double r9249742 = r9249735 - r9249741;
        return r9249742;
}

double f(double wj, double x) {
        double r9249743 = x;
        double r9249744 = wj;
        double r9249745 = r9249743 * r9249744;
        double r9249746 = -2.0;
        double r9249747 = fma(r9249744, r9249744, r9249743);
        double r9249748 = fma(r9249745, r9249746, r9249747);
        return r9249748;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.5

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

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

Reproduce

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