Average Error: 13.5 → 0.5
Time: 22.0s
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj - \log \left(e^{\frac{1}{wj + 1}}\right) \cdot \left(wj - \frac{x}{e^{wj}}\right) \le 7.565976676171613 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{e^{wj}} - \left(wj - \frac{x}{e^{wj}}\right) \cdot \left(wj \cdot wj - wj\right)\\ \mathbf{else}:\\ \;\;\;\;wj - \log \left(e^{\frac{1}{wj + 1}}\right) \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target12.9
Herbie0.5
\[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 (* (log (exp (/ 1 (+ wj 1)))) (- wj (/ x (exp wj))))) < 7.565976676171613e-13

    1. Initial program 17.7

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

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity17.8

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

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Applied simplify17.7

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj - \frac{x}{e^{wj}}\right)}\]
    7. Using strategy rm
    8. Applied add-log-exp17.8

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

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

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

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

    1. Initial program 2.6

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

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity2.6

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

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Applied simplify0.4

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

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

Runtime

Time bar (total: 22.0s)Debug logProfile

herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)' +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))))))