Average Error: 43.5 → 0.7
Time: 16.7s
Precision: binary64
Cost: 33280
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
↓
\[\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)↓
\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)(FPCore (re im)
:precision binary64
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
↓
(FPCore (re im)
:precision binary64
(-
(* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))
(*
(sin re)
(+
(* (pow im 5.0) 0.008333333333333333)
(* (pow im 7.0) 0.0001984126984126984)))))double code(double re, double im) {
return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
↓
double code(double re, double im) {
return (sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im)) - (sin(re) * ((pow(im, 5.0) * 0.008333333333333333) + (pow(im, 7.0) * 0.0001984126984126984)));
}
Try it out
Enter valid numbers for all inputs
Target
| Original | 43.5 |
|---|
| Target | 0.3 |
|---|
| Herbie | 0.7 |
|---|
\[\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \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}\]
Alternatives
| Alternative 1 |
|---|
| Error | 33.2 |
|---|
| Cost | 91328 |
|---|
\[\left(\sqrt[3]{\sin re} \cdot \sqrt[3]{\sin re}\right) \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(\sqrt[3]{{\sin re}^{0.6666666666666666}} \cdot \sqrt[3]{\sqrt[3]{\sin re}}\right)\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 2 |
|---|
| Error | 33.0 |
|---|
| Cost | 91264 |
|---|
\[\left(\sqrt[3]{\sin re} \cdot \sqrt[3]{\sin re}\right) \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(\sqrt{\sqrt[3]{\sin re}} \cdot \sqrt{\sqrt[3]{\sin re}}\right)\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 3 |
|---|
| Error | 1.7 |
|---|
| Cost | 79232 |
|---|
\[\sqrt[3]{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \cdot \left(\sqrt[3]{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \cdot \sqrt[3]{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 4 |
|---|
| Error | 48.9 |
|---|
| Cost | 72256 |
|---|
\[\left(\sqrt{\sin re} \cdot \sqrt{{im}^{3} \cdot -0.16666666666666666 - im}\right) \cdot \left(\sqrt{\sin re} \cdot \sqrt{{im}^{3} \cdot -0.16666666666666666 - im}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 5 |
|---|
| Error | 42.9 |
|---|
| Cost | 66752 |
|---|
\[\frac{\sin re \cdot \left({\left({im}^{3}\right)}^{3} \cdot -0.004629629629629629 - {im}^{3}\right)}{im \cdot im + \left(\left({im}^{3} \cdot 0.16666666666666666\right) \cdot \left({im}^{3} \cdot 0.16666666666666666\right) + im \cdot \left({im}^{3} \cdot -0.16666666666666666\right)\right)} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 6 |
|---|
| Error | 33.2 |
|---|
| Cost | 65600 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) \cdot \left(\sqrt[3]{\sin re} \cdot {\sin re}^{0.3333333333333333}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 7 |
|---|
| Error | 33.2 |
|---|
| Cost | 65600 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot {\sin re}^{0.3333333333333333}\right) \cdot \left(\sqrt[3]{\sin re} \cdot \sqrt[3]{\sin re}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 8 |
|---|
| Error | 33.3 |
|---|
| Cost | 65536 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot {\sin re}^{0.6666666666666666}\right) \cdot \sqrt[3]{{\left(\sqrt{\sin re}\right)}^{2}} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 9 |
|---|
| Error | 1.6 |
|---|
| Cost | 65536 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) \cdot \left(\sqrt[3]{\sin re} \cdot \sqrt[3]{\sin re}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 10 |
|---|
| Error | 43.5 |
|---|
| Cost | 65152 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \left(\sqrt[3]{e^{-im} - e^{im}} \cdot \left(\sqrt[3]{e^{-im} - e^{im}} \cdot \sqrt[3]{e^{-im} - e^{im}}\right)\right)\]
| Alternative 11 |
|---|
| Error | 26.0 |
|---|
| Cost | 59456 |
|---|
\[\sqrt{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \cdot \sqrt{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 12 |
|---|
| Error | 5.5 |
|---|
| Cost | 59136 |
|---|
\[{\left({\sin re}^{2}\right)}^{0.3333333333333333} \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 13 |
|---|
| Error | 34.8 |
|---|
| Cost | 59136 |
|---|
\[\sqrt[3]{{\sin re}^{2}} \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot {\sin re}^{0.3333333333333333}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 14 |
|---|
| Error | 4.9 |
|---|
| Cost | 59072 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) \cdot \sqrt[3]{{\sin re}^{2}} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 15 |
|---|
| Error | 1.6 |
|---|
| Cost | 59072 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) \cdot {\left(\sqrt[3]{\sin re}\right)}^{2} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 16 |
|---|
| Error | 43.6 |
|---|
| Cost | 58688 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \frac{{\left(e^{im}\right)}^{-3} - {\left(e^{im}\right)}^{3}}{{\left(e^{im}\right)}^{-2} + \left({\left(e^{im}\right)}^{2} + 1\right)}\]
| Alternative 17 |
|---|
| Error | 43.5 |
|---|
| Cost | 58432 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \left(\left(\sqrt{e^{-im}} + \sqrt{e^{im}}\right) \cdot \left(\sqrt{e^{-im}} - \sqrt{e^{im}}\right)\right)\]
| Alternative 18 |
|---|
| Error | 32.7 |
|---|
| Cost | 52928 |
|---|
\[\sqrt{{im}^{3} \cdot -0.16666666666666666 - im} \cdot \left(\sin re \cdot \sqrt{{im}^{3} \cdot -0.16666666666666666 - im}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 19 |
|---|
| Error | 33.3 |
|---|
| Cost | 52672 |
|---|
\[\sqrt[3]{\sin re} \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot {\sin re}^{0.6666666666666666}\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 20 |
|---|
| Error | 33.3 |
|---|
| Cost | 52672 |
|---|
\[\left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \sqrt[3]{\sin re}\right) \cdot {\sin re}^{0.6666666666666666} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 21 |
|---|
| Error | 32.7 |
|---|
| Cost | 52608 |
|---|
\[\sqrt{\sin re} \cdot \left(\sqrt{\sin re} \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 22 |
|---|
| Error | 33.6 |
|---|
| Cost | 46144 |
|---|
\[\sqrt[3]{{\left(\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\right)}^{3}} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 23 |
|---|
| Error | 43.6 |
|---|
| Cost | 45696 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \frac{{\left(e^{im}\right)}^{-2} - {\left(e^{im}\right)}^{2}}{e^{-im} + e^{im}}\]
| Alternative 24 |
|---|
| Error | 44.8 |
|---|
| Cost | 45632 |
|---|
\[\sqrt{e^{-im} - e^{im}} \cdot \left(\left(\sin re \cdot 0.5\right) \cdot \sqrt{e^{-im} - e^{im}}\right)\]
| Alternative 25 |
|---|
| Error | 22.6 |
|---|
| Cost | 40256 |
|---|
\[\frac{\sin re \cdot \left(im \cdot im + {im}^{6} \cdot -0.027777777777777776\right)}{{im}^{3} \cdot 0.16666666666666666 - im} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 26 |
|---|
| Error | 22.6 |
|---|
| Cost | 40256 |
|---|
\[\frac{\sin re \cdot \left({im}^{6} \cdot 0.027777777777777776 - im \cdot im\right)}{im + {im}^{3} \cdot -0.16666666666666666} - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 27 |
|---|
| Error | 44.8 |
|---|
| Cost | 38784 |
|---|
\[\log \left(\sqrt{e^{\sin re \cdot \left(e^{-im} - e^{im}\right)}}\right)\]
| Alternative 28 |
|---|
| Error | 43.5 |
|---|
| Cost | 32576 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \sqrt[3]{{\left(e^{-im} - e^{im}\right)}^{3}}\]
| Alternative 29 |
|---|
| Error | 44.9 |
|---|
| Cost | 32512 |
|---|
\[e^{\log \left(\left(\sin re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\right)}\]
| Alternative 30 |
|---|
| Error | 44.8 |
|---|
| Cost | 32512 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot e^{\log \left(e^{-im} - e^{im}\right)}\]
| Alternative 31 |
|---|
| Error | 43.9 |
|---|
| Cost | 32512 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \log \left(e^{e^{-im} - e^{im}}\right)\]
| Alternative 32 |
|---|
| Error | 0.7 |
|---|
| Cost | 27072 |
|---|
\[\sin re \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot -0.16666666666666666\right) - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
| Alternative 33 |
|---|
| Error | 0.8 |
|---|
| Cost | 26560 |
|---|
\[\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333\right)\]
| Alternative 34 |
|---|
| Error | 43.5 |
|---|
| Cost | 26304 |
|---|
\[\frac{\sin re \cdot 0.5}{e^{im}} + e^{im} \cdot \left(\sin re \cdot -0.5\right)\]
| Alternative 35 |
|---|
| Error | 43.5 |
|---|
| Cost | 19712 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\]
| Alternative 36 |
|---|
| Error | 0.9 |
|---|
| Cost | 13568 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \left(im \cdot -2 - {im}^{3} \cdot 0.3333333333333333\right)\]
| Alternative 37 |
|---|
| Error | 0.9 |
|---|
| Cost | 13312 |
|---|
\[\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\]
| Alternative 38 |
|---|
| Error | 44.8 |
|---|
| Cost | 13312 |
|---|
\[re \cdot \left(0.5 \cdot \left(e^{-im} - e^{im}\right)\right)\]
| Alternative 39 |
|---|
| Error | 1.2 |
|---|
| Cost | 6848 |
|---|
\[\left(\sin re \cdot 0.5\right) \cdot \left(im \cdot -2\right)\]
| Alternative 40 |
|---|
| Error | 1.2 |
|---|
| Cost | 6656 |
|---|
\[\sin re \cdot \left(-im\right)\]
| Alternative 41 |
|---|
| Error | 61.8 |
|---|
| Cost | 64 |
|---|
\[1\]
| Alternative 42 |
|---|
| Error | 45.9 |
|---|
| Cost | 64 |
|---|
\[0\]
| Alternative 43 |
|---|
| Error | 61.7 |
|---|
| Cost | 64 |
|---|
\[-1\]
Error

Derivation
Initial program 43.5
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
Taylor expanded around 0 0.7
\[\leadsto \color{blue}{-\left(0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right) + \left(\sin re \cdot im + \left(0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)\right)}\]
Simplified0.7
\[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) - {im}^{3} \cdot 0.16666666666666666\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)}\]
Simplified0.7
\[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)}\]
Final simplification0.7
\[\leadsto \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) - \sin re \cdot \left({im}^{5} \cdot 0.008333333333333333 + {im}^{7} \cdot 0.0001984126984126984\right)\]
Reproduce
herbie shell --seed 2021022
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
:herbie-target
(if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))