Average Error: 58.0 → 0.7
Time: 39.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, {im}^{5} \cdot \frac{-1}{60}\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, {im}^{5} \cdot \frac{-1}{60}\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r2765071 = 0.5;
        double r2765072 = re;
        double r2765073 = cos(r2765072);
        double r2765074 = r2765071 * r2765073;
        double r2765075 = 0.0;
        double r2765076 = im;
        double r2765077 = r2765075 - r2765076;
        double r2765078 = exp(r2765077);
        double r2765079 = exp(r2765076);
        double r2765080 = r2765078 - r2765079;
        double r2765081 = r2765074 * r2765080;
        return r2765081;
}

double f(double re, double im) {
        double r2765082 = -0.3333333333333333;
        double r2765083 = im;
        double r2765084 = r2765083 * r2765083;
        double r2765085 = r2765083 * r2765084;
        double r2765086 = -2.0;
        double r2765087 = 5.0;
        double r2765088 = pow(r2765083, r2765087);
        double r2765089 = -0.016666666666666666;
        double r2765090 = r2765088 * r2765089;
        double r2765091 = fma(r2765083, r2765086, r2765090);
        double r2765092 = fma(r2765082, r2765085, r2765091);
        double r2765093 = 0.5;
        double r2765094 = re;
        double r2765095 = cos(r2765094);
        double r2765096 = r2765093 * r2765095;
        double r2765097 = r2765092 * r2765096;
        return r2765097;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \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 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.0

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

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

Reproduce

herbie shell --seed 2019142 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))