Average Error: 58.1 → 0.7
Time: 10.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(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\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(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r368554 = 0.5;
        double r368555 = re;
        double r368556 = cos(r368555);
        double r368557 = r368554 * r368556;
        double r368558 = 0.0;
        double r368559 = im;
        double r368560 = r368558 - r368559;
        double r368561 = exp(r368560);
        double r368562 = exp(r368559);
        double r368563 = r368561 - r368562;
        double r368564 = r368557 * r368563;
        return r368564;
}

double f(double re, double im) {
        double r368565 = 0.5;
        double r368566 = re;
        double r368567 = cos(r368566);
        double r368568 = r368565 * r368567;
        double r368569 = 0.3333333333333333;
        double r368570 = im;
        double r368571 = 3.0;
        double r368572 = pow(r368570, r368571);
        double r368573 = r368569 * r368572;
        double r368574 = -r368573;
        double r368575 = 0.016666666666666666;
        double r368576 = 5.0;
        double r368577 = pow(r368570, r368576);
        double r368578 = 2.0;
        double r368579 = r368578 * r368570;
        double r368580 = fma(r368575, r368577, r368579);
        double r368581 = r368574 - r368580;
        double r368582 = r368568 * r368581;
        return r368582;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.7
\[\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. Taylor expanded around 0 0.7

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

    \[\leadsto \left(0.5 \cdot \cos 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. Final simplification0.7

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

Reproduce

herbie shell --seed 2019354 +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.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))))