Average Error: 42.8 → 0.7
Time: 39.4s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[(\left(\left(-\sin re\right) \cdot {im}^{5}\right) \cdot 0.008333333333333333 + \left(\left(\left(-im\right) \cdot \sin re\right) \cdot (0.16666666666666666 \cdot \left(im \cdot im\right) + 1.0)_*\right))_*\]

Error

Bits error versus re

Bits error versus im

Target

Original42.8
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 42.8

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{(im \cdot \left((\frac{-1}{3} \cdot \left(im \cdot im\right) + -2)_*\right) + \left({im}^{5} \cdot \frac{-1}{60}\right))_*}\]
  4. Taylor expanded around inf 0.7

    \[\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)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{(\left(\left(-\sin re\right) \cdot {im}^{5}\right) \cdot 0.008333333333333333 + \left(\left(-\sin re\right) \cdot (\left(im \cdot im\right) \cdot \left(im \cdot 0.16666666666666666\right) + \left(1.0 \cdot im\right))_*\right))_*}\]
  6. Taylor expanded around -inf 0.7

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

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

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

Reproduce

herbie shell --seed 2018365 +o rules:numerics
(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: 21.3s)Debug log

start481.0ms

Algorithm
intervals

setup178.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 44.4b

localize19.0ms

Local error

Found 2 expressions with local error:

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

rewrite53.0ms

Algorithm
rewrite-expression-head
Counts
2 → 71
Calls

2 calls. Slowest were:

36.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
15.0ms
(- (exp (- im)) (exp im))

series146.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

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

simplify6.6s

Counts
62 → 77
Calls

62 calls. Slowest were:

547.0ms
(* (* 0.5 (sin re)) (fma (- (sqrt (exp im))) (sqrt (exp im)) (* (sqrt (exp im)) (sqrt (exp im)))))
360.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
334.0ms
(* (* 0.5 (sin re)) (fma (- (exp im)) 1 (* (exp im) 1)))

prune1.2s

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0.2b

localize20.0ms

Local error

Found 3 expressions with local error:

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
3 → 42
Calls

3 calls. Slowest were:

10.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
4.0ms
(* (pow im 5) -1/60)
0.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))

series215.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

159.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
30.0ms
(* (pow im 5) -1/60)
26.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))

simplify2.3s

Counts
19 → 51
Calls

19 calls. Slowest were:

476.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
317.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
286.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune935.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.1b

localize42.0ms

Local error

Found 3 expressions with local error:

0.2b
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
0.0b
(* (- (sin re)) (pow im 5))
0.0b
(fma (* im im) (* im 0.16666666666666666) (* 1.0 im))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
3 → 66
Calls

3 calls. Slowest were:

14.0ms
(* (- (sin re)) (pow im 5))
9.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
0.0ms
(fma (* im im) (* im 0.16666666666666666) (* 1.0 im))

series314.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

153.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
105.0ms
(* (- (sin re)) (pow im 5))
55.0ms
(fma (* im im) (* im 0.16666666666666666) (* 1.0 im))

simplify1.9s

Counts
39 → 75
Calls

39 calls. Slowest were:

399.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
392.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
249.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))

prune1.6s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.0b

localize13.0ms

Local error

Found 4 expressions with local error:

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

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 81
Calls

4 calls. Slowest were:

12.0ms
(* (* (sin re) (- im)) (fma 0.16666666666666666 (* im im) 1.0))
4.0ms
(* (- (sin re)) (pow im 5))
4.0ms
(* (sin re) (- im))

series364.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

141.0ms
(* (- (sin re)) (pow im 5))
135.0ms
(* (* (sin re) (- im)) (fma 0.16666666666666666 (* im im) 1.0))
52.0ms
(* (sin re) (- im))
37.0ms
(fma 0.16666666666666666 (* im im) 1.0)

simplify2.7s

Counts
47 → 93
Calls

47 calls. Slowest were:

375.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
371.0ms
(* (* (sin re) (- im)) (fma 0.16666666666666666 (* im im) 1.0))
357.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))

prune1.7s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 0.0b

regimes480.0ms

Accuracy

0% (0.6b remaining)

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

bsearch10.0ms