Average Error: 13.8 → 2.1
Time: 16.4s
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 r89190 = wj;
        double r89191 = exp(r89190);
        double r89192 = r89190 * r89191;
        double r89193 = x;
        double r89194 = r89192 - r89193;
        double r89195 = r89191 + r89192;
        double r89196 = r89194 / r89195;
        double r89197 = r89190 - r89196;
        return r89197;
}

double f(double wj, double x) {
        double r89198 = wj;
        double r89199 = x;
        double r89200 = fma(r89198, r89198, r89199);
        double r89201 = 2.0;
        double r89202 = r89198 * r89199;
        double r89203 = r89201 * r89202;
        double r89204 = r89200 - r89203;
        return r89204;
}

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. Simplified13.2

    \[\leadsto \color{blue}{wj - \frac{\frac{wj}{1} - \frac{x}{e^{wj}}}{wj + 1}}\]
  3. Taylor expanded around 0 2.1

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

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

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

Reproduce

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