Average Error: 58.0 → 0.8
Time: 55.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r7682377 = 0.5;
        double r7682378 = re;
        double r7682379 = cos(r7682378);
        double r7682380 = r7682377 * r7682379;
        double r7682381 = 0.0;
        double r7682382 = im;
        double r7682383 = r7682381 - r7682382;
        double r7682384 = exp(r7682383);
        double r7682385 = exp(r7682382);
        double r7682386 = r7682384 - r7682385;
        double r7682387 = r7682380 * r7682386;
        return r7682387;
}

double f(double re, double im) {
        double r7682388 = -0.3333333333333333;
        double r7682389 = im;
        double r7682390 = r7682389 * r7682389;
        double r7682391 = r7682390 * r7682389;
        double r7682392 = r7682388 * r7682391;
        double r7682393 = 5.0;
        double r7682394 = pow(r7682389, r7682393);
        double r7682395 = 0.016666666666666666;
        double r7682396 = r7682389 + r7682389;
        double r7682397 = fma(r7682394, r7682395, r7682396);
        double r7682398 = r7682392 - r7682397;
        double r7682399 = 0.5;
        double r7682400 = re;
        double r7682401 = cos(r7682400);
        double r7682402 = r7682399 * r7682401;
        double r7682403 = r7682398 * r7682402;
        return r7682403;
}

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. 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(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)}\]
  4. Final simplification0.8

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

Reproduce

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