Average Error: 43.4 → 0.7
Time: 9.1s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(\sqrt[3]{-\frac{1}{3} \cdot {im}^{3}} \cdot \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}, \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}, -\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(\sqrt[3]{-\frac{1}{3} \cdot {im}^{3}} \cdot \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}, \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}, -\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r211667 = 0.5;
        double r211668 = re;
        double r211669 = sin(r211668);
        double r211670 = r211667 * r211669;
        double r211671 = im;
        double r211672 = -r211671;
        double r211673 = exp(r211672);
        double r211674 = exp(r211671);
        double r211675 = r211673 - r211674;
        double r211676 = r211670 * r211675;
        return r211676;
}

double f(double re, double im) {
        double r211677 = 0.5;
        double r211678 = re;
        double r211679 = sin(r211678);
        double r211680 = r211677 * r211679;
        double r211681 = 0.3333333333333333;
        double r211682 = im;
        double r211683 = 3.0;
        double r211684 = pow(r211682, r211683);
        double r211685 = r211681 * r211684;
        double r211686 = -r211685;
        double r211687 = cbrt(r211686);
        double r211688 = r211687 * r211687;
        double r211689 = 0.016666666666666666;
        double r211690 = 5.0;
        double r211691 = pow(r211682, r211690);
        double r211692 = 2.0;
        double r211693 = r211692 * r211682;
        double r211694 = fma(r211689, r211691, r211693);
        double r211695 = -r211694;
        double r211696 = fma(r211688, r211687, r211695);
        double r211697 = r211680 * r211696;
        return r211697;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.4
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.4

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

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\]
  4. Using strategy rm
  5. Applied add-cube-cbrt0.7

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\color{blue}{\left(\sqrt[3]{-\frac{1}{3} \cdot {im}^{3}} \cdot \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}\right) \cdot \sqrt[3]{-\frac{1}{3} \cdot {im}^{3}}} - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
  6. Applied fma-neg0.7

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

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

Reproduce

herbie shell --seed 2019344 +o rules:numerics
(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))))