Average Error: 13.8 → 2.1
Time: 40.5s
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 r6325292 = wj;
        double r6325293 = exp(r6325292);
        double r6325294 = r6325292 * r6325293;
        double r6325295 = x;
        double r6325296 = r6325294 - r6325295;
        double r6325297 = r6325293 + r6325294;
        double r6325298 = r6325296 / r6325297;
        double r6325299 = r6325292 - r6325298;
        return r6325299;
}

double f(double wj, double x) {
        double r6325300 = wj;
        double r6325301 = x;
        double r6325302 = fma(r6325300, r6325300, r6325301);
        double r6325303 = 2.0;
        double r6325304 = r6325300 * r6325301;
        double r6325305 = r6325303 * r6325304;
        double r6325306 = r6325302 - r6325305;
        return r6325306;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.8

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

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

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

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

Reproduce

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