Average Error: 14.1 → 2.0
Time: 25.5s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\left(wj \cdot x\right) \cdot -2 + \mathsf{fma}\left(wj, wj, x\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\left(wj \cdot x\right) \cdot -2 + \mathsf{fma}\left(wj, wj, x\right)
double f(double wj, double x) {
        double r9781205 = wj;
        double r9781206 = exp(r9781205);
        double r9781207 = r9781205 * r9781206;
        double r9781208 = x;
        double r9781209 = r9781207 - r9781208;
        double r9781210 = r9781206 + r9781207;
        double r9781211 = r9781209 / r9781210;
        double r9781212 = r9781205 - r9781211;
        return r9781212;
}

double f(double wj, double x) {
        double r9781213 = wj;
        double r9781214 = x;
        double r9781215 = r9781213 * r9781214;
        double r9781216 = -2.0;
        double r9781217 = r9781215 * r9781216;
        double r9781218 = fma(r9781213, r9781213, r9781214);
        double r9781219 = r9781217 + r9781218;
        return r9781219;
}

Error

Bits error versus wj

Bits error versus x

Target

Original14.1
Target13.5
Herbie2.0
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Initial program 14.1

    \[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(wj, wj, x\right) + \left(x \cdot wj\right) \cdot -2}\]
  4. Final simplification2.0

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

Reproduce

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