Average Error: 43.3 → 0.8
Time: 8.3s
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(\left(\frac{1}{60} \cdot {\left(\sqrt[3]{im} \cdot \sqrt[3]{im}\right)}^{5}\right) \cdot {\left(\sqrt[3]{im}\right)}^{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(\left(\frac{1}{60} \cdot {\left(\sqrt[3]{im} \cdot \sqrt[3]{im}\right)}^{5}\right) \cdot {\left(\sqrt[3]{im}\right)}^{5} + 2 \cdot im\right)\right)\right)
double f(double re, double im) {
        double r327565 = 0.5;
        double r327566 = re;
        double r327567 = sin(r327566);
        double r327568 = r327565 * r327567;
        double r327569 = im;
        double r327570 = -r327569;
        double r327571 = exp(r327570);
        double r327572 = exp(r327569);
        double r327573 = r327571 - r327572;
        double r327574 = r327568 * r327573;
        return r327574;
}

double f(double re, double im) {
        double r327575 = 0.5;
        double r327576 = re;
        double r327577 = sin(r327576);
        double r327578 = r327575 * r327577;
        double r327579 = 0.3333333333333333;
        double r327580 = im;
        double r327581 = 3.0;
        double r327582 = pow(r327580, r327581);
        double r327583 = r327579 * r327582;
        double r327584 = 0.016666666666666666;
        double r327585 = cbrt(r327580);
        double r327586 = r327585 * r327585;
        double r327587 = 5.0;
        double r327588 = pow(r327586, r327587);
        double r327589 = r327584 * r327588;
        double r327590 = pow(r327585, r327587);
        double r327591 = r327589 * r327590;
        double r327592 = 2.0;
        double r327593 = r327592 * r327580;
        double r327594 = r327591 + r327593;
        double r327595 = r327583 + r327594;
        double r327596 = -r327595;
        double r327597 = r327578 * r327596;
        return r327597;
}

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 add-cube-cbrt0.8

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot \color{blue}{\left({\left(\sqrt[3]{im} \cdot \sqrt[3]{im}\right)}^{5} \cdot {\left(\sqrt[3]{im}\right)}^{5}\right)} + 2 \cdot im\right)\right)\right)\]
  6. Applied associate-*r*0.8

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

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

Reproduce

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