Average Error: 58.0 → 27.9
Time: 34.0s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\begin{array}{l} \mathbf{if}\;\cos re \le -0.024407493522205715:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;\cos re \le 0.9991588276041066:\\ \;\;\;\;\left(\left(\sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}} \cdot \left(\sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}} \cdot \sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}}\right)\right) \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(re \cdot re\right) + \left(-2 - \left(im \cdot im\right) \cdot \frac{1}{3}\right) \cdot im\right)\\ \end{array}\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
\mathbf{if}\;\cos re \le -0.024407493522205715:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\\

\mathbf{elif}\;\cos re \le 0.9991588276041066:\\
\;\;\;\;\left(\left(\sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}} \cdot \left(\sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}} \cdot \sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}}\right)\right) \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}\right) \cdot 0.5\\

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

\end{array}
double f(double re, double im) {
        double r2073622 = 0.5;
        double r2073623 = re;
        double r2073624 = cos(r2073623);
        double r2073625 = r2073622 * r2073624;
        double r2073626 = 0.0;
        double r2073627 = im;
        double r2073628 = r2073626 - r2073627;
        double r2073629 = exp(r2073628);
        double r2073630 = exp(r2073627);
        double r2073631 = r2073629 - r2073630;
        double r2073632 = r2073625 * r2073631;
        return r2073632;
}

double f(double re, double im) {
        double r2073633 = re;
        double r2073634 = cos(r2073633);
        double r2073635 = -0.024407493522205715;
        bool r2073636 = r2073634 <= r2073635;
        double r2073637 = 0.5;
        double r2073638 = r2073634 * r2073637;
        double r2073639 = im;
        double r2073640 = -r2073639;
        double r2073641 = exp(r2073640);
        double r2073642 = exp(r2073639);
        double r2073643 = r2073641 - r2073642;
        double r2073644 = r2073638 * r2073643;
        double r2073645 = 0.9991588276041066;
        bool r2073646 = r2073634 <= r2073645;
        double r2073647 = -2.0;
        double r2073648 = r2073647 * r2073639;
        double r2073649 = 0.3333333333333333;
        double r2073650 = r2073639 * r2073639;
        double r2073651 = r2073639 * r2073650;
        double r2073652 = r2073649 * r2073651;
        double r2073653 = r2073648 - r2073652;
        double r2073654 = cbrt(r2073653);
        double r2073655 = r2073654 * r2073654;
        double r2073656 = cbrt(r2073655);
        double r2073657 = r2073656 * r2073656;
        double r2073658 = r2073656 * r2073657;
        double r2073659 = r2073658 * r2073654;
        double r2073660 = r2073659 * r2073637;
        double r2073661 = r2073633 * r2073633;
        double r2073662 = r2073639 * r2073661;
        double r2073663 = r2073650 * r2073649;
        double r2073664 = r2073647 - r2073663;
        double r2073665 = r2073664 * r2073639;
        double r2073666 = r2073662 + r2073665;
        double r2073667 = r2073637 * r2073666;
        double r2073668 = r2073646 ? r2073660 : r2073667;
        double r2073669 = r2073636 ? r2073644 : r2073668;
        return r2073669;
}

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.0
Target0.3
Herbie27.9
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \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 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (cos re) < -0.024407493522205715

    1. Initial program 57.9

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]

    if -0.024407493522205715 < (cos re) < 0.9991588276041066

    1. Initial program 58.4

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
    2. Simplified58.5

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{\cos re}{e^{im}} - \cos re \cdot e^{im}\right)}\]
    3. Taylor expanded around 0 62.4

      \[\leadsto 0.5 \cdot \color{blue}{\left({re}^{2} \cdot im - \left(\frac{1}{3} \cdot {im}^{3} + 2 \cdot im\right)\right)}\]
    4. Simplified62.4

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(re \cdot re - 2\right) - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)}\]
    5. Taylor expanded around 0 50.7

      \[\leadsto 0.5 \cdot \left(\color{blue}{-2 \cdot im} - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)\]
    6. Using strategy rm
    7. Applied add-cube-cbrt50.7

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}\right) \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}\right)}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt50.7

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(\left(\sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}} \cdot \sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}}\right) \cdot \sqrt[3]{\sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}}\right)} \cdot \sqrt[3]{-2 \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)}\right)\]

    if 0.9991588276041066 < (cos re)

    1. Initial program 57.9

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
    2. Simplified57.9

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{\cos re}{e^{im}} - \cos re \cdot e^{im}\right)}\]
    3. Taylor expanded around 0 1.8

      \[\leadsto 0.5 \cdot \color{blue}{\left({re}^{2} \cdot im - \left(\frac{1}{3} \cdot {im}^{3} + 2 \cdot im\right)\right)}\]
    4. Simplified1.8

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(re \cdot re - 2\right) - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)}\]
    5. Using strategy rm
    6. Applied sub-neg1.8

      \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(re \cdot re + \left(-2\right)\right)} - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)\]
    7. Applied distribute-rgt-in1.8

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(\left(re \cdot re\right) \cdot im + \left(-2\right) \cdot im\right)} - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)\]
    8. Applied associate--l+1.8

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(re \cdot re\right) \cdot im + \left(\left(-2\right) \cdot im - \frac{1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right)\right)}\]
    9. Simplified1.8

      \[\leadsto 0.5 \cdot \left(\left(re \cdot re\right) \cdot im + \color{blue}{im \cdot \left(-2 - \left(im \cdot im\right) \cdot \frac{1}{3}\right)}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification27.9

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

Reproduce

herbie shell --seed 2019139 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

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