Average Error: 43.4 → 0.7
Time: 1.3m
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(-im \cdot im\right) \cdot im\right) \cdot \left(\sin re \cdot 0.16666666666666666\right) - \left(1.0 \cdot im + {im}^{5} \cdot 0.008333333333333333\right) \cdot \sin re\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(-im \cdot im\right) \cdot im\right) \cdot \left(\sin re \cdot 0.16666666666666666\right) - \left(1.0 \cdot im + {im}^{5} \cdot 0.008333333333333333\right) \cdot \sin re
double f(double re, double im) {
        double r43497256 = 0.5;
        double r43497257 = re;
        double r43497258 = sin(r43497257);
        double r43497259 = r43497256 * r43497258;
        double r43497260 = im;
        double r43497261 = -r43497260;
        double r43497262 = exp(r43497261);
        double r43497263 = exp(r43497260);
        double r43497264 = r43497262 - r43497263;
        double r43497265 = r43497259 * r43497264;
        return r43497265;
}

double f(double re, double im) {
        double r43497266 = im;
        double r43497267 = r43497266 * r43497266;
        double r43497268 = -r43497267;
        double r43497269 = r43497268 * r43497266;
        double r43497270 = re;
        double r43497271 = sin(r43497270);
        double r43497272 = 0.16666666666666666;
        double r43497273 = r43497271 * r43497272;
        double r43497274 = r43497269 * r43497273;
        double r43497275 = 1.0;
        double r43497276 = r43497275 * r43497266;
        double r43497277 = 5.0;
        double r43497278 = pow(r43497266, r43497277);
        double r43497279 = 0.008333333333333333;
        double r43497280 = r43497278 * r43497279;
        double r43497281 = r43497276 + r43497280;
        double r43497282 = r43497281 * r43497271;
        double r43497283 = r43497274 - r43497282;
        return r43497283;
}

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.4
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.4

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

    \[\leadsto \color{blue}{-\left(0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1.0 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{\left(\left(-im\right) \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \sin re\right) - \sin re \cdot \left(0.008333333333333333 \cdot {im}^{5} + 1.0 \cdot im\right)}\]
  6. Final simplification0.7

    \[\leadsto \left(\left(-im \cdot im\right) \cdot im\right) \cdot \left(\sin re \cdot 0.16666666666666666\right) - \left(1.0 \cdot im + {im}^{5} \cdot 0.008333333333333333\right) \cdot \sin re\]

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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