Average Error: 43.3 → 0.8
Time: 8.8s
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 r234226 = 0.5;
        double r234227 = re;
        double r234228 = sin(r234227);
        double r234229 = r234226 * r234228;
        double r234230 = im;
        double r234231 = -r234230;
        double r234232 = exp(r234231);
        double r234233 = exp(r234230);
        double r234234 = r234232 - r234233;
        double r234235 = r234229 * r234234;
        return r234235;
}

double f(double re, double im) {
        double r234236 = 0.5;
        double r234237 = re;
        double r234238 = sin(r234237);
        double r234239 = r234236 * r234238;
        double r234240 = im;
        double r234241 = 3.0;
        double r234242 = pow(r234240, r234241);
        double r234243 = r234239 * r234242;
        double r234244 = -0.3333333333333333;
        double r234245 = r234243 * r234244;
        double r234246 = 0.016666666666666666;
        double r234247 = 5.0;
        double r234248 = pow(r234240, r234247);
        double r234249 = r234246 * r234248;
        double r234250 = 2.0;
        double r234251 = r234250 * r234240;
        double r234252 = r234249 + r234251;
        double r234253 = -r234252;
        double r234254 = r234239 * r234253;
        double r234255 = r234245 + r234254;
        return r234255;
}

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(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 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. 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 2020056 
(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))))