Average Error: 58.1 → 0.7
Time: 36.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\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)
\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r8588365 = 0.5;
        double r8588366 = re;
        double r8588367 = cos(r8588366);
        double r8588368 = r8588365 * r8588367;
        double r8588369 = 0.0;
        double r8588370 = im;
        double r8588371 = r8588369 - r8588370;
        double r8588372 = exp(r8588371);
        double r8588373 = exp(r8588370);
        double r8588374 = r8588372 - r8588373;
        double r8588375 = r8588368 * r8588374;
        return r8588375;
}

double f(double re, double im) {
        double r8588376 = im;
        double r8588377 = r8588376 * r8588376;
        double r8588378 = r8588376 * r8588377;
        double r8588379 = -0.3333333333333333;
        double r8588380 = r8588378 * r8588379;
        double r8588381 = 2.0;
        double r8588382 = 5.0;
        double r8588383 = pow(r8588376, r8588382);
        double r8588384 = 0.016666666666666666;
        double r8588385 = r8588383 * r8588384;
        double r8588386 = fma(r8588381, r8588376, r8588385);
        double r8588387 = r8588380 - r8588386;
        double r8588388 = 0.5;
        double r8588389 = re;
        double r8588390 = cos(r8588389);
        double r8588391 = r8588388 * r8588390;
        double r8588392 = r8588387 * r8588391;
        return r8588392;
}

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(\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.1

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

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

Reproduce

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