Average Error: 13.8 → 0.4
Time: 55.1s
Precision: 64
Internal Precision: 128
\[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 -7.888296966995117:\\ \;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\\ \mathbf{elif}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 6.214893319422228 \cdot 10^{-18}:\\ \;\;\;\;\log_* (1 + (e^{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*} - 1)^*)\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.8
Target13.1
Herbie0.4
\[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))))) < -7.888296966995117 or 6.214893319422228e-18 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 1.7

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

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

    if -7.888296966995117 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))) < 6.214893319422228e-18

    1. Initial program 28.2

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Taylor expanded around 0 0.4

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

      \[\leadsto \color{blue}{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*}\]
    4. Using strategy rm
    5. Applied log1p-expm1-u0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le -7.888296966995117:\\ \;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\\ \mathbf{elif}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 6.214893319422228 \cdot 10^{-18}:\\ \;\;\;\;\log_* (1 + (e^{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*} - 1)^*)\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\\ \end{array}\]

Runtime

Time bar (total: 55.1s)Debug logProfile

herbie shell --seed 2018349 +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))))))