Average Error: 13.2 → 2.0
Time: 56.1s
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 r7416021 = wj;
        double r7416022 = exp(r7416021);
        double r7416023 = r7416021 * r7416022;
        double r7416024 = x;
        double r7416025 = r7416023 - r7416024;
        double r7416026 = r7416022 + r7416023;
        double r7416027 = r7416025 / r7416026;
        double r7416028 = r7416021 - r7416027;
        return r7416028;
}

double f(double wj, double x) {
        double r7416029 = x;
        double r7416030 = wj;
        double r7416031 = r7416029 * r7416030;
        double r7416032 = -2.0;
        double r7416033 = fma(r7416030, r7416030, r7416029);
        double r7416034 = fma(r7416031, r7416032, r7416033);
        return r7416034;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.2

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
  2. Taylor expanded around 0 2.0

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

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

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

Reproduce

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