Average Error: 58.0 → 0.8
Time: 24.7s
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 r137575 = 0.5;
        double r137576 = re;
        double r137577 = cos(r137576);
        double r137578 = r137575 * r137577;
        double r137579 = 0.0;
        double r137580 = im;
        double r137581 = r137579 - r137580;
        double r137582 = exp(r137581);
        double r137583 = exp(r137580);
        double r137584 = r137582 - r137583;
        double r137585 = r137578 * r137584;
        return r137585;
}

double f(double re, double im) {
        double r137586 = 0.5;
        double r137587 = 0.016666666666666666;
        double r137588 = im;
        double r137589 = 5.0;
        double r137590 = pow(r137588, r137589);
        double r137591 = 2.0;
        double r137592 = 0.3333333333333333;
        double r137593 = 3.0;
        double r137594 = pow(r137588, r137593);
        double r137595 = r137592 * r137594;
        double r137596 = fma(r137591, r137588, r137595);
        double r137597 = fma(r137587, r137590, r137596);
        double r137598 = r137586 * r137597;
        double r137599 = re;
        double r137600 = cos(r137599);
        double r137601 = -r137600;
        double r137602 = r137598 * r137601;
        return r137602;
}

Error

Bits error versus re

Bits error versus im

Target

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

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

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