Average Error: 43.3 → 0.8
Time: 34.8s
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 r164000 = 0.5;
        double r164001 = re;
        double r164002 = sin(r164001);
        double r164003 = r164000 * r164002;
        double r164004 = im;
        double r164005 = -r164004;
        double r164006 = exp(r164005);
        double r164007 = exp(r164004);
        double r164008 = r164006 - r164007;
        double r164009 = r164003 * r164008;
        return r164009;
}

double f(double re, double im) {
        double r164010 = 0.5;
        double r164011 = re;
        double r164012 = sin(r164011);
        double r164013 = r164010 * r164012;
        double r164014 = -0.3333333333333333;
        double r164015 = im;
        double r164016 = 3.0;
        double r164017 = pow(r164015, r164016);
        double r164018 = r164014 * r164017;
        double r164019 = 0.016666666666666666;
        double r164020 = 5.0;
        double r164021 = pow(r164015, r164020);
        double r164022 = r164019 * r164021;
        double r164023 = 2.0;
        double r164024 = r164023 * r164015;
        double r164025 = r164022 + r164024;
        double r164026 = r164018 - r164025;
        double r164027 = r164013 * r164026;
        return r164027;
}

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))))