Average Error: 13.6 → 0.6
Time: 26.9s
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 2.5232382752585948 \cdot 10^{-17}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \frac{1}{1 + wj} \cdot \left(wj - \frac{x}{e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.6
Target12.9
Herbie0.6
\[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))))) < 2.5232382752585948e-17

    1. Initial program 17.8

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

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

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

    if 2.5232382752585948e-17 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 2.8

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in2.8

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity2.8

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac2.8

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified0.6

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

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

Reproduce

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

Details

Time bar (total: 12.4s)Debug log

start468.0ms

Algorithm
intervals

setup159.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 14.0b

localize15.0ms

Local error

Found 4 expressions with local error:

5.5b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
0.5b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(* wj (exp wj))
0.0b
(* wj (exp wj))

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 82
Calls

4 calls. Slowest were:

9.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
1.0ms
(* wj (exp wj))
1.0ms
(* wj (exp wj))

series165.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
51.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
28.0ms
(* wj (exp wj))
27.0ms
(* wj (exp wj))

simplify3.4s

Counts
63 → 94
Calls

63 calls. Slowest were:

676.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
393.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))
321.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))

prune1.3s

Pruning

5 alts after pruning (5 fresh and 0 done)

Merged error: 0.6b

localize7.0ms

Local error

Found 1 expressions with local error:

0.2b
(fma wj (fma x -2 wj) x)

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
1 → 10
Calls

1 calls. Slowest were:

0.0ms
(fma wj (fma x -2 wj) x)

series16.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

16.0ms
(fma wj (fma x -2 wj) x)

simplify295.0ms

Counts
3 → 13
Calls

3 calls. Slowest were:

122.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
97.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))
75.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))

prune191.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 0.6b

localize17.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.5b
(* (cbrt (fma wj (fma x -2 wj) x)) (cbrt (fma wj (fma x -2 wj) x)))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

10.0ms
(* (cbrt (fma wj (fma x -2 wj) x)) (cbrt (fma wj (fma x -2 wj) x)))
2.0ms
(cbrt (fma wj (fma x -2 wj) x))
1.0ms
(cbrt (fma wj (fma x -2 wj) x))

series633.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

184.0ms
(cbrt (fma wj (fma x -2 wj) x))
164.0ms
(* (cbrt (fma wj (fma x -2 wj) x)) (cbrt (fma wj (fma x -2 wj) x)))
158.0ms
(cbrt (fma wj (fma x -2 wj) x))
127.0ms
(cbrt (fma wj (fma x -2 wj) x))

simplify1.7s

Counts
41 → 81
Calls

41 calls. Slowest were:

264.0ms
(- (pow x 2/3) (+ (* 4/9 (* (pow (pow x 2) 1/3) (pow wj 2))) (* 4/3 (* (pow (pow x 2) 1/3) wj))))
263.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
255.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))

prune951.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.6b

localize16.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.6b
(cbrt (fma wj (fma x -2 wj) x))
0.6b
(cbrt (fma wj (fma x -2 wj) x))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
4 → 52
Calls

4 calls. Slowest were:

1.0ms
(cbrt (fma wj (fma x -2 wj) x))
1.0ms
(cbrt (fma wj (fma x -2 wj) x))
1.0ms
(cbrt (fma wj (fma x -2 wj) x))

series592.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

165.0ms
(cbrt (fma wj (fma x -2 wj) x))
162.0ms
(cbrt (fma wj (fma x -2 wj) x))
138.0ms
(cbrt (fma wj (fma x -2 wj) x))
127.0ms
(cbrt (fma wj (fma x -2 wj) x))

simplify1.3s

Counts
24 → 64
Calls

24 calls. Slowest were:

307.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
268.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
253.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))

prune878.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.6b

regimes256.0ms

Accuracy

80.2% (0.3b remaining)

Error of 0.6b against oracle of 0.3b and baseline of 2.0b

bsearch7.0ms