Average Error: 58.0 → 0.8
Time: 36.6s
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 r167508 = 0.5;
        double r167509 = re;
        double r167510 = cos(r167509);
        double r167511 = r167508 * r167510;
        double r167512 = 0.0;
        double r167513 = im;
        double r167514 = r167512 - r167513;
        double r167515 = exp(r167514);
        double r167516 = exp(r167513);
        double r167517 = r167515 - r167516;
        double r167518 = r167511 * r167517;
        return r167518;
}

double f(double re, double im) {
        double r167519 = 0.5;
        double r167520 = re;
        double r167521 = cos(r167520);
        double r167522 = r167519 * r167521;
        double r167523 = 0.3333333333333333;
        double r167524 = im;
        double r167525 = 3.0;
        double r167526 = pow(r167524, r167525);
        double r167527 = 0.016666666666666666;
        double r167528 = 5.0;
        double r167529 = pow(r167524, r167528);
        double r167530 = 2.0;
        double r167531 = r167530 * r167524;
        double r167532 = fma(r167527, r167529, r167531);
        double r167533 = fma(r167523, r167526, r167532);
        double r167534 = -r167533;
        double r167535 = r167522 * r167534;
        return r167535;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
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.0

    \[\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 2019325 +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))))