Average Error: 14.1 → 0.7
Time: 20.1s
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 3.959449308085633 \cdot 10^{-17}:\\ \;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(x \cdot wj\right)\\ \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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.1
Target13.3
Herbie0.7
\[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))))) < 3.959449308085633e-17

    1. Initial program 18.6

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

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

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

    1. Initial program 3.0

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

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

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

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

Reproduce

herbie shell --seed 2019021 
(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: 18.9s)Debug log

sample238.0ms

Algorithm
intervals
Results
181.0ms249×body10240exit
19.0ms186×body80valid
9.0ms29×body320valid
8.0ms19×body640valid
4.0ms23×body160valid

simplify115.0ms

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 16.3b

localize21.0ms

Local error

Found 4 expressions with local error:

5.9b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
0.8b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(+ (exp wj) (* wj (exp wj)))
0.0b
(* wj (exp wj))

rewrite22.0ms

Algorithm
rewrite-expression-head
Rules
20×*-un-lft-identity
15×add-cube-cbrt
15×times-frac
15×add-sqr-sqrt
add-log-exp
add-exp-log
add-cbrt-cube
distribute-rgt1-in
distribute-rgt-out
associate-/r*
pow1
associate-/l*
associate-*r*
associate-/l/
flip--
flip-+
associate-/r/
div-sub
flip3--
flip3-+
associate--r-
div-inv
*-commutative
div-exp
frac-2neg
sub-neg
sum-log
clear-num
+-commutative
cbrt-undiv
Counts
4 → 76
Calls
4 calls:
Slowest
15.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
5.0ms
(+ (exp wj) (* wj (exp wj)))
1.0ms
(* wj (exp wj))
0.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

series151.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
59.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
39.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
31.0ms
(+ (exp wj) (* wj (exp wj)))
22.0ms
(* wj (exp wj))

simplify3.2s

Counts
64 → 88
Calls
64 calls:
Slowest
778.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
679.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
143.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))
115.0ms
(- (* (* wj (exp wj)) (* wj (exp wj))) (* x x))
103.0ms
(/ (* (* (- (* wj (exp wj)) x) (- (* wj (exp wj)) x)) (- (* wj (exp wj)) x)) (* (* (+ (exp wj) (* wj (exp wj))) (+ (exp wj) (* wj (exp wj)))) (+ (exp wj) (* wj (exp wj)))))

prune770.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.6b

localize13.0ms

Local error

Found 3 expressions with local error:

0.0b
(* 2 (* x wj))
0.0b
(- (+ (pow wj 2) x) (* 2 (* x wj)))
0.0b
(+ (pow wj 2) x)

rewrite23.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
pow1
add-sqr-sqrt
flip--
flip-+
*-commutative
associate--l+
associate-*r*
diff-log
flip3--
flip3-+
sub-neg
+-commutative
Counts
3 → 32
Calls
3 calls:
Slowest
19.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
2.0ms
(+ (pow wj 2) x)
1.0ms
(* 2 (* x wj))

series39.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
15.0ms
(+ (pow wj 2) x)
14.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
11.0ms
(* 2 (* x wj))

simplify359.0ms

Counts
11 → 41
Calls
11 calls:
Slowest
147.0ms
(/ (exp (+ (pow wj 2) x)) (exp (* 2 (* x wj))))
79.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))
63.0ms
(- (+ (pow wj 2) x) (* 2 (* x wj)))
41.0ms
(- (+ x (pow wj 2)) (* 2 (* x wj)))
6.0ms
(* 2 (* x wj))

prune408.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.6b

localize18.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (+ (pow wj 2) x))
0.6b
(cbrt (+ (pow wj 2) x))
0.6b
(cbrt (+ (pow wj 2) x))
0.5b
(* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))

rewrite15.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
flip-+
flip3-+
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
add-cbrt-cube
frac-times
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 75
Calls
4 calls:
Slowest
9.0ms
(* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))
2.0ms
(cbrt (+ (pow wj 2) x))
2.0ms
(cbrt (+ (pow wj 2) x))
2.0ms
(cbrt (+ (pow wj 2) x))

series368.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
113.0ms
(cbrt (+ (pow wj 2) x))
94.0ms
(* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))
89.0ms
(cbrt (+ (pow wj 2) x))
72.0ms
(cbrt (+ (pow wj 2) x))

simplify1.7s

Counts
59 → 87
Calls
59 calls:
Slowest
154.0ms
(* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (+ (pow (pow wj 2) 3) (pow x 3))))
136.0ms
(* (cbrt (- (pow wj 2) x)) (cbrt (+ (* (pow wj 2) (pow wj 2)) (- (* x x) (* (pow wj 2) x)))))
120.0ms
(* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))
113.0ms
(* (cbrt (+ (* (pow wj 2) (pow wj 2)) (- (* x x) (* (pow wj 2) x)))) (cbrt (+ (* (pow wj 2) (pow wj 2)) (- (* x x) (* (pow wj 2) x)))))
108.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))

prune850.0ms

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.6b

localize13.0ms

Local error

Found 4 expressions with local error:

4.9b
(exp (log (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))))
0.6b
(cbrt (+ (pow wj 2) x))
0.6b
(cbrt (+ (pow wj 2) x))
0.6b
(cbrt (+ (pow wj 2) x))

rewrite26.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
10×exp-prod
10×pow1
flip-+
flip3-+
cbrt-prod
add-cube-cbrt
exp-diff
*-un-lft-identity
log-div
add-sqr-sqrt
log-pow
pow1/3
add-log-exp
add-exp-log
add-cbrt-cube
frac-times
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
rem-exp-log
exp-sum
pow-plus
log-prod
pow2
Counts
4 → 66
Calls
4 calls:
Slowest
19.0ms
(exp (log (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))))
3.0ms
(cbrt (+ (pow wj 2) x))
2.0ms
(cbrt (+ (pow wj 2) x))
2.0ms
(cbrt (+ (pow wj 2) x))

series369.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
105.0ms
(exp (log (* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))))
92.0ms
(cbrt (+ (pow wj 2) x))
88.0ms
(cbrt (+ (pow wj 2) x))
84.0ms
(cbrt (+ (pow wj 2) x))

simplify1.2s

Counts
47 → 78
Calls
47 calls:
Slowest
136.0ms
(exp (log (* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))))
118.0ms
(exp (log (* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (+ (pow wj 2) x)))))
114.0ms
(exp (log (* (cbrt (+ (pow (pow wj 2) 3) (pow x 3))) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))))
113.0ms
(exp (log (* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (+ (pow (pow wj 2) 3) (pow x 3))))))
96.0ms
(exp (log (* (cbrt (+ (pow wj 2) x)) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))))

prune890.0ms

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.6b

regimes281.0ms

Accuracy

77.7% (0.4b remaining)

Error of 0.7b against oracle of 0.3b and baseline of 2.2b

bsearch4.0ms

end0.0ms

sample7.8s

Algorithm
intervals
Results
6.5s7550×body10240exit
643.0ms6251×body80valid
236.0ms472×body640valid
235.0ms818×body320valid
120.0ms538×body160valid