Average Error: 13.6 → 0.7
Time: 1.5m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 2.2227895358128606 \cdot 10^{-18}:\\ \;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \left(\frac{\frac{x}{e^{wj}}}{wj + 1} - \frac{wj}{wj + 1}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original13.6
Target13.0
Herbie0.7
\[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 (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))) < 2.2227895358128606e-18

    1. Initial program 18.1

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

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

    if 2.2227895358128606e-18 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 2.7

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

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

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

Runtime

Time bar (total: 1.5m)Debug logProfile

herbie shell --seed 2018206 
(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))))))