Average Error: 13.9 → 2.3
Time: 11.8s
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 r778 = wj;
        double r779 = exp(r778);
        double r780 = r778 * r779;
        double r781 = x;
        double r782 = r780 - r781;
        double r783 = r779 + r780;
        double r784 = r782 / r783;
        double r785 = r778 - r784;
        return r785;
}

double f(double wj, double x) {
        double r786 = wj;
        double r787 = x;
        double r788 = 2.0;
        double r789 = r787 * r788;
        double r790 = r786 - r789;
        double r791 = fma(r786, r790, r787);
        double r792 = r786 * r787;
        double r793 = -r788;
        double r794 = r793 + r788;
        double r795 = r792 * r794;
        double r796 = r791 + r795;
        return r796;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.9

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

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

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

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

    \[\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.3

    \[\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.3

    \[\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.3

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