Average Error: 43.5 → 0.8
Time: 39.6s
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(-\sin re\right) \cdot (\left(im \cdot im\right) \cdot \left(im \cdot 0.16666666666666666\right) + \left(im \cdot 1.0\right))_*\right))_*\]

Error

Bits error versus re

Bits error versus im

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. Simplified0.9

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

    \[\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. Final simplification0.8

    \[\leadsto (\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(im \cdot 1.0\right))_*\right))_*\]

Reproduce

herbie shell --seed 2018362 +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.5s)Debug log

start731.0ms

Algorithm
intervals

setup209.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 45.7b

localize23.0ms

Local error

Found 2 expressions with local error:

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

rewrite41.0ms

Algorithm
rewrite-expression-head
Counts
2 → 71
Calls

2 calls. Slowest were:

27.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
12.0ms
(- (exp (- im)) (exp im))

series178.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

121.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
57.0ms
(- (exp (- im)) (exp im))

simplify6.1s

Counts
62 → 77
Calls

62 calls. Slowest were:

356.0ms
(* (* 0.5 (sin re)) (fma (- (exp im)) 1 (* (exp im) 1)))
332.0ms
(* (* 0.5 (sin re)) (fma (- (exp im)) 1 (* (exp im) 1)))
311.0ms
(* (* 0.5 (sin re)) (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))))

prune1.1s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.1b

localize19.0ms

Local error

Found 3 expressions with local error:

0.1b
(* (* 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))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
3 → 42
Calls

3 calls. Slowest were:

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

series199.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

143.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
32.0ms
(* (pow im 5) -1/60)
23.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))

simplify2.3s

Counts
19 → 51
Calls

19 calls. Slowest were:

504.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
336.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
283.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune1.1s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 0.0b

localize24.0ms

Local error

Found 3 expressions with local error:

0.1b
(* (- (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))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
3 → 66
Calls

3 calls. Slowest were:

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

series322.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

138.0ms
(* (- (sin re)) (pow im 5))
125.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
59.0ms
(fma (* im im) (* im 0.16666666666666666) (* 1.0 im))

simplify1.9s

Counts
39 → 75
Calls

39 calls. Slowest were:

361.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
303.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
298.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))

prune1.5s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.0b

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 104
Calls

4 calls. Slowest were:

8.0ms
(* (cbrt (- (sin re))) (cbrt (- (sin re))))
2.0ms
(cbrt (- (sin re)))
2.0ms
(cbrt (- (sin re)))

series879.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

249.0ms
(* (cbrt (- (sin re))) (cbrt (- (sin re))))
226.0ms
(cbrt (- (sin re)))
208.0ms
(cbrt (- (sin re)))
195.0ms
(cbrt (- (sin re)))

simplify1.8s

Counts
76 → 116
Calls

76 calls. Slowest were:

432.0ms
(- (* (pow re 1/3) (cbrt -1)) (+ (* 1/3240 (* (pow (pow re 13) 1/3) (cbrt -1))) (* 1/18 (* (pow (pow re 7) 1/3) (cbrt -1)))))
402.0ms
(- (* (pow re 1/3) (cbrt -1)) (+ (* 1/3240 (* (pow (pow re 13) 1/3) (cbrt -1))) (* 1/18 (* (pow (pow re 7) 1/3) (cbrt -1)))))
386.0ms
(- (* (pow re 1/3) (cbrt -1)) (+ (* 1/3240 (* (pow (pow re 13) 1/3) (cbrt -1))) (* 1/18 (* (pow (pow re 7) 1/3) (cbrt -1)))))

prune2.6s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.0b

regimes399.0ms

Accuracy

0% (0.8b remaining)

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

bsearch8.0ms