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

Error

Bits error versus wj

Bits error versus x

Target

Original13.7
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 < 4.713924537321262e-08

    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. Simplified13.5

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

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

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

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

      \[\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))_*}\]
    10. Simplified0.2

      \[\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 4.713924537321262e-08 < wj

    1. Initial program 23.9

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

      \[\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. Simplified1.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 4.713924537321262 \cdot 10^{-08}:\\ \;\;\;\;(\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))_*}\\ \mathbf{else}:\\ \;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \end{array}\]

Runtime

Time bar (total: 37.8s)Debug logProfile

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