Average Error: 14.0 → 0.1
Time: 1.1m
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;e^{\log \left(wj - \frac{e^{wj} \cdot wj - x}{e^{wj} + e^{wj} \cdot wj}\right)} \le 1.1060540041510762 \cdot 10^{-13}:\\ \;\;\;\;\left(\left({wj}^{2} + {wj}^{4}\right) - {wj}^{3}\right) + \frac{x}{\left(1 + wj\right) \cdot e^{wj}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(1 + wj\right) \cdot e^{wj}} + \left(wj - \frac{wj}{1 + wj}\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

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

Derivation

  1. Split input into 2 regimes
  2. if (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))) < 1.1060540041510762e-13

    1. Initial program 38.7

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

      \[\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 associate--r-20.2

      \[\leadsto \color{blue}{\left(wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}}\]
    5. Simplified20.2

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

      \[\leadsto \color{blue}{\left(\left({wj}^{4} + {wj}^{2}\right) - {wj}^{3}\right)} + \frac{x}{e^{wj} \cdot \left(1 + wj\right)}\]

    if 1.1060540041510762e-13 < (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))))

    1. Initial program 1.6

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

      \[\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 associate--r-1.2

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

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

      \[\leadsto \left(wj - \frac{wj \cdot e^{wj}}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\right) + \frac{x}{e^{wj} \cdot \left(1 + wj\right)}\]
    8. Applied times-frac1.2

      \[\leadsto \left(wj - \color{blue}{\frac{wj}{wj + 1} \cdot \frac{e^{wj}}{e^{wj}}}\right) + \frac{x}{e^{wj} \cdot \left(1 + wj\right)}\]
    9. Simplified0.2

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

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

Runtime

Time bar (total: 1.1m)Debug logProfile

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