Average Error: 13.5 → 0.2
Time: 1.2m
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 4.5497853715898254 \cdot 10^{-12}:\\ \;\;\;\;\frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} + \left(\left(wj \cdot wj\right) \cdot \left(1 - wj\right) + {wj}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(wj - \frac{wj}{1 + wj}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.5
Target12.9
Herbie0.2
\[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))))) < 4.5497853715898254e-12

    1. Initial program 17.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied div-sub17.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-9.8

      \[\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. Applied simplify9.8

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

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

      \[\leadsto \color{blue}{\frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*} + (\left(wj \cdot wj\right) \cdot \left(1 - wj\right) + \left({wj}^{4}\right))_*}\]
    8. Using strategy rm
    9. Applied fma-udef0.2

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

    if 4.5497853715898254e-12 < (- 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 div-sub2.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-2.7

      \[\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. Applied simplify0.2

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

Runtime

Time bar (total: 1.2m)Debug logProfile

herbie shell --seed '#(1072967564 1937075727 894099792 790700740 1036514779 1027793188)' +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))))))