Average Error: 13.7 → 2.1
Time: 34.8s
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 r21403728 = wj;
        double r21403729 = exp(r21403728);
        double r21403730 = r21403728 * r21403729;
        double r21403731 = x;
        double r21403732 = r21403730 - r21403731;
        double r21403733 = r21403729 + r21403730;
        double r21403734 = r21403732 / r21403733;
        double r21403735 = r21403728 - r21403734;
        return r21403735;
}

double f(double wj, double x) {
        double r21403736 = x;
        double r21403737 = wj;
        double r21403738 = r21403736 * r21403737;
        double r21403739 = -2.0;
        double r21403740 = fma(r21403737, r21403737, r21403736);
        double r21403741 = fma(r21403738, r21403739, r21403740);
        return r21403741;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.7
Target13.0
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.2

    \[\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 2019173 +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))))))