Average Error: 43.3 → 0.8
Time: 33.3s
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 r186451 = 0.5;
        double r186452 = re;
        double r186453 = sin(r186452);
        double r186454 = r186451 * r186453;
        double r186455 = im;
        double r186456 = -r186455;
        double r186457 = exp(r186456);
        double r186458 = exp(r186455);
        double r186459 = r186457 - r186458;
        double r186460 = r186454 * r186459;
        return r186460;
}

double f(double re, double im) {
        double r186461 = 0.5;
        double r186462 = re;
        double r186463 = sin(r186462);
        double r186464 = r186461 * r186463;
        double r186465 = -0.3333333333333333;
        double r186466 = im;
        double r186467 = 3.0;
        double r186468 = pow(r186466, r186467);
        double r186469 = r186465 * r186468;
        double r186470 = 0.016666666666666666;
        double r186471 = 5.0;
        double r186472 = pow(r186466, r186471);
        double r186473 = r186470 * r186472;
        double r186474 = 2.0;
        double r186475 = r186474 * r186466;
        double r186476 = r186473 + r186475;
        double r186477 = r186469 - r186476;
        double r186478 = r186464 * r186477;
        return r186478;
}

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.3
Target0.2
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.3

    \[\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 2019325 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (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))))