Average Error: 57.8 → 0.8
Time: 31.2s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)
double f(double re, double im) {
        double r197509 = 0.5;
        double r197510 = re;
        double r197511 = cos(r197510);
        double r197512 = r197509 * r197511;
        double r197513 = 0.0;
        double r197514 = im;
        double r197515 = r197513 - r197514;
        double r197516 = exp(r197515);
        double r197517 = exp(r197514);
        double r197518 = r197516 - r197517;
        double r197519 = r197512 * r197518;
        return r197519;
}

double f(double re, double im) {
        double r197520 = 0.5;
        double r197521 = re;
        double r197522 = cos(r197521);
        double r197523 = r197520 * r197522;
        double r197524 = 0.3333333333333333;
        double r197525 = im;
        double r197526 = 3.0;
        double r197527 = pow(r197525, r197526);
        double r197528 = 0.016666666666666666;
        double r197529 = 5.0;
        double r197530 = pow(r197525, r197529);
        double r197531 = 2.0;
        double r197532 = r197531 * r197525;
        double r197533 = fma(r197528, r197530, r197532);
        double r197534 = fma(r197524, r197527, r197533);
        double r197535 = -r197534;
        double r197536 = r197523 * r197535;
        return r197536;
}

Error

Bits error versus re

Bits error versus im

Target

Original57.8
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 57.8

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

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

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 0.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 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))))