Average Error: 43.4 → 0.8
Time: 25.4s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(im \cdot \sin re\right) \cdot \left(\left(-0.16666666666666666\right) \cdot \left(im \cdot im\right) - 1.0\right) - 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\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.4
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.4

    \[\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. Taylor expanded around inf 0.8

    \[\leadsto \color{blue}{-\left(0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1.0 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  4. Simplified0.8

    \[\leadsto \color{blue}{\left(\sin re \cdot im\right) \cdot \left(\left(-0.16666666666666666\right) \cdot \left(im \cdot im\right) - 1.0\right) - \left(\sin re \cdot {im}^{5}\right) \cdot 0.008333333333333333}\]
  5. Final simplification0.8

    \[\leadsto \left(im \cdot \sin re\right) \cdot \left(\left(-0.16666666666666666\right) \cdot \left(im \cdot im\right) - 1.0\right) - 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\]

Reproduce

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

sample323.0ms

Algorithm
intervals
Results
186.0ms145×body1280valid
72.0ms111×body640valid
23.0ms59×body320valid
16.0ms124×body80valid
9.0ms34×body160valid

simplify123.0ms

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 44.3b

localize41.0ms

Local error

Found 2 expressions with local error:

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

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

series175.0ms

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

simplify1.1s

Counts
24 → 43
Calls
24 calls:
Slowest
189.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
144.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
136.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))
122.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
103.0ms
(+ (* (exp (- im)) (exp (- im))) (+ (* (exp im) (exp im)) (* (exp (- im)) (exp im))))

prune405.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.2b

localize21.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.0b
(* 1/60 (pow im 5))
0.0b
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))

rewrite45.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
34.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)))
2.0ms
(* 1/3 (pow im 3))
2.0ms
(* 1/60 (pow im 5))

series228.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
156.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
38.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
19.0ms
(* 1/60 (pow im 5))
15.0ms
(* 1/3 (pow im 3))

simplify3.2s

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

prune987.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.0b

localize37.0ms

Local error

Found 4 expressions with local error:

0.1b
(* (- 0.16666666666666666) (* im im))
0.1b
(* (sin re) im)
0.0b
(* (sin re) (pow im 5))
0.0b
(* (* (sin re) (pow im 5)) 0.008333333333333333)

rewrite16.0ms

Algorithm
rewrite-expression-head
Rules
11×associate-*l*
add-exp-log
add-cube-cbrt
add-cbrt-cube
*-un-lft-identity
add-sqr-sqrt
pow1
add-log-exp
*-commutative
associate-*r*
prod-exp
cbrt-unprod
pow-prod-down
neg-mul-1
pow-to-exp
distribute-lft-neg-out
Counts
4 → 54
Calls
4 calls:
Slowest
7.0ms
(* (* (sin re) (pow im 5)) 0.008333333333333333)
4.0ms
(* (sin re) (pow im 5))
3.0ms
(* (- 0.16666666666666666) (* im im))
2.0ms
(* (sin re) im)

series276.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
125.0ms
(* (* (sin re) (pow im 5)) 0.008333333333333333)
108.0ms
(* (sin re) (pow im 5))
32.0ms
(* (sin re) im)
11.0ms
(* (- 0.16666666666666666) (* im im))

simplify978.0ms

Counts
29 → 66
Calls
29 calls:
Slowest
364.0ms
(* (* (* (- 0.16666666666666666) (- 0.16666666666666666)) (- 0.16666666666666666)) (* (* (* im im) (* im im)) (* im im)))
240.0ms
(- (* re (pow im 5)) (* 1/6 (* (pow re 3) (pow im 5))))
203.0ms
(- (* 0.008333333333333333 (* re (pow im 5))) (* 0.0013888888888888887 (* (pow re 3) (pow im 5))))
57.0ms
(* (* (* (sin re) (sin re)) (sin re)) (* (* (pow im 5) (pow im 5)) (pow im 5)))
21.0ms
(* (- 0.16666666666666666) (* im im))

prune862.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.0b

localize15.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (sin re))
0.6b
(cbrt (sin re))
0.6b
(cbrt (sin re))
0.5b
(* (cbrt (sin re)) (cbrt (sin re)))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
add-cbrt-cube
pow-prod-up
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 61
Calls
4 calls:
Slowest
5.0ms
(* (cbrt (sin re)) (cbrt (sin re)))
3.0ms
(cbrt (sin re))
1.0ms
(cbrt (sin re))
0.0ms
(cbrt (sin re))

series621.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
170.0ms
(cbrt (sin re))
151.0ms
(cbrt (sin re))
151.0ms
(cbrt (sin re))
148.0ms
(* (cbrt (sin re)) (cbrt (sin re)))

simplify367.0ms

Counts
41 → 73
Calls
41 calls:
Slowest
84.0ms
(- (pow re 1/3) (+ (* 1/3240 (pow (pow re 13) 1/3)) (* 1/18 (pow (pow re 7) 1/3))))
81.0ms
(- (pow re 1/3) (+ (* 1/3240 (pow (pow re 13) 1/3)) (* 1/18 (pow (pow re 7) 1/3))))
64.0ms
(- (+ (* 1/405 (pow (pow re 14) 1/3)) (pow re 2/3)) (* 1/9 (pow (pow re 8) 1/3)))
57.0ms
(- (pow re 1/3) (+ (* 1/3240 (pow (pow re 13) 1/3)) (* 1/18 (pow (pow re 7) 1/3))))
5.0ms
(pow (pow (sin re) 2) 1/3)

prune987.0ms

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.0b

regimes1.0s

Accuracy

0% (0.7b remaining)

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

bsearch6.0ms

end0.0ms

sample12.0s

Algorithm
intervals
Results
5.8s4806×body1280valid
3.8s3665×body640valid
1.0s1885×body320valid
788.0ms4433×body80valid
313.0ms991×body160valid