Average Error: 43.5 → 0.8
Time: 39.2s
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.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.5

    \[\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 0 0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\color{blue}{\frac{1}{60} \cdot {im}^{5}} + 2 \cdot im\right)\right)\right)\]
  4. 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 2019005 
(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: 37.7s)Debug log

sample381.0ms

Algorithm
intervals

simplify157.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 43.9b

localize25.0ms

Local error

Found 2 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
2 → 37
Calls

2 calls. Slowest were:

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

series145.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

86.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
59.0ms
(- (exp (- im)) (exp im))

simplify1.0s

Counts
24 → 43
Calls

24 calls. Slowest were:

166.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
152.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
123.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune482.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0.1b

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

rewrite34.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

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

series200.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

119.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
28.0ms
(* 1/60 (pow im 5))
27.0ms
(* 1/3 (pow im 3))
25.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))

simplify3.4s

Counts
39 → 76
Calls

39 calls. Slowest were:

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

prune1.0s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 0.0b

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

rewrite38.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

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

series217.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

151.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
25.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
21.0ms
(* 1/3 (pow im 3))
21.0ms
(* 1/60 (pow im 5))

simplify3.2s

Counts
39 → 76
Calls

39 calls. Slowest were:

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

prune917.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 0.0b

localize18.0ms

Local error

Found 4 expressions with local error:

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

rewrite69.0ms

Algorithm
rewrite-expression-head
Counts
4 → 65
Calls

4 calls. Slowest were:

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

series1.4s

Counts
4 → 12
Calls

4 calls. Slowest were:

417.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)))))))
362.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
326.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
322.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

simplify9.8s

Counts
49 → 77
Calls

49 calls. Slowest were:

594.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))))))))
411.0ms
(+ (log (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))) (log (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))))
403.0ms
(cbrt (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))

prune1.5s

Pruning

11 alts after pruning (9 fresh and 2 done)

Merged error: 0.0b

regimes621.0ms

Accuracy

0% (0.7b remaining)

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

bsearch9.0ms

end0.0ms

sample13.0s

Algorithm
intervals