Average Error: 58.0 → 0.8
Time: 39.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\mathsf{fma}\left(im \cdot \left(im \cdot im\right), \frac{1}{3}, \mathsf{fma}\left(2, im, {im}^{5} \cdot \frac{1}{60}\right)\right) \cdot \left(\cos re \cdot \left(-0.5\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\mathsf{fma}\left(im \cdot \left(im \cdot im\right), \frac{1}{3}, \mathsf{fma}\left(2, im, {im}^{5} \cdot \frac{1}{60}\right)\right) \cdot \left(\cos re \cdot \left(-0.5\right)\right)
double f(double re, double im) {
        double r2876357 = 0.5;
        double r2876358 = re;
        double r2876359 = cos(r2876358);
        double r2876360 = r2876357 * r2876359;
        double r2876361 = 0.0;
        double r2876362 = im;
        double r2876363 = r2876361 - r2876362;
        double r2876364 = exp(r2876363);
        double r2876365 = exp(r2876362);
        double r2876366 = r2876364 - r2876365;
        double r2876367 = r2876360 * r2876366;
        return r2876367;
}

double f(double re, double im) {
        double r2876368 = im;
        double r2876369 = r2876368 * r2876368;
        double r2876370 = r2876368 * r2876369;
        double r2876371 = 0.3333333333333333;
        double r2876372 = 2.0;
        double r2876373 = 5.0;
        double r2876374 = pow(r2876368, r2876373);
        double r2876375 = 0.016666666666666666;
        double r2876376 = r2876374 * r2876375;
        double r2876377 = fma(r2876372, r2876368, r2876376);
        double r2876378 = fma(r2876370, r2876371, r2876377);
        double r2876379 = re;
        double r2876380 = cos(r2876379);
        double r2876381 = 0.5;
        double r2876382 = -r2876381;
        double r2876383 = r2876380 * r2876382;
        double r2876384 = r2876378 * r2876383;
        return r2876384;
}

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

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

Reproduce

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