Average Error: 44.1 → 0.8
Time: 9.7s
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(\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right) + \frac{1}{3} \cdot {im}^{3}\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(-0.5 \cdot \sin re\right) \cdot \left(\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right) + \frac{1}{3} \cdot {im}^{3}\right)
double f(double re, double im) {
        double r158416 = 0.5;
        double r158417 = re;
        double r158418 = sin(r158417);
        double r158419 = r158416 * r158418;
        double r158420 = im;
        double r158421 = -r158420;
        double r158422 = exp(r158421);
        double r158423 = exp(r158420);
        double r158424 = r158422 - r158423;
        double r158425 = r158419 * r158424;
        return r158425;
}

double f(double re, double im) {
        double r158426 = 0.5;
        double r158427 = re;
        double r158428 = sin(r158427);
        double r158429 = r158426 * r158428;
        double r158430 = -r158429;
        double r158431 = 0.016666666666666666;
        double r158432 = im;
        double r158433 = 5.0;
        double r158434 = pow(r158432, r158433);
        double r158435 = r158431 * r158434;
        double r158436 = 2.0;
        double r158437 = r158436 * r158432;
        double r158438 = r158435 + r158437;
        double r158439 = 0.3333333333333333;
        double r158440 = 3.0;
        double r158441 = pow(r158432, r158440);
        double r158442 = r158439 * r158441;
        double r158443 = r158438 + r158442;
        double r158444 = r158430 * r158443;
        return r158444;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original44.1
Target0.3
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 44.1

    \[\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. Using strategy rm
  4. Applied *-un-lft-identity0.8

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

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

Reproduce

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