Average Error: 13.6 → 0.5
Time: 1.2m
Precision: 64
Internal Precision: 896
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;e^{\log \left(wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \le 3.362279932287092 \cdot 10^{-19}:\\ \;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;wj + \left(\frac{x}{\left(wj + 1\right) \cdot e^{wj}} - \frac{wj}{wj + 1}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.6
Target13.0
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 (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))) < 3.362279932287092e-19

    1. Initial program 38.1

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

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

    if 3.362279932287092e-19 < (exp (log (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))))

    1. Initial program 1.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied sub-neg1.5

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

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

Runtime

Time bar (total: 1.2m)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' 
(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))))))