Average Error: 14.1 → 0.4
Time: 32.8s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le -3.6456389569550817 \cdot 10^{-09}:\\ \;\;\;\;wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + \log \left(e^{e^{wj} \cdot wj}\right)}\right)\\ \mathbf{elif}\;wj \le 8.693438469307387 \cdot 10^{-09}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + e^{wj} \cdot wj}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if wj < -3.6456389569550817e-09

    1. Initial program 4.3

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied div-sub4.3

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

      \[\leadsto wj - \left(\color{blue}{\frac{wj}{1 + wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]
    5. Using strategy rm
    6. Applied add-log-exp8.6

      \[\leadsto wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + \color{blue}{\log \left(e^{wj \cdot e^{wj}}\right)}}\right)\]

    if -3.6456389569550817e-09 < wj < 8.693438469307387e-09

    1. Initial program 13.9

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

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

      \[\leadsto \color{blue}{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*}\]

    if 8.693438469307387e-09 < wj

    1. Initial program 27.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied div-sub27.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le -3.6456389569550817 \cdot 10^{-09}:\\ \;\;\;\;wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + \log \left(e^{e^{wj} \cdot wj}\right)}\right)\\ \mathbf{elif}\;wj \le 8.693438469307387 \cdot 10^{-09}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + e^{wj} \cdot wj}\right)\\ \end{array}\]

Runtime

Time bar (total: 32.8s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes2.10.40.31.893.2%
herbie shell --seed 2018339 +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))))))