Average Error: 58.2 → 0.6
Time: 1.0m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left({im}^{5} \cdot \frac{-1}{60} - im \cdot \left(2 + im \cdot \left(\frac{1}{3} \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r51760537 = 0.5;
        double r51760538 = re;
        double r51760539 = cos(r51760538);
        double r51760540 = r51760537 * r51760539;
        double r51760541 = 0.0;
        double r51760542 = im;
        double r51760543 = r51760541 - r51760542;
        double r51760544 = exp(r51760543);
        double r51760545 = exp(r51760542);
        double r51760546 = r51760544 - r51760545;
        double r51760547 = r51760540 * r51760546;
        return r51760547;
}

double f(double re, double im) {
        double r51760548 = im;
        double r51760549 = 5.0;
        double r51760550 = pow(r51760548, r51760549);
        double r51760551 = -0.016666666666666666;
        double r51760552 = r51760550 * r51760551;
        double r51760553 = 2.0;
        double r51760554 = 0.3333333333333333;
        double r51760555 = r51760554 * r51760548;
        double r51760556 = r51760548 * r51760555;
        double r51760557 = r51760553 + r51760556;
        double r51760558 = r51760548 * r51760557;
        double r51760559 = r51760552 - r51760558;
        double r51760560 = 0.5;
        double r51760561 = re;
        double r51760562 = cos(r51760561);
        double r51760563 = r51760560 * r51760562;
        double r51760564 = r51760559 * r51760563;
        return r51760564;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.2
Target0.2
Herbie0.6
\[\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.2

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

    \[\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.6

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\frac{-1}{60} \cdot {im}^{5} - \left(\left(\frac{1}{3} \cdot im\right) \cdot im + 2\right) \cdot im\right)}\]
  4. Final simplification0.6

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

Reproduce

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