Average Error: 13.2 → 2.0
Time: 22.5s
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 r9581016 = wj;
        double r9581017 = exp(r9581016);
        double r9581018 = r9581016 * r9581017;
        double r9581019 = x;
        double r9581020 = r9581018 - r9581019;
        double r9581021 = r9581017 + r9581018;
        double r9581022 = r9581020 / r9581021;
        double r9581023 = r9581016 - r9581022;
        return r9581023;
}

double f(double wj, double x) {
        double r9581024 = x;
        double r9581025 = wj;
        double r9581026 = r9581024 * r9581025;
        double r9581027 = -2.0;
        double r9581028 = fma(r9581025, r9581025, r9581024);
        double r9581029 = fma(r9581026, r9581027, r9581028);
        return r9581029;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.2
Target12.6
Herbie2.0
\[wj - \left(\frac{wj}{wj + 1} - \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)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))