Average Error: 13.9 → 1.5
Time: 24.6s
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 5.982744081820541 \cdot 10^{-09}:\\ \;\;\;\;(\left(x \cdot 2\right) \cdot \left(-wj\right) + \left((wj \cdot wj + x)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;(\left((\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*\right) \cdot \left(\log_* (1 + (e^{\frac{1}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}} - 1)^*)\right) + wj)_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.9
Target13.4
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 < 5.982744081820541e-09

    1. Initial program 13.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Initial simplification13.6

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

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

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

    if 5.982744081820541e-09 < wj

    1. Initial program 23.3

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Initial simplification23.3

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

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

      \[\leadsto \color{blue}{(\left((\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*\right) \cdot \left(\frac{1}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}\right) + wj)_*}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u23.4

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

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

Runtime

Time bar (total: 24.6s)Debug logProfile

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