Average Error: 14.1 → 0.8
Time: 27.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 8.36959831267844 \cdot 10^{-18}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \mathbf{else}:\\ \;\;\;\;wj - \left(\frac{wj}{1 + wj} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original14.1
Target13.5
Herbie0.8
\[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))))) < 8.36959831267844e-18

    1. Initial program 18.6

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

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

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

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

    1. Initial program 2.6

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

      \[\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.5

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

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

Reproduce

herbie shell --seed 2018362 +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.9s)Debug log

start332.0ms

Algorithm
intervals

setup177.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 16.2b

localize18.0ms

Local error

Found 4 expressions with local error:

6.8b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
1.0b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(+ (exp wj) (* wj (exp wj)))
0.0b
(* wj (exp wj))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 87
Calls

4 calls. Slowest were:

11.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
5.0ms
(+ (exp wj) (* wj (exp wj)))
1.0ms
(* wj (exp wj))

series180.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

65.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
56.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
32.0ms
(+ (exp wj) (* wj (exp wj)))
27.0ms
(* wj (exp wj))

simplify3.4s

Counts
66 → 99
Calls

66 calls. Slowest were:

615.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
442.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
318.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))

prune1.1s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.4b

localize16.0ms

Local error

Found 1 expressions with local error:

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

rewrite1.0ms

Algorithm
rewrite-expression-head
Counts
1 → 10
Calls

1 calls. Slowest were:

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

series24.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

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

simplify338.0ms

Counts
3 → 13
Calls

3 calls. Slowest were:

121.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))
116.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))
100.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))

prune148.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 0.4b

localize18.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)))

rewrite14.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)))
1.0ms
(cbrt (fma wj (fma x -2 wj) x))
1.0ms
(cbrt (fma wj (fma x -2 wj) x))

series570.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

158.0ms
(* (cbrt (fma wj (fma x -2 wj) x)) (cbrt (fma wj (fma x -2 wj) x)))
145.0ms
(cbrt (fma wj (fma x -2 wj) x))
136.0ms
(cbrt (fma wj (fma x -2 wj) x))
131.0ms
(cbrt (fma wj (fma x -2 wj) x))

simplify2.3s

Counts
41 → 81
Calls

41 calls. Slowest were:

640.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
362.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
319.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))

prune906.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.4b

localize19.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))

rewrite5.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))

series635.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

174.0ms
(cbrt (fma wj (fma x -2 wj) x))
164.0ms
(cbrt (fma wj (fma x -2 wj) x))
153.0ms
(cbrt (fma wj (fma x -2 wj) x))
143.0ms
(cbrt (fma wj (fma x -2 wj) x))

simplify1.5s

Counts
24 → 64
Calls

24 calls. Slowest were:

321.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
315.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))
285.0ms
(- (pow x 1/3) (+ (* 4/9 (* (pow x 1/3) (pow wj 2))) (* 2/3 (* (pow x 1/3) wj))))

prune927.0ms

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 0.4b

regimes226.0ms

Accuracy

73.9% (0.5b remaining)

Error of 0.8b against oracle of 0.3b and baseline of 2.1b

bsearch7.0ms