Average Error: 13.7 → 1.0
Time: 6.4s
Precision: 64
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le 7.575706194898737323694237493331283921083 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{wj + 1}}{e^{wj}} + \left(wj - \frac{wj}{wj + 1}\right)\\ \end{array}\]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\begin{array}{l}
\mathbf{if}\;wj \le 7.575706194898737323694237493331283921083 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{wj + 1}}{e^{wj}} + \left(wj - \frac{wj}{wj + 1}\right)\\

\end{array}
double f(double wj, double x) {
        double r279994 = wj;
        double r279995 = exp(r279994);
        double r279996 = r279994 * r279995;
        double r279997 = x;
        double r279998 = r279996 - r279997;
        double r279999 = r279995 + r279996;
        double r280000 = r279998 / r279999;
        double r280001 = r279994 - r280000;
        return r280001;
}

double f(double wj, double x) {
        double r280002 = wj;
        double r280003 = 7.575706194898737e-11;
        bool r280004 = r280002 <= r280003;
        double r280005 = x;
        double r280006 = fma(r280002, r280002, r280005);
        double r280007 = 2.0;
        double r280008 = r280002 * r280005;
        double r280009 = r280007 * r280008;
        double r280010 = r280006 - r280009;
        double r280011 = 1.0;
        double r280012 = r280002 + r280011;
        double r280013 = r280005 / r280012;
        double r280014 = exp(r280002);
        double r280015 = r280013 / r280014;
        double r280016 = r280002 / r280012;
        double r280017 = r280002 - r280016;
        double r280018 = r280015 + r280017;
        double r280019 = r280004 ? r280010 : r280018;
        return r280019;
}

Error

Bits error versus wj

Bits error versus x

Target

Original13.7
Target13.1
Herbie1.0
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if wj < 7.575706194898737e-11

    1. Initial program 13.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified13.4

      \[\leadsto \color{blue}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1}}\]
    3. Taylor expanded around 0 0.9

      \[\leadsto \color{blue}{\left(x + {wj}^{2}\right) - 2 \cdot \left(wj \cdot x\right)}\]
    4. Taylor expanded around 0 0.9

      \[\leadsto \color{blue}{\left(x + {wj}^{2}\right)} - 2 \cdot \left(wj \cdot x\right)\]
    5. Simplified0.9

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

    if 7.575706194898737e-11 < wj

    1. Initial program 25.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified4.0

      \[\leadsto \color{blue}{\left(\frac{\frac{x}{wj + 1}}{e^{wj}} + wj\right) - \frac{wj}{wj + 1}}\]
    3. Using strategy rm
    4. Applied associate--l+3.9

      \[\leadsto \color{blue}{\frac{\frac{x}{wj + 1}}{e^{wj}} + \left(wj - \frac{wj}{wj + 1}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 7.575706194898737323694237493331283921083 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(wj, wj, x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{wj + 1}}{e^{wj}} + \left(wj - \frac{wj}{wj + 1}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 +o rules:numerics
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"
  :precision binary64

  :herbie-target
  (- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))

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