Average Error: 58.1 → 0.8
Time: 25.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, \mathsf{fma}\left(2, im, \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(-\cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, \mathsf{fma}\left(2, im, \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(-\cos re\right)
double f(double re, double im) {
        double r99157 = 0.5;
        double r99158 = re;
        double r99159 = cos(r99158);
        double r99160 = r99157 * r99159;
        double r99161 = 0.0;
        double r99162 = im;
        double r99163 = r99161 - r99162;
        double r99164 = exp(r99163);
        double r99165 = exp(r99162);
        double r99166 = r99164 - r99165;
        double r99167 = r99160 * r99166;
        return r99167;
}

double f(double re, double im) {
        double r99168 = 0.5;
        double r99169 = 0.016666666666666666;
        double r99170 = im;
        double r99171 = 5.0;
        double r99172 = pow(r99170, r99171);
        double r99173 = 2.0;
        double r99174 = 0.3333333333333333;
        double r99175 = 3.0;
        double r99176 = pow(r99170, r99175);
        double r99177 = r99174 * r99176;
        double r99178 = fma(r99173, r99170, r99177);
        double r99179 = fma(r99169, r99172, r99178);
        double r99180 = r99168 * r99179;
        double r99181 = re;
        double r99182 = cos(r99181);
        double r99183 = -r99182;
        double r99184 = r99180 * r99183;
        return r99184;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.8
\[\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. Initial program 58.1

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

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

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

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

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

Reproduce

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