Average Error: 13.9 → 0.9
Time: 1.2m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;(\left(\frac{wj - \frac{x}{e^{wj}}}{e^{wj} - \left(wj \cdot wj\right) \cdot e^{wj}}\right) \cdot \left(\left(-1\right) + (\frac{1}{3} \cdot wj + \frac{1}{2})_* \cdot \left(wj \cdot wj\right)\right) + wj)_* \le 2.608735788713234 \cdot 10^{-17}:\\ \;\;\;\;(wj \cdot wj + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.9
Target13.3
Herbie0.9
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (fma (/ (- wj (/ x (exp wj))) (- (exp wj) (* (* wj wj) (exp wj)))) (+ (- 1) (* (fma 1/3 wj 1/2) (* wj wj))) wj) < 2.608735788713234e-17

    1. Initial program 18.5

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

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

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

    if 2.608735788713234e-17 < (fma (/ (- wj (/ x (exp wj))) (- (exp wj) (* (* wj wj) (exp wj)))) (+ (- 1) (* (fma 1/3 wj 1/2) (* wj wj))) wj)

    1. Initial program 2.8

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

      \[\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 simplify0.6

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

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

Runtime

Time bar (total: 1.2m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' +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))))))