Average Error: 14.2 → 0.8
Time: 57.6s
Precision: 64
Internal Precision: 128
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 1.719945733550579 \cdot 10^{-10}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - (\left(\frac{wj}{1 + {wj}^{3}}\right) \cdot \left(\left(wj \cdot wj - wj\right) + 1\right) + \left(x \cdot \frac{-1}{e^{wj} + wj \cdot e^{wj}}\right))_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original14.2
Target13.7
Herbie0.8
\[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 (exp wj)) x) (+ (exp wj) (* wj (exp wj)))) < 1.719945733550579e-10

    1. Initial program 18.8

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

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

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

    if 1.719945733550579e-10 < (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))

    1. Initial program 2.2

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

      \[\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. Simplified0.3

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

      \[\leadsto wj - \left(\frac{wj}{1 + wj} - \color{blue}{x \cdot \frac{1}{e^{wj} + wj \cdot e^{wj}}}\right)\]
    7. Applied flip3-+0.3

      \[\leadsto wj - \left(\frac{wj}{\color{blue}{\frac{{1}^{3} + {wj}^{3}}{1 \cdot 1 + \left(wj \cdot wj - 1 \cdot wj\right)}}} - x \cdot \frac{1}{e^{wj} + wj \cdot e^{wj}}\right)\]
    8. Applied associate-/r/0.3

      \[\leadsto wj - \left(\color{blue}{\frac{wj}{{1}^{3} + {wj}^{3}} \cdot \left(1 \cdot 1 + \left(wj \cdot wj - 1 \cdot wj\right)\right)} - x \cdot \frac{1}{e^{wj} + wj \cdot e^{wj}}\right)\]
    9. Applied prod-diff0.3

      \[\leadsto wj - \color{blue}{\left((\left(\frac{wj}{{1}^{3} + {wj}^{3}}\right) \cdot \left(1 \cdot 1 + \left(wj \cdot wj - 1 \cdot wj\right)\right) + \left(-\frac{1}{e^{wj} + wj \cdot e^{wj}} \cdot x\right))_* + (\left(-\frac{1}{e^{wj} + wj \cdot e^{wj}}\right) \cdot x + \left(\frac{1}{e^{wj} + wj \cdot e^{wj}} \cdot x\right))_*\right)}\]
    10. Applied associate--r+0.3

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

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

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

Runtime

Time bar (total: 57.6s)Debug logProfile

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