Average Error: 13.3 → 0.4
Time: 20.5s
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 -4.312359683013498 \cdot 10^{-09} \lor \neg \left(wj \le 5.2518683439657065 \cdot 10^{-09}\right):\\ \;\;\;\;wj - \frac{wj - \frac{x}{e^{wj}}}{1 + wj}\\ \mathbf{else}:\\ \;\;\;\;\left(x + {wj}^{2}\right) - 2 \cdot \left(x \cdot 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

Original13.3
Target12.7
Herbie0.4
\[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 < -4.312359683013498e-09 or 5.2518683439657065e-09 < wj

    1. Initial program 17.4

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity17.4

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

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

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

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

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

    if -4.312359683013498e-09 < wj < 5.2518683439657065e-09

    1. Initial program 13.1

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

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

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

Reproduce

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

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

simplify154.0ms

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

prune14.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 15.3b

localize34.0ms

Local error

Found 4 expressions with local error:

4.3b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
0.7b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(+ (exp wj) (* wj (exp wj)))
0.0b
(* wj (exp wj))

rewrite20.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
13.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
3.0ms
(+ (exp wj) (* wj (exp wj)))
1.0ms
(* wj (exp wj))
1.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

series158.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
58.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
46.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
28.0ms
(* wj (exp wj))
26.0ms
(+ (exp wj) (* wj (exp wj)))

simplify3.5s

Counts
64 → 88
Calls
64 calls:
Slowest
769.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
702.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
190.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))
147.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)))))
115.0ms
(- (* (* wj (exp wj)) (* wj (exp wj))) (* x x))

prune888.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.6b

localize27.0ms

Local error

Found 2 expressions with local error:

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

rewrite7.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-+
*-commutative
associate-*r*
flip3-+
+-commutative
Counts
2 → 19
Calls
2 calls:
Slowest
5.0ms
(+ (pow wj 2) x)
2.0ms
(* 2 (* x wj))

series26.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
15.0ms
(* 2 (* x wj))
11.0ms
(+ (pow wj 2) x)

simplify48.0ms

Counts
6 → 25
Calls
6 calls:
Slowest
13.0ms
(* 2 (* x wj))
13.0ms
(* 2 (* x wj))
10.0ms
(* 2 (* x wj))
4.0ms
(+ (pow wj 2) x)
4.0ms
(+ x (pow wj 2))

prune218.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.6b

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

rewrite27.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
19.0ms
(* (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))

series386.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
113.0ms
(cbrt (+ (pow wj 2) x))
101.0ms
(cbrt (+ (pow wj 2) x))
91.0ms
(* (cbrt (+ (pow wj 2) x)) (cbrt (+ (pow wj 2) x)))
80.0ms
(cbrt (+ (pow wj 2) x))

simplify1.7s

Counts
59 → 87
Calls
59 calls:
Slowest
134.0ms
(* (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))
128.0ms
(* (cbrt (- (pow wj 2) x)) (cbrt (+ (* (pow wj 2) (pow wj 2)) (- (* x x) (* (pow wj 2) x)))))
126.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))
121.0ms
(* (cbrt (+ (* (pow wj 2) (pow wj 2)) (- (* x x) (* (pow wj 2) x)))) (cbrt (- (pow wj 2) x)))
108.0ms
(* (cbrt (+ (pow (pow wj 2) 3) (pow x 3))) (cbrt (- (* (pow wj 2) (pow wj 2)) (* x x))))

prune1.0s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.5b

localize27.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.6b
(cbrt (+ (pow wj 2) x))

rewrite7.0ms

Algorithm
rewrite-expression-head
Rules
12×cbrt-prod
add-cube-cbrt
*-un-lft-identity
cbrt-div
add-sqr-sqrt
add-log-exp
flip-+
add-exp-log
pow1/3
add-cbrt-cube
flip3-+
pow1
Counts
4 → 52
Calls
4 calls:
Slowest
2.0ms
(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))

series378.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
109.0ms
(cbrt (+ (pow wj 2) x))
106.0ms
(cbrt (+ (pow wj 2) x))
86.0ms
(cbrt (+ (pow wj 2) x))
77.0ms
(cbrt (+ (pow wj 2) x))

simplify647.0ms

Counts
32 → 64
Calls
32 calls:
Slowest
104.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))
92.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))
79.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))
73.0ms
(cbrt (- (* (pow wj 2) (pow wj 2)) (* x x)))
46.0ms
(+ (* 1/3 (* (pow (/ 1 (pow x 2)) 1/3) (pow wj 2))) (pow x 1/3))

prune778.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.5b

regimes209.0ms

Accuracy

98.9% (0.0b remaining)

Error of 0.4b against oracle of 0.3b and baseline of 2.3b

bsearch149.0ms

end0.0ms

sample8.4s

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)