Average Error: 43.5 → 0.7
Time: 38.6s
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.5
Target0.3
Herbie0.7
\[\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.5

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

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

    \[\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 2019021 
(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: 36.9s)Debug log

sample321.0ms

Algorithm
intervals
Results
140.0ms157×body1280valid
81.0ms124×body640valid
55.0ms63×body320valid
16.0ms134×body80valid
7.0ms27×body160valid

simplify103.0ms

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

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 44.2b

localize33.0ms

Local error

Found 2 expressions with local error:

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

rewrite23.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
15.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
7.0ms
(- (exp (- im)) (exp im))

series146.0ms

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

simplify1.0s

Counts
24 → 43
Calls
24 calls:
Slowest
144.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
144.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))
139.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
128.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
73.0ms
(* (* (* (* 0.5 (sin re)) (* 0.5 (sin re))) (* 0.5 (sin re))) (* (* (- (exp (- im)) (exp im)) (- (exp (- im)) (exp im))) (- (exp (- im)) (exp im))))

prune496.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.1b

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

rewrite55.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
38.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
12.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))

series216.0ms

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

simplify3.0s

Counts
39 → 76
Calls
39 calls:
Slowest
302.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
277.0ms
(* (* 0.5 (sin re)) (- (+ (* 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))))))
208.0ms
(* (- (+ (* 1/60 (pow im 5)) (* 2 im))) (* 0.5 (sin re)))
170.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (+ (* 1.0 (* (sin re) im)) (* 0.008333333333333333 (* (sin re) (pow im 5))))))

prune1.1s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite93.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))))))
20.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
20.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
381.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)))))))
335.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
297.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
297.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

simplify9.6s

Counts
49 → 77
Calls
49 calls:
Slowest
511.0ms
(* (cbrt (- (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))) (cbrt (+ (* (* 1/3 (pow im 3)) (* 1/3 (pow im 3))) (- (* (+ (* 1/60 (pow im 5)) (* 2 im)) (+ (* 1/60 (pow im 5)) (* 2 im))) (* (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))
373.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)))))))))
371.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))))
353.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)))))))))
345.0ms
(* (cbrt (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))) (cbrt (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))))

prune1.4s

Pruning

13 alts after pruning (11 fresh and 2 done)

Merged error: 0.0b

localize29.0ms

Local error

Found 4 expressions with local error:

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

rewrite54.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
24.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
20.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
8.0ms
(cbrt (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
1.0ms
(cbrt (* 0.5 (sin re)))

series972.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
325.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
292.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
183.0ms
(cbrt (* 0.5 (sin re)))
172.0ms
(cbrt (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))

simplify4.0s

Counts
31 → 63
Calls
31 calls:
Slowest
393.0ms
(cbrt (- (+ (pow (* 1/3 (pow im 3)) 3) (pow (+ (* 1/60 (pow im 5)) (* 2 im)) 3))))
350.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)))))))))
332.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))))
315.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)))))))))
297.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.2s

Pruning

13 alts after pruning (10 fresh and 3 done)

Merged error: 0.0b

regimes560.0ms

Accuracy

0% (0.7b remaining)

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

bsearch8.0ms

end0.0ms

sample11.1s

Algorithm
intervals
Results
6.0s4726×body1280valid
2.8s3704×body640valid
1.3s1890×body320valid
528.0ms4424×body80valid
366.0ms978×body160valid