Average Error: 13.6 → 2.1
Time: 4.9s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj - x \cdot 2, x\right) + \left(wj \cdot x\right) \cdot \left(\left(-2\right) + 2\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj - x \cdot 2, x\right) + \left(wj \cdot x\right) \cdot \left(\left(-2\right) + 2\right)
double f(double wj, double x) {
        double r216722 = wj;
        double r216723 = exp(r216722);
        double r216724 = r216722 * r216723;
        double r216725 = x;
        double r216726 = r216724 - r216725;
        double r216727 = r216723 + r216724;
        double r216728 = r216726 / r216727;
        double r216729 = r216722 - r216728;
        return r216729;
}

double f(double wj, double x) {
        double r216730 = wj;
        double r216731 = x;
        double r216732 = 2.0;
        double r216733 = r216731 * r216732;
        double r216734 = r216730 - r216733;
        double r216735 = fma(r216730, r216734, r216731);
        double r216736 = r216730 * r216731;
        double r216737 = -r216732;
        double r216738 = r216737 + r216732;
        double r216739 = r216736 * r216738;
        double r216740 = r216735 + r216739;
        return r216740;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.6

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
  2. Simplified13.0

    \[\leadsto \color{blue}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1}}\]
  3. Taylor expanded around 0 2.1

    \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt29.1

    \[\leadsto \color{blue}{\sqrt{x + {wj}^{2}} \cdot \sqrt{x + {wj}^{2}}} - 2 \cdot \left(wj \cdot x\right)\]
  6. Applied prod-diff29.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x + {wj}^{2}}, \sqrt{x + {wj}^{2}}, -\left(wj \cdot x\right) \cdot 2\right) + \mathsf{fma}\left(-wj \cdot x, 2, \left(wj \cdot x\right) \cdot 2\right)}\]
  7. Simplified2.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(wj, wj - x \cdot 2, x\right)} + \mathsf{fma}\left(-wj \cdot x, 2, \left(wj \cdot x\right) \cdot 2\right)\]
  8. Simplified2.1

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

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

Reproduce

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