Average Error: 43.3 → 0.8
Time: 37.3s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[-\left(\sin re \cdot \left(1.0 \cdot im + \left(\left(im \cdot im\right) \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.008333333333333333\right) + \left(\sin re \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.16666666666666666\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
-\left(\sin re \cdot \left(1.0 \cdot im + \left(\left(im \cdot im\right) \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.008333333333333333\right) + \left(\sin re \cdot \left(im \cdot \left(im \cdot im\right)\right)\right) \cdot 0.16666666666666666\right)
double f(double re, double im) {
        double r9921533 = 0.5;
        double r9921534 = re;
        double r9921535 = sin(r9921534);
        double r9921536 = r9921533 * r9921535;
        double r9921537 = im;
        double r9921538 = -r9921537;
        double r9921539 = exp(r9921538);
        double r9921540 = exp(r9921537);
        double r9921541 = r9921539 - r9921540;
        double r9921542 = r9921536 * r9921541;
        return r9921542;
}

double f(double re, double im) {
        double r9921543 = re;
        double r9921544 = sin(r9921543);
        double r9921545 = 1.0;
        double r9921546 = im;
        double r9921547 = r9921545 * r9921546;
        double r9921548 = r9921546 * r9921546;
        double r9921549 = r9921546 * r9921548;
        double r9921550 = r9921548 * r9921549;
        double r9921551 = 0.008333333333333333;
        double r9921552 = r9921550 * r9921551;
        double r9921553 = r9921547 + r9921552;
        double r9921554 = r9921544 * r9921553;
        double r9921555 = r9921544 * r9921549;
        double r9921556 = 0.16666666666666666;
        double r9921557 = r9921555 * r9921556;
        double r9921558 = r9921554 + r9921557;
        double r9921559 = -r9921558;
        return r9921559;
}

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

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

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

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

Reproduce

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