Average Error: 13.7 → 1.4
Time: 15.3s
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;(wj \cdot wj + x)_* \le 3.0497598146818108 \cdot 10^{-34}:\\ \;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{(wj \cdot \left(e^{wj}\right) + \left(-x\right))_*}{(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.1
Herbie1.4
\[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 wj x) < 3.0497598146818108e-34

    1. Initial program 18.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied simplify18.4

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

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

    if 3.0497598146818108e-34 < (fma wj wj x)

    1. Initial program 3.2

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied simplify3.2

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

Runtime

Time bar (total: 15.3s)Debug logProfile

herbie shell --seed '#(1070100504 930361288 1279167582 284574201 1450237281 2578255382)' +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))))))