Average Error: 42.9 → 0.8
Time: 9.9s
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 r213832 = 0.5;
        double r213833 = re;
        double r213834 = sin(r213833);
        double r213835 = r213832 * r213834;
        double r213836 = im;
        double r213837 = -r213836;
        double r213838 = exp(r213837);
        double r213839 = exp(r213836);
        double r213840 = r213838 - r213839;
        double r213841 = r213835 * r213840;
        return r213841;
}

double f(double re, double im) {
        double r213842 = 0.5;
        double r213843 = re;
        double r213844 = sin(r213843);
        double r213845 = r213842 * r213844;
        double r213846 = 0.3333333333333333;
        double r213847 = im;
        double r213848 = 3.0;
        double r213849 = pow(r213847, r213848);
        double r213850 = r213846 * r213849;
        double r213851 = 0.016666666666666666;
        double r213852 = 5.0;
        double r213853 = pow(r213847, r213852);
        double r213854 = r213851 * r213853;
        double r213855 = 2.0;
        double r213856 = r213855 * r213847;
        double r213857 = r213854 + r213856;
        double r213858 = r213850 + r213857;
        double r213859 = -r213858;
        double r213860 = r213845 * r213859;
        return r213860;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original42.9
Target0.3
Herbie0.8
\[\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 42.9

    \[\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 2020047 
(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))))