Average Error: 58.0 → 0.8
Time: 38.5s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(-\cos re\right) \cdot (0.008333333333333333 \cdot \left({im}^{5}\right) + \left((\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

Original58.0
Target0.2
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \cos 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 \cos 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(1.0 \cdot \left(im \cdot \cos re\right) + \left(0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + 0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)\right)\right)}\]
  5. Simplified0.8

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

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

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

Details

Time bar (total: 36.3s)Debug log

sample362.0ms

Algorithm
intervals
Results
520×(pre true 80)
191×(body real 1280)
144×(body real 80)
109×(body real 640)
52×(body real 320)
24×(body real 160)

simplify156.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
156.0ms
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im)))

prune13.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 58.1b

localize45.0ms

Local error

Found 2 expressions with local error:

4.2b
(- (exp (- 0 im)) (exp im))
0.0b
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im)))

rewrite52.0ms

Algorithm
rewrite-expression-head
Rules
45×prod-diff
32×*-un-lft-identity
32×add-sqr-sqrt
28×add-cube-cbrt
20×exp-sum
17×distribute-lft-in
17×distribute-rgt-in
13×sub-neg
associate-*r*
fma-neg
add-log-exp
add-exp-log
add-cbrt-cube
pow1
difference-of-squares
distribute-lft-out--
flip--
log1p-expm1-u
associate-*r/
flip3--
expm1-log1p-u
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
associate-*l*
diff-log
Counts
2 → 91
Calls
2 calls:
Slowest
32.0ms
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im)))
18.0ms
(- (exp (- 0 im)) (exp im))

series160.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
96.0ms
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im)))
64.0ms
(- (exp (- 0 im)) (exp im))

simplify9.4s

Counts
88 → 97
Calls
88 calls:
Slowest
335.0ms
(* (* 0.5 (cos re)) (fma (- (exp im)) 1 (* (exp im) 1)))
309.0ms
(* (* 0.5 (cos re)) (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))))
290.0ms
(* (* 0.5 (cos re)) (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))))
290.0ms
(* (fma (- (cbrt (exp im))) (* (cbrt (exp im)) (cbrt (exp im))) (* (cbrt (exp im)) (* (cbrt (exp im)) (cbrt (exp im))))) (* 0.5 (cos re)))
286.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))

prune1.2s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.1b

localize35.0ms

Local error

Found 4 expressions with local error:

0.1b
(* (* 0.5 (cos 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))
0.0b
(fma -1/3 (* im im) -2)

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
pow1
add-sqr-sqrt
add-log-exp
log1p-expm1-u
fma-udef
associate-*l*
expm1-log1p-u
associate-*r*
*-commutative
cbrt-unprod
prod-exp
pow-prod-down
distribute-lft-in
distribute-rgt-in
Counts
4 → 52
Calls
4 calls:
Slowest
5.0ms
(* (* 0.5 (cos 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))
0.0ms
(fma -1/3 (* im im) -2)

series245.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
147.0ms
(* (* 0.5 (cos re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
40.0ms
(fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60))
38.0ms
(fma -1/3 (* im im) -2)
20.0ms
(* (pow im 5) -1/60)

simplify2.4s

Counts
22 → 64
Calls
22 calls:
Slowest
413.0ms
(* (* 0.5 (cos re)) (fma im (fma -1/3 (* im im) -2) (* (pow im 5) -1/60)))
355.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
303.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
260.0ms
(- (+ (* 1.0 (* im (cos re))) (+ (* 0.16666666666666666 (* (pow im 3) (cos re))) (* 0.008333333333333333 (* (pow im 5) (cos re))))))
212.0ms
(- (+ (* 1.0 (* im (cos re))) (+ (* 0.16666666666666666 (* (pow im 3) (cos re))) (* 0.008333333333333333 (* (pow im 5) (cos re))))))

prune985.0ms

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.1b

localize37.0ms

Local error

Found 3 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Rules
10×associate-*l*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
fma-udef
add-log-exp
log1p-expm1-u
associate-*r*
distribute-rgt-neg-in
expm1-log1p-u
distribute-lft-neg-in
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
distribute-lft-in
neg-mul-1
distribute-rgt-in
distribute-lft-neg-out
Counts
3 → 49
Calls
3 calls:
Slowest
10.0ms
(* (- (cos re)) (fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))))
0.0ms
(fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im)))
0.0ms
(fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))

series244.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
133.0ms
(* (- (cos re)) (fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))))
67.0ms
(fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))
43.0ms
(fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im)))

simplify2.3s

Counts
25 → 58
Calls
25 calls:
Slowest
354.0ms
(* (- (cos re)) (fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))))
254.0ms
(* (cos re) (fma 0.008333333333333333 (pow im 5) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im))))
236.0ms
(- (+ (* 1.0 (* im (cos re))) (+ (* 0.16666666666666666 (* (pow im 3) (cos re))) (* 0.008333333333333333 (* (pow im 5) (cos re))))))
224.0ms
(* (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im)) (- (cos re)))
220.0ms
(* (- (cos re)) (fma (* im im) (* 0.16666666666666666 im) (* 1.0 im)))

prune866.0ms

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 0.0b

localize16.0ms

Local error

Found 4 expressions with local error:

0.3b
(cbrt (- (cos re)))
0.3b
(cbrt (- (cos re)))
0.3b
(cbrt (- (cos re)))
0.2b
(* (cbrt (- (cos re))) (cbrt (- (cos re))))

rewrite11.0ms

Algorithm
rewrite-expression-head
Rules
50×cbrt-prod
21×add-cube-cbrt
21×*-un-lft-identity
21×add-sqr-sqrt
15×distribute-rgt-neg-in
15×distribute-lft-neg-in
13×associate-*l*
13×associate-*r*
pow1
pow1/3
add-exp-log
neg-mul-1
add-log-exp
log1p-expm1-u
add-cbrt-cube
expm1-log1p-u
pow-prod-up
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 104
Calls
4 calls:
Slowest
7.0ms
(* (cbrt (- (cos re))) (cbrt (- (cos re))))
1.0ms
(cbrt (- (cos re)))
1.0ms
(cbrt (- (cos re)))
1.0ms
(cbrt (- (cos re)))

series1.0s

Counts
4 → 12
Calls
4 calls:
Slowest
372.0ms
(* (cbrt (- (cos re))) (cbrt (- (cos re))))
223.0ms
(cbrt (- (cos re)))
204.0ms
(cbrt (- (cos re)))
202.0ms
(cbrt (- (cos re)))

simplify1.0s

Counts
76 → 116
Calls
76 calls:
Slowest
269.0ms
(- (cbrt -1) (+ (* 1/6 (* (pow re 2) (cbrt -1))) (* 1/72 (* (pow re 4) (cbrt -1)))))
244.0ms
(- (cbrt -1) (+ (* 1/6 (* (pow re 2) (cbrt -1))) (* 1/72 (* (pow re 4) (cbrt -1)))))
168.0ms
(- (cbrt -1) (+ (* 1/6 (* (pow re 2) (cbrt -1))) (* 1/72 (* (pow re 4) (cbrt -1)))))
139.0ms
(- (pow (cbrt -1) 2) (+ (* 1/405 (* (pow re 6) (pow (cbrt -1) 2))) (* 1/3 (* (pow re 2) (pow (cbrt -1) 2)))))
24.0ms
(* (- (cos re)) (- (cos re)))

prune2.0s

Pruning

13 alts after pruning (12 fresh and 1 done)

Merged error: 0.0b

regimes800.0ms

Accuracy

0% (0.7b remaining)

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

bsearch7.0ms

end0.0ms

sample12.8s

Algorithm
intervals
Results
15930×(pre true 80)
5734×(body real 1280)
4437×(body real 80)
3638×(body real 640)
1483×(body real 320)
638×(body real 160)