Average Error: 44.2 → 0.8
Time: 8.5s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(0.5 \cdot \sin re\right) \cdot {im}^{3}\right) \cdot \frac{-1}{3} + \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(0.5 \cdot \sin re\right) \cdot {im}^{3}\right) \cdot \frac{-1}{3} + \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r229867 = 0.5;
        double r229868 = re;
        double r229869 = sin(r229868);
        double r229870 = r229867 * r229869;
        double r229871 = im;
        double r229872 = -r229871;
        double r229873 = exp(r229872);
        double r229874 = exp(r229871);
        double r229875 = r229873 - r229874;
        double r229876 = r229870 * r229875;
        return r229876;
}

double f(double re, double im) {
        double r229877 = 0.5;
        double r229878 = re;
        double r229879 = sin(r229878);
        double r229880 = r229877 * r229879;
        double r229881 = im;
        double r229882 = 3.0;
        double r229883 = pow(r229881, r229882);
        double r229884 = r229880 * r229883;
        double r229885 = -0.3333333333333333;
        double r229886 = r229884 * r229885;
        double r229887 = 0.016666666666666666;
        double r229888 = 5.0;
        double r229889 = pow(r229881, r229888);
        double r229890 = r229887 * r229889;
        double r229891 = 2.0;
        double r229892 = r229891 * r229881;
        double r229893 = r229890 + r229892;
        double r229894 = -r229893;
        double r229895 = r229880 * r229894;
        double r229896 = r229886 + r229895;
        return r229896;
}

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.2
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 44.2

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

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

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

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

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

Reproduce

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