Average Error: 43.8 → 0.8
Time: 42.5s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(\left(im \cdot -2 + \frac{-1}{60} \cdot {im}^{5}\right) + \frac{-1}{3} \cdot {im}^{3}\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.8
Target0.3
Herbie0.8
\[\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.8

    \[\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. Final simplification0.8

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

Reproduce

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

sample894.0ms

Algorithm
intervals
Results
520×(pre true 80)
166×(body real 1280)
149×(body real 80)
118×(body real 640)
55×(body real 320)
32×(body real 160)

simplify137.0ms

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 44.5b

localize28.0ms

Local error

Found 2 expressions with local error:

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

rewrite48.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
33.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
14.0ms
(- (exp (- im)) (exp im))

series200.0ms

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

simplify1.0s

Counts
24 → 43
Calls
24 calls:
Slowest
167.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
161.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))
150.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
117.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
99.0ms
(+ (* (exp (- im)) (exp (- im))) (+ (* (exp im) (exp im)) (* (exp (- im)) (exp im))))

prune483.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.1b

localize40.0ms

Local error

Found 4 expressions with local error:

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

rewrite37.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
20.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
13.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
2.0ms
(* 1/60 (pow im 5))
2.0ms
(* 1/3 (pow im 3))

series238.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
134.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
42.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
34.0ms
(* 1/60 (pow im 5))
28.0ms
(* 1/3 (pow im 3))

simplify3.3s

Counts
39 → 76
Calls
39 calls:
Slowest
377.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/60 (pow im 5)) (* 2 im))))
316.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
306.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))))))
240.0ms
(* (- (+ (* 1/60 (pow im 5)) (* 2 im))) (* 0.5 (sin re)))
188.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (+ (* 1.0 (* (sin re) im)) (* 0.008333333333333333 (* (sin re) (pow im 5))))))

prune1.1s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.0b

localize12.0ms

Local error

Found 4 expressions with local error:

13.9b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
13.9b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
13.9b
(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)))))))

rewrite92.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
31.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)))))))
21.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
21.0ms
(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))))))

series1.3s

Counts
4 → 12
Calls
4 calls:
Slowest
446.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)))))))
303.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
281.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
255.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

simplify9.3s

Counts
49 → 77
Calls
49 calls:
Slowest
407.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)))))))
389.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))))
354.0ms
(- (+ (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))) (* 1/18 (* (pow im 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re))))))))) (* 1/18 (* (pow re 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))))))
341.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))))
341.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.6s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite61.0ms

Algorithm
rewrite-expression-head
Rules
13×cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
distribute-neg-frac
cbrt-div
add-log-exp
add-exp-log
associate-*r/
pow1/3
add-cbrt-cube
pow1
flip-+
flip3-+
distribute-rgt-neg-in
distribute-lft-neg-in
neg-mul-1
Counts
4 → 51
Calls
4 calls:
Slowest
22.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
21.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
16.0ms
(cbrt (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
2.0ms
(cbrt (* 0.5 (sin re)))

series924.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
300.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
284.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
200.0ms
(cbrt (* 0.5 (sin re)))
140.0ms
(cbrt (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))

simplify4.4s

Counts
31 → 63
Calls
31 calls:
Slowest
446.0ms
(cbrt (- (+ (pow (* 1/3 (pow im 3)) 3) (pow (+ (* 1/60 (pow im 5)) (* 2 im)) 3))))
372.0ms
(- (+ (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))) (* 1/18 (* (pow im 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re))))))))) (* 1/18 (* (pow re 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))))))
354.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))))
344.0ms
(- (+ (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))) (* 1/18 (* (pow im 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re))))))))) (* 1/18 (* (pow re 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))))))
333.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))))

prune1.4s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 0.0b

regimes834.0ms

Accuracy

0% (0.7b remaining)

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

bsearch18.0ms

end0.0ms

sample13.1s

Algorithm
intervals
Results
15926×(pre true 80)
4769×(body real 1280)
4531×(body real 80)
3865×(body real 640)
1858×(body real 320)
903×(body real 160)