Average Error: 13.4 → 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}\;\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) \le 6.850226452164976 \cdot 10^{-10}:\\ \;\;\;\;\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(\sqrt[3]{wj - \frac{wj}{1 + wj}} \cdot \sqrt[3]{wj - \frac{wj}{1 + wj}}\right) \cdot \sqrt[3]{wj - \frac{wj}{1 + wj}} + \frac{x}{e^{wj} + wj \cdot e^{wj}}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.4
Target12.8
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 (+ (/ x (fma wj (exp wj) (exp wj))) (+ (* (* wj wj) (- 1 wj)) (pow wj 4))) < 6.850226452164976e-10

    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.3

      \[\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.3

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

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

      \[\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.0

      \[\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 6.850226452164976e-10 < (+ (/ x (fma wj (exp wj) (exp wj))) (+ (* (* wj wj) (- 1 wj)) (pow wj 4)))

    1. Initial program 2.4

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

      \[\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.4

      \[\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.3

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

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

Runtime

Time bar (total: 1.1m)Debug logProfile

herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)' +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))))))