Average Error: 43.6 → 0.8
Time: 9.4s
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 r488557 = 0.5;
        double r488558 = re;
        double r488559 = sin(r488558);
        double r488560 = r488557 * r488559;
        double r488561 = im;
        double r488562 = -r488561;
        double r488563 = exp(r488562);
        double r488564 = exp(r488561);
        double r488565 = r488563 - r488564;
        double r488566 = r488560 * r488565;
        return r488566;
}

double f(double re, double im) {
        double r488567 = 0.5;
        double r488568 = re;
        double r488569 = sin(r488568);
        double r488570 = r488567 * r488569;
        double r488571 = im;
        double r488572 = 3.0;
        double r488573 = pow(r488571, r488572);
        double r488574 = r488570 * r488573;
        double r488575 = -0.3333333333333333;
        double r488576 = r488574 * r488575;
        double r488577 = 0.016666666666666666;
        double r488578 = 5.0;
        double r488579 = pow(r488571, r488578);
        double r488580 = r488577 * r488579;
        double r488581 = 2.0;
        double r488582 = r488581 * r488571;
        double r488583 = r488580 + r488582;
        double r488584 = -r488583;
        double r488585 = r488570 * r488584;
        double r488586 = r488576 + r488585;
        return r488586;
}

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.6
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.6

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