Average Error: 13.4 → 2.2
Time: 19.7s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)
double f(double wj, double x) {
        double r177871 = wj;
        double r177872 = exp(r177871);
        double r177873 = r177871 * r177872;
        double r177874 = x;
        double r177875 = r177873 - r177874;
        double r177876 = r177872 + r177873;
        double r177877 = r177875 / r177876;
        double r177878 = r177871 - r177877;
        return r177878;
}

double f(double wj, double x) {
        double r177879 = wj;
        double r177880 = x;
        double r177881 = fma(r177879, r177879, r177880);
        double r177882 = 2.0;
        double r177883 = r177879 * r177880;
        double r177884 = r177882 * r177883;
        double r177885 = r177881 - r177884;
        return r177885;
}

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}{wj - \frac{\frac{wj}{1} - \frac{x}{e^{wj}}}{wj + 1}}\]
  3. Taylor expanded around 0 2.2

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

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

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

Reproduce

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