Average Error: 43.1 → 0.8
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(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\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(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)
double f(double re, double im) {
        double r478864 = 0.5;
        double r478865 = re;
        double r478866 = sin(r478865);
        double r478867 = r478864 * r478866;
        double r478868 = im;
        double r478869 = -r478868;
        double r478870 = exp(r478869);
        double r478871 = exp(r478868);
        double r478872 = r478870 - r478871;
        double r478873 = r478867 * r478872;
        return r478873;
}

double f(double re, double im) {
        double r478874 = 0.5;
        double r478875 = re;
        double r478876 = sin(r478875);
        double r478877 = r478874 * r478876;
        double r478878 = 0.3333333333333333;
        double r478879 = im;
        double r478880 = 3.0;
        double r478881 = pow(r478879, r478880);
        double r478882 = r478878 * r478881;
        double r478883 = 0.016666666666666666;
        double r478884 = 5.0;
        double r478885 = pow(r478879, r478884);
        double r478886 = r478883 * r478885;
        double r478887 = 2.0;
        double r478888 = r478887 * r478879;
        double r478889 = r478886 + r478888;
        double r478890 = r478882 + r478889;
        double r478891 = -r478890;
        double r478892 = r478877 * r478891;
        return r478892;
}

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.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 43.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. Final simplification0.8

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

Reproduce

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