Average Error: 43.7 → 0.7
Time: 10.2s
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(im \cdot -2 - \left(\frac{1}{3} \cdot {im}^{3} + \frac{1}{60} \cdot {im}^{5}\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(im \cdot -2 - \left(\frac{1}{3} \cdot {im}^{3} + \frac{1}{60} \cdot {im}^{5}\right)\right)
double f(double re, double im) {
        double r389334 = 0.5;
        double r389335 = re;
        double r389336 = sin(r389335);
        double r389337 = r389334 * r389336;
        double r389338 = im;
        double r389339 = -r389338;
        double r389340 = exp(r389339);
        double r389341 = exp(r389338);
        double r389342 = r389340 - r389341;
        double r389343 = r389337 * r389342;
        return r389343;
}

double f(double re, double im) {
        double r389344 = 0.5;
        double r389345 = re;
        double r389346 = sin(r389345);
        double r389347 = r389344 * r389346;
        double r389348 = im;
        double r389349 = -2.0;
        double r389350 = r389348 * r389349;
        double r389351 = 0.3333333333333333;
        double r389352 = 3.0;
        double r389353 = pow(r389348, r389352);
        double r389354 = r389351 * r389353;
        double r389355 = 0.016666666666666666;
        double r389356 = 5.0;
        double r389357 = pow(r389348, r389356);
        double r389358 = r389355 * r389357;
        double r389359 = r389354 + r389358;
        double r389360 = r389350 - r389359;
        double r389361 = r389347 * r389360;
        return r389361;
}

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

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

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

Reproduce

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