Average Error: 13.8 → 0.3
Time: 21.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 1.5677861928767593 \cdot 10^{-05}:\\ \;\;\;\;\frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} + (\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_*\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{1 + wj} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.8
Target13.2
Herbie0.3
\[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 < 1.5677861928767593e-05

    1. Initial program 13.5

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

      \[\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. Applied associate--r-7.1

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

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

      \[\leadsto \color{blue}{\left(\left({wj}^{2} + {wj}^{4}\right) - {wj}^{3}\right)} + \frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]
    7. Simplified0.3

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

    if 1.5677861928767593e-05 < wj

    1. Initial program 28.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in28.6

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity28.6

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac28.6

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 1.5677861928767593 \cdot 10^{-05}:\\ \;\;\;\;\frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} + (\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_*\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{1 + wj} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Runtime

Time bar (total: 21.8s)Debug logProfile

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