Average Error: 13.5 → 0.3
Time: 52.4s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj \le 3.366079653129577 \cdot 10^{-06}:\\ \;\;\;\;(\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_* - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \mathbf{else}:\\ \;\;\;\;(\left(\frac{1}{1 + wj}\right) \cdot \left(\frac{x}{e^{wj}}\right) + \left(wj - \frac{wj}{1 + wj}\right))_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target12.9
Herbie0.3
\[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 < 3.366079653129577e-06

    1. Initial program 13.1

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

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

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

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified13.2

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

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

      \[\leadsto wj - \color{blue}{\left(wj \cdot \frac{1}{wj + 1} + \left(-\frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}\right)}\]
    10. Applied associate--r+6.9

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

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

      \[\leadsto \color{blue}{\left(\left({wj}^{2} + {wj}^{4}\right) - {wj}^{3}\right)} - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]
    13. Simplified0.3

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

    if 3.366079653129577e-06 < wj

    1. Initial program 28.7

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

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity28.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-frac28.7

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

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

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj + \left(-\frac{x}{e^{wj}}\right)\right)}\]
    9. Applied distribute-rgt-in1.4

      \[\leadsto wj - \color{blue}{\left(wj \cdot \frac{1}{wj + 1} + \left(-\frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}\right)}\]
    10. Applied associate--r+1.4

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

      \[\leadsto \left(wj - wj \cdot \frac{1}{wj + 1}\right) - \color{blue}{\frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
    12. Using strategy rm
    13. Applied div-inv1.4

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

      \[\leadsto \color{blue}{1 \cdot \left(wj - wj \cdot \frac{1}{wj + 1}\right)} - \left(-x\right) \cdot \frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]
    15. Applied prod-diff1.4

      \[\leadsto \color{blue}{(1 \cdot \left(wj - wj \cdot \frac{1}{wj + 1}\right) + \left(-\frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} \cdot \left(-x\right)\right))_* + (\left(-\frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\right) \cdot \left(-x\right) + \left(\frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} \cdot \left(-x\right)\right))_*}\]
    16. Simplified1.4

      \[\leadsto \color{blue}{(\left(\frac{1}{wj + 1}\right) \cdot \left(\frac{x}{e^{wj}}\right) + \left(wj - \frac{wj}{wj + 1}\right))_*} + (\left(-\frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\right) \cdot \left(-x\right) + \left(\frac{1}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} \cdot \left(-x\right)\right))_*\]
    17. Simplified1.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj \le 3.366079653129577 \cdot 10^{-06}:\\ \;\;\;\;(\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_* - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \mathbf{else}:\\ \;\;\;\;(\left(\frac{1}{1 + wj}\right) \cdot \left(\frac{x}{e^{wj}}\right) + \left(wj - \frac{wj}{1 + wj}\right))_*\\ \end{array}\]

Runtime

Time bar (total: 52.4s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes1.00.30.01.075.9%
herbie shell --seed 2018297 +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))))))