Average Error: 43.0 → 1.0
Time: 41.4s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(-0.5\right) \cdot \sin re\right) \cdot \left(\left(2 \cdot im + \frac{1}{60} \cdot {im}^{5}\right) + \log \left(e^{{im}^{3} \cdot \frac{1}{3}}\right)\right)\]

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.0
Target0.3
Herbie1.0
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.0

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  3. Using strategy rm
  4. Applied add-log-exp1.0

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\color{blue}{\log \left(e^{\frac{1}{3} \cdot {im}^{3}}\right)} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)\]
  5. Final simplification1.0

    \[\leadsto \left(\left(-0.5\right) \cdot \sin re\right) \cdot \left(\left(2 \cdot im + \frac{1}{60} \cdot {im}^{5}\right) + \log \left(e^{{im}^{3} \cdot \frac{1}{3}}\right)\right)\]

Reproduce

herbie shell --seed 2019018 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

Details

Time bar (total: 39.1s)Debug log

sample331.0ms

Algorithm
intervals
Results
163.0ms126×body1280valid
79.0ms106×body640valid
35.0ms72×body320valid
21.0ms138×body80valid
10.0ms33×body160valid

simplify145.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
145.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))

prune12.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 43.4b

localize36.0ms

Local error

Found 2 expressions with local error:

7.4b
(- (exp (- im)) (exp im))
0.0b
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))

rewrite40.0ms

Algorithm
rewrite-expression-head
Rules
*-un-lft-identity
add-sqr-sqrt
associate-*r*
add-log-exp
add-exp-log
add-cbrt-cube
pow1
add-cube-cbrt
sub-neg
difference-of-squares
distribute-lft-out--
flip--
associate-*r/
flip3--
distribute-lft-in
distribute-rgt-in
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
associate-*l*
diff-log
Counts
2 → 37
Calls
2 calls:
Slowest
26.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
13.0ms
(- (exp (- im)) (exp im))

series154.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
108.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
46.0ms
(- (exp (- im)) (exp im))

simplify911.0ms

Counts
24 → 43
Calls
24 calls:
Slowest
172.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))
121.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
120.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
120.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
71.0ms
(+ (* (exp (- im)) (exp (- im))) (+ (* (exp im) (exp im)) (* (exp (- im)) (exp im))))

prune453.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.1b

localize29.0ms

Local error

Found 4 expressions with local error:

0.1b
(* 1/3 (pow im 3))
0.1b
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
0.1b
(* 1/60 (pow im 5))
0.0b
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))

rewrite35.0ms

Algorithm
rewrite-expression-head
Rules
18×associate-*r*
add-log-exp
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
*-commutative
distribute-rgt-neg-in
sum-log
distribute-lft-neg-in
distribute-neg-frac
flip-+
associate-*r/
flip3-+
distribute-neg-in
cbrt-unprod
distribute-rgt-neg-out
prod-exp
pow-prod-down
associate-*l*
unpow3
distribute-lft-in
neg-mul-1
associate-+r+
+-commutative
cube-mult
distribute-rgt-in
Counts
4 → 64
Calls
4 calls:
Slowest
26.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
6.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
1.0ms
(* 1/3 (pow im 3))
1.0ms
(* 1/60 (pow im 5))

series225.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
142.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
43.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
24.0ms
(* 1/60 (pow im 5))
16.0ms
(* 1/3 (pow im 3))

simplify3.4s

Counts
39 → 76
Calls
39 calls:
Slowest
417.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/60 (pow im 5)) (* 2 im))))
336.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
275.0ms
(* (* (* (* 0.5 (sin re)) (* 0.5 (sin re))) (* 0.5 (sin re))) (* (* (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
235.0ms
(* (- (+ (* 1/60 (pow im 5)) (* 2 im))) (* 0.5 (sin re)))
197.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune1.2s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 0.0b

localize24.0ms

Local error

Found 4 expressions with local error:

2.0b
(log (exp (* 1/3 (pow im 3))))
0.1b
(* 1/3 (pow im 3))
0.1b
(* (* 0.5 (sin re)) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))))
0.1b
(* 1/60 (pow im 5))

rewrite55.0ms

Algorithm
rewrite-expression-head
Rules
22×associate-*r*
16×*-un-lft-identity
10×add-cube-cbrt
10×add-sqr-sqrt
pow1
add-exp-log
add-cbrt-cube
distribute-rgt-neg-in
distribute-lft-neg-in
add-log-exp
distribute-lft-out
log-pow
*-commutative
log-prod
distribute-neg-frac
associate-*r/
distribute-neg-in
flip-+
cbrt-unprod
distribute-rgt-neg-out
prod-exp
pow-prod-down
associate-*l*
rem-log-exp
unpow3
flip3-+
distribute-lft-in
neg-mul-1
exp-prod
cube-mult
distribute-rgt-in
Counts
4 → 68
Calls
4 calls:
Slowest
46.0ms
(* (* 0.5 (sin re)) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))))
3.0ms
(log (exp (* 1/3 (pow im 3))))
2.0ms
(* 1/3 (pow im 3))
2.0ms
(* 1/60 (pow im 5))

series264.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
178.0ms
(* (* 0.5 (sin re)) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))))
34.0ms
(* 1/60 (pow im 5))
27.0ms
(* 1/3 (pow im 3))
25.0ms
(log (exp (* 1/3 (pow im 3))))

simplify4.5s

Counts
44 → 80
Calls
44 calls:
Slowest
387.0ms
(* (* (* (* 0.5 (sin re)) (* 0.5 (sin re))) (* 0.5 (sin re))) (* (* (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im))))) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im))))))
365.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/60 (pow im 5)) (* 2 im))))
361.0ms
(* (- (+ (* 1/60 (pow im 5)) (* 2 im))) (* 0.5 (sin re)))
360.0ms
(* (* 0.5 (sin re)) (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))))
298.0ms
(cbrt (- (+ (log (exp (* 1/3 (pow im 3)))) (+ (* 1/60 (pow im 5)) (* 2 im)))))

prune1.4s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

14.3b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
14.3b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
14.3b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
0.5b
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))

rewrite88.0ms

Algorithm
rewrite-expression-head
Rules
20×associate-*r/
18×distribute-neg-frac
18×cbrt-div
flip-+
flip3-+
pow1
pow1/3
add-cube-cbrt
add-exp-log
*-un-lft-identity
add-sqr-sqrt
cbrt-prod
add-log-exp
associate-*l*
associate-*r*
add-cbrt-cube
frac-times
pow-prod-up
associate-*l/
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 65
Calls
4 calls:
Slowest
41.0ms
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))
18.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
16.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
11.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

series1.9s

Counts
4 → 12
Calls
4 calls:
Slowest
671.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
465.0ms
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))
388.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
366.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

simplify9.4s

Counts
49 → 77
Calls
49 calls:
Slowest
377.0ms
(+ (* (cbrt 0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ -1 im))))))) (* 20/3 (/ (* (cbrt 0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ -1 im))))))) (pow im 2))))
367.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
349.0ms
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))
342.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
338.0ms
(+ (* 20/3 (/ (* (cbrt -0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ 1 im))))))) (pow im 2))) (* (cbrt -0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ 1 im))))))))

prune1.5s

Pruning

14 alts after pruning (12 fresh and 2 done)

Merged error: 0.0b

regimes715.0ms

Accuracy

0% (0.9b remaining)

Error of 1.0b against oracle of 0.1b and baseline of 1.0b

bsearch10.0ms

end0.0ms

sample12.2s

Algorithm
intervals
Results
6.9s4690×body1280valid
3.0s3737×body640valid
1.1s1917×body320valid
690.0ms4452×body80valid
337.0ms979×body160valid