Average Error: 58.2 → 0.4
Time: 32.5s
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 9.28429385085305 \cdot 10^{-4}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{0.0 - im} \cdot \left(0.5 \cdot \cos re\right) + \left(-e^{im}\right) \cdot \left(0.5 \cdot \cos re\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 9.28429385085305 \cdot 10^{-4}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3} - \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;e^{0.0 - im} \cdot \left(0.5 \cdot \cos re\right) + \left(-e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)\\

\end{array}
double f(double re, double im) {
        double r334428 = 0.5;
        double r334429 = re;
        double r334430 = cos(r334429);
        double r334431 = r334428 * r334430;
        double r334432 = 0.0;
        double r334433 = im;
        double r334434 = r334432 - r334433;
        double r334435 = exp(r334434);
        double r334436 = exp(r334433);
        double r334437 = r334435 - r334436;
        double r334438 = r334431 * r334437;
        return r334438;
}

double f(double re, double im) {
        double r334439 = 0.5;
        double r334440 = re;
        double r334441 = cos(r334440);
        double r334442 = r334439 * r334441;
        double r334443 = 0.0;
        double r334444 = im;
        double r334445 = r334443 - r334444;
        double r334446 = exp(r334445);
        double r334447 = exp(r334444);
        double r334448 = r334446 - r334447;
        double r334449 = r334442 * r334448;
        double r334450 = 0.0009284293850853054;
        bool r334451 = r334449 <= r334450;
        double r334452 = -0.3333333333333333;
        double r334453 = 3.0;
        double r334454 = pow(r334444, r334453);
        double r334455 = r334452 * r334454;
        double r334456 = 0.016666666666666666;
        double r334457 = 5.0;
        double r334458 = pow(r334444, r334457);
        double r334459 = r334456 * r334458;
        double r334460 = 2.0;
        double r334461 = r334460 * r334444;
        double r334462 = r334459 + r334461;
        double r334463 = r334455 - r334462;
        double r334464 = r334442 * r334463;
        double r334465 = r334446 * r334442;
        double r334466 = -r334447;
        double r334467 = r334466 * r334442;
        double r334468 = r334465 + r334467;
        double r334469 = r334451 ? r334464 : r334468;
        return r334469;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.2
Target0.2
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos 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 \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.0009284293850853054

    1. Initial program 58.6

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

      \[\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. Simplified0.4

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

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

    1. Initial program 2.0

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(e^{0.0 - im} + \left(-e^{im}\right)\right)}\]
    4. Applied distribute-lft-in2.1

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

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

      \[\leadsto e^{0.0 - im} \cdot \left(0.5 \cdot \cos re\right) + \color{blue}{\left(-e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (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))))