Average Error: 58.1 → 0.8
Time: 34.8s
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 \mathsf{fma}\left({im}^{5}, \frac{-1}{60}, \mathsf{fma}\left(im, -2, {im}^{3} \cdot \frac{-1}{3}\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 \mathsf{fma}\left({im}^{5}, \frac{-1}{60}, \mathsf{fma}\left(im, -2, {im}^{3} \cdot \frac{-1}{3}\right)\right)
double f(double re, double im) {
        double r116408 = 0.5;
        double r116409 = re;
        double r116410 = cos(r116409);
        double r116411 = r116408 * r116410;
        double r116412 = 0.0;
        double r116413 = im;
        double r116414 = r116412 - r116413;
        double r116415 = exp(r116414);
        double r116416 = exp(r116413);
        double r116417 = r116415 - r116416;
        double r116418 = r116411 * r116417;
        return r116418;
}

double f(double re, double im) {
        double r116419 = 0.5;
        double r116420 = re;
        double r116421 = cos(r116420);
        double r116422 = r116419 * r116421;
        double r116423 = im;
        double r116424 = 5.0;
        double r116425 = pow(r116423, r116424);
        double r116426 = -0.016666666666666666;
        double r116427 = -2.0;
        double r116428 = 3.0;
        double r116429 = pow(r116423, r116428);
        double r116430 = -0.3333333333333333;
        double r116431 = r116429 * r116430;
        double r116432 = fma(r116423, r116427, r116431);
        double r116433 = fma(r116425, r116426, r116432);
        double r116434 = r116422 * r116433;
        return r116434;
}

Error

Bits error versus re

Bits error versus im

Target

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

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

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

Reproduce

herbie shell --seed 2019303 +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.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 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))))