Average Error: 44.0 → 0.8
Time: 44.0s
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(\frac{-1}{60} \cdot {im}^{5} + im \cdot -2\right) + \left(0.5 \cdot \sin re\right) \cdot \left(\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

Original44.0
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 44.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 distribute-neg-in0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) + \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  5. Applied distribute-lft-in0.8

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

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

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

Reproduce

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

start429.0ms

Algorithm
intervals

setup190.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 44.8b

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

rewrite40.0ms

Algorithm
rewrite-expression-head
Counts
2 → 37
Calls

2 calls. Slowest were:

26.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
13.0ms
(- (exp (- im)) (exp im))

series172.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

115.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
56.0ms
(- (exp (- im)) (exp im))

simplify1.0s

Counts
24 → 43
Calls

24 calls. Slowest were:

163.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))
157.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
153.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))

prune524.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0.1b

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

rewrite44.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

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)))
1.0ms
(* 1/3 (pow im 3))

series205.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

135.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
32.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
21.0ms
(* 1/60 (pow im 5))
16.0ms
(* 1/3 (pow im 3))

simplify3.7s

Counts
39 → 76
Calls

39 calls. Slowest were:

437.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (+ (* 1.0 (* (sin re) im)) (* 0.008333333333333333 (* (sin re) (pow im 5))))))
400.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
389.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/60 (pow im 5)) (* 2 im))))

prune1.7s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.0b

localize35.0ms

Local error

Found 4 expressions with local error:

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

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
4 → 60
Calls

4 calls. Slowest were:

14.0ms
(* (+ (* im -2) (* -1/60 (pow im 5))) (* 0.5 (sin re)))
12.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
7.0ms
(* 1/3 (pow im 3))

series205.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

82.0ms
(* (+ (* im -2) (* -1/60 (pow im 5))) (* 0.5 (sin re)))
77.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
26.0ms
(* 1/3 (pow im 3))
20.0ms
(* -1/60 (pow im 5))

simplify2.0s

Counts
36 → 72
Calls

36 calls. Slowest were:

418.0ms
(+ (log (* 0.5 (sin re))) (log (- (* 1/3 (pow im 3)))))
200.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
199.0ms
(- (* 0.027777777777777776 (* (pow re 3) (pow im 3))) (* 0.16666666666666666 (* re (pow im 3))))

prune1.6s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.0b

localize30.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
0.6b
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
0.6b
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
0.5b
(* (cbrt (+ (* im -2) (* -1/60 (pow im 5)))) (cbrt (+ (* im -2) (* -1/60 (pow im 5)))))

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
4 → 75
Calls

4 calls. Slowest were:

15.0ms
(* (cbrt (+ (* im -2) (* -1/60 (pow im 5)))) (cbrt (+ (* im -2) (* -1/60 (pow im 5)))))
3.0ms
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
2.0ms
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))

series3.0s

Counts
4 → 12
Calls

4 calls. Slowest were:

823.0ms
(* (cbrt (+ (* im -2) (* -1/60 (pow im 5)))) (cbrt (+ (* im -2) (* -1/60 (pow im 5)))))
755.0ms
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
741.0ms
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))
722.0ms
(cbrt (+ (* im -2) (* -1/60 (pow im 5))))

simplify7.9s

Counts
59 → 87
Calls

59 calls. Slowest were:

536.0ms
(- (+ (exp (* 1/3 (- (log 1/60) (* 5 (log (/ -1 im)))))) (* 40 (/ (exp (* 1/3 (- (log 1/60) (* 5 (log (/ -1 im)))))) (pow im 4)))) (* 1600 (/ (exp (* 1/3 (- (log 1/60) (* 5 (log (/ -1 im)))))) (pow im 8))))
472.0ms
(* (cbrt (+ (* (* im -2) (* im -2)) (- (* (* -1/60 (pow im 5)) (* -1/60 (pow im 5))) (* (* im -2) (* -1/60 (pow im 5)))))) (cbrt (- (* im -2) (* -1/60 (pow im 5)))))
429.0ms
(* (cbrt (+ (pow (* im -2) 3) (pow (* -1/60 (pow im 5)) 3))) (cbrt (- (* (* im -2) (* im -2)) (* (* -1/60 (pow im 5)) (* -1/60 (pow im 5))))))

prune2.5s

Pruning

9 alts after pruning (7 fresh and 2 done)

Merged error: 0.0b

regimes564.0ms

Accuracy

0% (0.3b remaining)

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

bsearch16.0ms