Average Error: 44.2 → 0.7
Time: 24.2s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left({im}^{3} \cdot \frac{-1}{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left({im}^{3} \cdot \frac{-1}{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r257245 = 0.5;
        double r257246 = re;
        double r257247 = sin(r257246);
        double r257248 = r257245 * r257247;
        double r257249 = im;
        double r257250 = -r257249;
        double r257251 = exp(r257250);
        double r257252 = exp(r257249);
        double r257253 = r257251 - r257252;
        double r257254 = r257248 * r257253;
        return r257254;
}

double f(double re, double im) {
        double r257255 = 0.5;
        double r257256 = re;
        double r257257 = sin(r257256);
        double r257258 = r257255 * r257257;
        double r257259 = im;
        double r257260 = 3.0;
        double r257261 = pow(r257259, r257260);
        double r257262 = -0.3333333333333333;
        double r257263 = r257261 * r257262;
        double r257264 = 0.016666666666666666;
        double r257265 = 5.0;
        double r257266 = pow(r257259, r257265);
        double r257267 = r257264 * r257266;
        double r257268 = 2.0;
        double r257269 = r257268 * r257259;
        double r257270 = r257267 + r257269;
        double r257271 = r257263 - r257270;
        double r257272 = r257258 * r257271;
        return r257272;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original44.2
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \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 44.2

    \[\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}{\left({im}^{3} \cdot \frac{-1}{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)}\]
  4. Final simplification0.7

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left({im}^{3} \cdot \frac{-1}{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\]

Reproduce

herbie shell --seed 2019212 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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