Average Error: 31.5 → 0.2
Time: 10.3s
Precision: 64
Internal precision: 896
\[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 1.6280626156164055 \cdot 10^{-12}:\\ \;\;\;\;\left({wj}^2 + x\right) - 2 \cdot \left(wj \cdot x\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

Original31.5
Comparison13.1
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))))) < 1.6280626156164055e-12

    1. Initial program 24.6

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Applied taylor 0.0

      \[\leadsto \left({wj}^2 + x\right) - 2 \cdot \left(wj \cdot x\right)\]
    3. Taylor expanded around 0 0.0

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

    if 1.6280626156164055e-12 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 39.1

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

      \[\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- 39.1

      \[\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 simplify 0.4

      \[\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.
  4. Removed slow pow expressions

Runtime

Time bar (total: 10.3s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"

  :target
  (- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))