Average Error: 13.3 → 2.0
Time: 17.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 \le -3.360608489066791 \cdot 10^{-08}:\\ \;\;\;\;\frac{\frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} \cdot \frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} - wj \cdot wj}{\frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} - wj}\\ \mathbf{else}:\\ \;\;\;\;(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.3
Target12.7
Herbie2.0
\[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 < -3.360608489066791e-08

    1. Initial program 5.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified5.2

      \[\leadsto \color{blue}{\frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj}\]
    3. Using strategy rm
    4. Applied flip-+21.3

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

    if -3.360608489066791e-08 < wj

    1. Initial program 13.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Simplified13.5

      \[\leadsto \color{blue}{\frac{(\left(-wj\right) \cdot \left(e^{wj}\right) + x)_*}{(\left(e^{wj}\right) \cdot wj + \left(e^{wj}\right))_*} + wj}\]
    3. Taylor expanded around 0 1.6

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

      \[\leadsto \color{blue}{(wj \cdot \left((x \cdot -2 + wj)_*\right) + x)_*}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.0

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

Reproduce

herbie shell --seed 2019016 +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: 16.7s)Debug log

sample268.0ms

Algorithm
intervals
Results
526×(pre true 80)
266×(body exit 10240)
196×(body real 80)
28×(body real 320)
19×(body real 160)
17×(body real 640)

simplify145.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
145.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 15.3b

localize27.0ms

Local error

Found 4 expressions with local error:

4.3b
(+ (/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj))) wj)
0.8b
(/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj)))
0.0b
(fma (exp wj) wj (exp wj))
0.0b
(fma (- wj) (exp wj) x)

rewrite12.0ms

Algorithm
rewrite-expression-head
Rules
19×add-cube-cbrt
19×*-un-lft-identity
19×add-sqr-sqrt
18×times-frac
13×fma-def
add-exp-log
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
associate-/r*
div-inv
fma-udef
flip-+
div-exp
flip3-+
frac-2neg
clear-num
+-commutative
cbrt-undiv
Counts
4 → 74
Calls
4 calls:
Slowest
7.0ms
(+ (/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj))) wj)
3.0ms
(/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj)))
0.0ms
(fma (exp wj) wj (exp wj))
0.0ms
(fma (- wj) (exp wj) x)

series162.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
60.0ms
(/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj)))
52.0ms
(+ (/ (fma (- wj) (exp wj) x) (fma (exp wj) wj (exp wj))) wj)
27.0ms
(fma (- wj) (exp wj) x)
22.0ms
(fma (exp wj) wj (exp wj))

simplify1.5s

Counts
49 → 86
Calls
49 calls:
Slowest
216.0ms
(/ (* (* (fma (- wj) (exp wj) x) (fma (- wj) (exp wj) x)) (fma (- wj) (exp wj) x)) (* (* (fma (exp wj) wj (exp wj)) (fma (exp wj) wj (exp wj))) (fma (exp wj) wj (exp wj))))
90.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
68.0ms
(- (/ x (* (exp wj) wj)) (+ (/ x (* (exp wj) (pow wj 2))) 1))
62.0ms
(/ (* (cbrt (fma (- wj) (exp wj) x)) (cbrt (fma (- wj) (exp wj) x))) (* (cbrt (fma (exp wj) wj (exp wj))) (cbrt (fma (exp wj) wj (exp wj)))))
58.0ms
(- x (+ (pow wj 2) wj))

prune917.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.6b

localize8.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune23.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.6b

localize7.0ms

Local error

Found 4 expressions with local error:

5.1b
(fma (fma (- wj) (exp wj) x) (/ 1 (fma (exp wj) wj (exp wj))) wj)
0.0b
(/ 1 (fma (exp wj) wj (exp wj)))
0.0b
(fma (exp wj) wj (exp wj))
0.0b
(fma (- wj) (exp wj) x)

rewrite5.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
*-un-lft-identity
pow1
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-cbrt-cube
expm1-log1p-u
fma-udef
associate-/r*
inv-pow
pow-flip
div-inv
frac-2neg
clear-num
rec-exp
Counts
4 → 48
Calls
4 calls:
Slowest
3.0ms
(fma (- wj) (exp wj) x)
1.0ms
(/ 1 (fma (exp wj) wj (exp wj)))
0.0ms
(fma (fma (- wj) (exp wj) x) (/ 1 (fma (exp wj) wj (exp wj))) wj)
0.0ms
(fma (exp wj) wj (exp wj))

series126.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
49.0ms
(fma (fma (- wj) (exp wj) x) (/ 1 (fma (exp wj) wj (exp wj))) wj)
26.0ms
(fma (exp wj) wj (exp wj))
26.0ms
(fma (- wj) (exp wj) x)
25.0ms
(/ 1 (fma (exp wj) wj (exp wj)))

simplify480.0ms

Counts
16 → 60
Calls
16 calls:
Slowest
109.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
64.0ms
(- (+ (/ 1 (* (exp wj) (pow wj 3))) (/ 1 (* (exp wj) wj))) (/ 1 (* (exp wj) (pow wj 2))))
50.0ms
(- (+ (* 5/2 (pow wj 2)) 1) (* 2 wj))
45.0ms
(- (+ (/ 1 (* (exp wj) (pow wj 3))) (/ 1 (* (exp wj) wj))) (/ 1 (* (exp wj) (pow wj 2))))
42.0ms
(- (+ (/ x (* (exp wj) wj)) wj) 1)

prune615.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.6b

localize27.0ms

Local error

Found 4 expressions with local error:

5.1b
(fma (fma (- wj) (exp wj) x) (* (* (cbrt (/ 1 (fma (exp wj) wj (exp wj)))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) wj)
0.3b
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
0.3b
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
0.3b
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))

rewrite6.0ms

Algorithm
rewrite-expression-head
Rules
12×cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
div-inv
pow1/3
cbrt-div
fma-udef
Counts
4 → 55
Calls
4 calls:
Slowest
2.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
1.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
1.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
0.0ms
(fma (fma (- wj) (exp wj) x) (* (* (cbrt (/ 1 (fma (exp wj) wj (exp wj)))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) wj)

series204.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
61.0ms
(fma (fma (- wj) (exp wj) x) (* (* (cbrt (/ 1 (fma (exp wj) wj (exp wj)))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) (cbrt (/ 1 (fma (exp wj) wj (exp wj))))) wj)
60.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
43.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))
38.0ms
(cbrt (/ 1 (fma (exp wj) wj (exp wj))))

simplify2.9s

Counts
27 → 67
Calls
27 calls:
Slowest
424.0ms
(- (+ (* 7/18 (pow wj 2)) 1) (* 2/3 wj))
378.0ms
(- (+ (* 2/9 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) (pow wj 2))) (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj))))))) (* 1/3 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) wj)))
378.0ms
(- (+ (exp (* 1/3 (+ (log (/ -1 (exp wj))) (log (/ -1 wj))))) (* 2/9 (/ (exp (* 1/3 (+ (log (/ -1 (exp wj))) (log (/ -1 wj))))) (pow wj 2)))) (* 1/3 (/ (exp (* 1/3 (+ (log (/ -1 (exp wj))) (log (/ -1 wj))))) wj)))
365.0ms
(- (+ (* 2/9 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) (pow wj 2))) (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj))))))) (* 1/3 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) wj)))
350.0ms
(- (+ (* 2/9 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) (pow wj 2))) (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj))))))) (* 1/3 (/ (exp (* 1/3 (+ (log (/ 1 wj)) (log (/ 1 (exp wj)))))) wj)))

prune834.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.6b

regimes155.0ms

Accuracy

18.1% (1.5b remaining)

Error of 2.0b against oracle of 0.5b and baseline of 2.3b

bsearch79.0ms

end0.0ms

sample8.1s

Algorithm
intervals
Results
15721×(pre true 80)
7639×(body exit 10240)
6344×(body real 80)
731×(body real 320)
566×(body real 160)
441×(body real 640)