Average Error: 58.1 → 0.7
Time: 31.0s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)
double f(double re, double im) {
        double r249269 = 0.5;
        double r249270 = re;
        double r249271 = cos(r249270);
        double r249272 = r249269 * r249271;
        double r249273 = 0.0;
        double r249274 = im;
        double r249275 = r249273 - r249274;
        double r249276 = exp(r249275);
        double r249277 = exp(r249274);
        double r249278 = r249276 - r249277;
        double r249279 = r249272 * r249278;
        return r249279;
}

double f(double re, double im) {
        double r249280 = 0.008333333333333333;
        double r249281 = im;
        double r249282 = 5.0;
        double r249283 = pow(r249281, r249282);
        double r249284 = r249280 * r249283;
        double r249285 = re;
        double r249286 = cos(r249285);
        double r249287 = 0.16666666666666666;
        double r249288 = 3.0;
        double r249289 = pow(r249281, r249288);
        double r249290 = 1.0;
        double r249291 = r249290 * r249281;
        double r249292 = fma(r249287, r249289, r249291);
        double r249293 = r249286 * r249292;
        double r249294 = fma(r249284, r249286, r249293);
        double r249295 = -r249294;
        return r249295;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.2
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(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)}\]
  4. Taylor expanded around inf 0.7

    \[\leadsto \color{blue}{-\left(0.1666666666666666574148081281236954964697 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(0.008333333333333333217685101601546193705872 \cdot \left(\cos re \cdot {im}^{5}\right) + 1 \cdot \left(\cos re \cdot im\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)}\]
  6. Final simplification0.7

    \[\leadsto -\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)\]

Reproduce

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