Average Error: 43.6 → 0.8
Time: 34.7s
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.6
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.6

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

    \[\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 2019004 +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: 32.9s)Debug log

sample383.0ms

Algorithm
intervals

simplify208.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 44.0b

localize22.0ms

Local error

Found 2 expressions with local error:

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

rewrite46.0ms

Algorithm
rewrite-expression-head
Counts
2 → 71
Calls

2 calls. Slowest were:

28.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
16.0ms
(- (exp (- im)) (exp im))

series182.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

108.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
74.0ms
(- (exp (- im)) (exp im))

simplify5.7s

Counts
62 → 77
Calls

62 calls. Slowest were:

355.0ms
(* (* 0.5 (sin re)) (fma (- (exp im)) 1 (* (exp im) 1)))
300.0ms
(* (* 0.5 (sin re)) (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))))
300.0ms
(* (* 0.5 (sin re)) (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))))

prune889.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.2b

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

rewrite11.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)))
2.0ms
(* (pow im 5) -1/60)
0.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))

series226.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

151.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
39.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))
36.0ms
(* (pow im 5) -1/60)

simplify2.2s

Counts
19 → 51
Calls

19 calls. Slowest were:

500.0ms
(* (* 0.5 (sin re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
320.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
294.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune748.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.1b

localize43.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 (* (- (sin re)) (pow im 5)) 0.008333333333333333 (* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im))))

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
3 → 66
Calls

3 calls. Slowest were:

5.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
4.0ms
(* (- (sin re)) (pow im 5))
0.0ms
(fma (* (- (sin re)) (pow im 5)) 0.008333333333333333 (* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im))))

series373.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

148.0ms
(fma (* (- (sin re)) (pow im 5)) 0.008333333333333333 (* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im))))
126.0ms
(* (- (sin re)) (fma (* im im) (* im 0.16666666666666666) (* 1.0 im)))
99.0ms
(* (- (sin re)) (pow im 5))

simplify2.1s

Counts
39 → 75
Calls

39 calls. Slowest were:

325.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
300.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (* 1.0 (* (sin re) im))))
262.0ms
(- (+ (* 0.16666666666666666 (* (sin re) (pow im 3))) (+ (* 1.0 (* (sin re) im)) (* 0.008333333333333333 (* (sin re) (pow im 5))))))

prune1.4s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.0b

localize27.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.4b
(* (cbrt (- (sin re))) (cbrt (- (sin re))))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 104
Calls

4 calls. Slowest were:

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

series912.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

273.0ms
(* (cbrt (- (sin re))) (cbrt (- (sin re))))
223.0ms
(cbrt (- (sin re)))
211.0ms
(cbrt (- (sin re)))
204.0ms
(cbrt (- (sin re)))

simplify1.7s

Counts
76 → 116
Calls

76 calls. Slowest were:

442.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)))))
431.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)))))
364.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)))))

prune1.9s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.0b

regimes501.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.1s

Algorithm
intervals