Average Error: 43.2 → 0.8
Time: 27.0s
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(\frac{-1}{3} \cdot {im}^{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(\frac{-1}{3} \cdot {im}^{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r126127 = 0.5;
        double r126128 = re;
        double r126129 = sin(r126128);
        double r126130 = r126127 * r126129;
        double r126131 = im;
        double r126132 = -r126131;
        double r126133 = exp(r126132);
        double r126134 = exp(r126131);
        double r126135 = r126133 - r126134;
        double r126136 = r126130 * r126135;
        return r126136;
}

double f(double re, double im) {
        double r126137 = 0.5;
        double r126138 = re;
        double r126139 = sin(r126138);
        double r126140 = r126137 * r126139;
        double r126141 = -0.3333333333333333;
        double r126142 = im;
        double r126143 = 3.0;
        double r126144 = pow(r126142, r126143);
        double r126145 = r126141 * r126144;
        double r126146 = 0.016666666666666666;
        double r126147 = 5.0;
        double r126148 = pow(r126142, r126147);
        double r126149 = r126146 * r126148;
        double r126150 = 2.0;
        double r126151 = r126150 * r126142;
        double r126152 = r126149 + r126151;
        double r126153 = r126145 - r126152;
        double r126154 = r126140 * r126153;
        return r126154;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.2
Target0.3
Herbie0.8
\[\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 43.2

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

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

Reproduce

herbie shell --seed 2019303 
(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))))