Average Error: 13.4 → 1.2
Time: 55.4s
Precision: 64
Internal Precision: 832
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;\left(\sqrt[3]{{wj}^{2} + x} \cdot \sqrt[3]{{wj}^{2} + x}\right) \cdot \left(\sqrt[3]{\sqrt{{wj}^{2} + x}} \cdot \sqrt[3]{\sqrt{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le 3.15013478012448 \cdot 10^{-18}:\\ \;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\ \mathbf{if}\;\left(\sqrt[3]{{wj}^{2} + x} \cdot \sqrt[3]{{wj}^{2} + x}\right) \cdot \left(\sqrt[3]{\sqrt{{wj}^{2} + x}} \cdot \sqrt[3]{\sqrt{{wj}^{2} + x}}\right) - 2 \cdot \left(wj \cdot x\right) \le 1.0763031702691529 \cdot 10^{+28}:\\ \;\;\;\;wj - \frac{1}{\frac{wj + 1}{wj - \frac{x}{e^{wj}}}}\\ \mathbf{else}:\\ \;\;\;\;\left({wj}^{2} + x\right) - 2 \cdot \left(wj \cdot x\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.4
Target12.9
Herbie1.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 (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < 3.15013478012448e-18 or 1.0763031702691529e+28 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x)))

    1. Initial program 13.8

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

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

    if 3.15013478012448e-18 < (- (* (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x))) (* (cbrt (sqrt (+ (pow wj 2) x))) (cbrt (sqrt (+ (pow wj 2) x))))) (* 2 (* wj x))) < 1.0763031702691529e+28

    1. Initial program 7.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied clear-num7.6

      \[\leadsto wj - \color{blue}{\frac{1}{\frac{e^{wj} + wj \cdot e^{wj}}{wj \cdot e^{wj} - x}}}\]
    4. Applied simplify2.5

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

Runtime

Time bar (total: 55.4s)Debug logProfile

herbie shell --seed '#(1072330854 3074818769 591214268 3603999196 3863745332 3332387116)' 
(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))))))