Average Error: 14.0 → 1.2
Time: 1.0m
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 -6.120139512610608 \cdot 10^{-09}:\\ \;\;\;\;\frac{wj \cdot wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} \cdot \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}{wj + \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\\ \mathbf{if}\;wj \le 1.4918198301414643 \cdot 10^{-11}:\\ \;\;\;\;(wj \cdot wj + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{\frac{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original14.0
Target13.4
Herbie1.2
\[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 < -6.120139512610608e-09

    1. Initial program 3.9

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied simplify3.9

      \[\leadsto \color{blue}{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
    3. Using strategy rm
    4. Applied flip--19.0

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

    if -6.120139512610608e-09 < wj < 1.4918198301414643e-11

    1. Initial program 13.9

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied simplify13.9

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

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

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

    if 1.4918198301414643e-11 < wj

    1. Initial program 22.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied simplify22.5

      \[\leadsto \color{blue}{wj - \frac{(\left(e^{wj}\right) \cdot wj + \left(-x\right))_*}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
    3. Using strategy rm
    4. Applied clear-num22.6

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

Runtime

Time bar (total: 1.0m)Debug logProfile

herbie shell --seed '#(1072840222 1305617769 1692503039 1353360431 4178980589 1488672652)' +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))))))