Average Error: 13.5 → 2.1
Time: 28.6s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\mathsf{fma}\left(wj, wj, x\right) - x \cdot \left(2 \cdot wj\right)\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\mathsf{fma}\left(wj, wj, x\right) - x \cdot \left(2 \cdot wj\right)
double f(double wj, double x) {
        double r8350973 = wj;
        double r8350974 = exp(r8350973);
        double r8350975 = r8350973 * r8350974;
        double r8350976 = x;
        double r8350977 = r8350975 - r8350976;
        double r8350978 = r8350974 + r8350975;
        double r8350979 = r8350977 / r8350978;
        double r8350980 = r8350973 - r8350979;
        return r8350980;
}

double f(double wj, double x) {
        double r8350981 = wj;
        double r8350982 = x;
        double r8350983 = fma(r8350981, r8350981, r8350982);
        double r8350984 = 2.0;
        double r8350985 = r8350984 * r8350981;
        double r8350986 = r8350982 * r8350985;
        double r8350987 = r8350983 - r8350986;
        return r8350987;
}

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Initial program 13.5

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

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

Reproduce

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