Average Error: 57.9 → 0.5
Time: 11.9s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right) \le -0.190683920025477987580941885426000226289:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \frac{e^{\left(0.0 - im\right) + \left(0.0 - im\right)} + \left(-e^{im + im}\right)}{e^{0.0 - im} + e^{im}}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)\\ \end{array}\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right) \le -0.190683920025477987580941885426000226289:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \frac{e^{\left(0.0 - im\right) + \left(0.0 - im\right)} + \left(-e^{im + im}\right)}{e^{0.0 - im} + e^{im}}\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)\\

\end{array}
double f(double re, double im) {
        double r440611 = 0.5;
        double r440612 = re;
        double r440613 = cos(r440612);
        double r440614 = r440611 * r440613;
        double r440615 = 0.0;
        double r440616 = im;
        double r440617 = r440615 - r440616;
        double r440618 = exp(r440617);
        double r440619 = exp(r440616);
        double r440620 = r440618 - r440619;
        double r440621 = r440614 * r440620;
        return r440621;
}

double f(double re, double im) {
        double r440622 = 0.5;
        double r440623 = re;
        double r440624 = cos(r440623);
        double r440625 = r440622 * r440624;
        double r440626 = 0.0;
        double r440627 = im;
        double r440628 = r440626 - r440627;
        double r440629 = exp(r440628);
        double r440630 = exp(r440627);
        double r440631 = r440629 - r440630;
        double r440632 = r440625 * r440631;
        double r440633 = -0.190683920025478;
        bool r440634 = r440632 <= r440633;
        double r440635 = r440628 + r440628;
        double r440636 = exp(r440635);
        double r440637 = r440627 + r440627;
        double r440638 = exp(r440637);
        double r440639 = -r440638;
        double r440640 = r440636 + r440639;
        double r440641 = r440629 + r440630;
        double r440642 = r440640 / r440641;
        double r440643 = r440625 * r440642;
        double r440644 = 0.3333333333333333;
        double r440645 = 3.0;
        double r440646 = pow(r440627, r440645);
        double r440647 = r440644 * r440646;
        double r440648 = 0.016666666666666666;
        double r440649 = 5.0;
        double r440650 = pow(r440627, r440649);
        double r440651 = r440648 * r440650;
        double r440652 = 2.0;
        double r440653 = r440652 * r440627;
        double r440654 = r440651 + r440653;
        double r440655 = r440647 + r440654;
        double r440656 = -r440655;
        double r440657 = r440625 * r440656;
        double r440658 = r440634 ? r440643 : r440657;
        return r440658;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original57.9
Target0.2
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) < -0.190683920025478

    1. Initial program 0.3

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
    2. Using strategy rm
    3. Applied flip--2.9

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\frac{e^{0.0 - im} \cdot e^{0.0 - im} - e^{im} \cdot e^{im}}{e^{0.0 - im} + e^{im}}}\]
    4. Simplified2.9

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \frac{\color{blue}{e^{\left(0.0 - im\right) + \left(0.0 - im\right)} + \left(-e^{im + im}\right)}}{e^{0.0 - im} + e^{im}}\]

    if -0.190683920025478 < (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))

    1. Initial program 58.3

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
    2. Taylor expanded around 0 0.5

      \[\leadsto \left(0.5 \cdot \cos 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. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right) \le -0.190683920025477987580941885426000226289:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \frac{e^{\left(0.0 - im\right) + \left(0.0 - im\right)} + \left(-e^{im + im}\right)}{e^{0.0 - im} + e^{im}}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019362 
(FPCore (re im)
  :name "math.sin on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))