Average Error: 13.5 → 1.5
Time: 36.5s
Precision: 64
Internal Precision: 128
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le -8.76421065063732 \cdot 10^{-09}:\\ \;\;\;\;wj - \frac{e^{wj} \cdot wj - x}{(\left(\sqrt{e^{wj}}\right) \cdot \left(\sqrt{e^{wj}}\right) + \left(e^{wj} \cdot wj\right))_*}\\ \mathbf{else}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target12.9
Herbie1.5
\[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 < -8.76421065063732e-09

    1. Initial program 4.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt4.8

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\sqrt{e^{wj}} \cdot \sqrt{e^{wj}}} + wj \cdot e^{wj}}\]
    4. Applied fma-def4.8

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

    if -8.76421065063732e-09 < wj

    1. Initial program 13.7

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

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

      \[\leadsto \color{blue}{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.5

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

Runtime

Time bar (total: 36.5s)Debug logProfile

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