Average Error: 13.4 → 2.2
Time: 9.6s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, \mathsf{fma}\left(x, -2, wj\right), x\right) + wj \cdot \mathsf{fma}\left(-2, x, 2 \cdot x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, \mathsf{fma}\left(x, -2, wj\right), x\right) + wj \cdot \mathsf{fma}\left(-2, x, 2 \cdot x\right)
double f(double wj, double x) {
        double r238971 = wj;
        double r238972 = exp(r238971);
        double r238973 = r238971 * r238972;
        double r238974 = x;
        double r238975 = r238973 - r238974;
        double r238976 = r238972 + r238973;
        double r238977 = r238975 / r238976;
        double r238978 = r238971 - r238977;
        return r238978;
}

double f(double wj, double x) {
        double r238979 = wj;
        double r238980 = x;
        double r238981 = -2.0;
        double r238982 = fma(r238980, r238981, r238979);
        double r238983 = fma(r238979, r238982, r238980);
        double r238984 = 2.0;
        double r238985 = -r238984;
        double r238986 = r238984 * r238980;
        double r238987 = fma(r238985, r238980, r238986);
        double r238988 = r238979 * r238987;
        double r238989 = r238983 + r238988;
        return r238989;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.4
Target12.8
Herbie2.2
\[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. Simplified12.8

    \[\leadsto \color{blue}{\frac{\frac{x}{e^{wj}} - wj}{1 + wj} + wj}\]
  3. Taylor expanded around 0 2.2

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

    \[\leadsto \color{blue}{x + wj \cdot \left(wj - x \cdot 2\right)}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt32.8

    \[\leadsto x + wj \cdot \left(\color{blue}{\sqrt{wj} \cdot \sqrt{wj}} - x \cdot 2\right)\]
  7. Applied prod-diff32.8

    \[\leadsto x + wj \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{wj}, \sqrt{wj}, -2 \cdot x\right) + \mathsf{fma}\left(-2, x, 2 \cdot x\right)\right)}\]
  8. Applied distribute-lft-in32.8

    \[\leadsto x + \color{blue}{\left(wj \cdot \mathsf{fma}\left(\sqrt{wj}, \sqrt{wj}, -2 \cdot x\right) + wj \cdot \mathsf{fma}\left(-2, x, 2 \cdot x\right)\right)}\]
  9. Applied associate-+r+32.8

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

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

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

Reproduce

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