Average Error: 58.0 → 0.8
Time: 29.0s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\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 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\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 r3509363 = 0.5;
        double r3509364 = re;
        double r3509365 = cos(r3509364);
        double r3509366 = r3509363 * r3509365;
        double r3509367 = 0.0;
        double r3509368 = im;
        double r3509369 = r3509367 - r3509368;
        double r3509370 = exp(r3509369);
        double r3509371 = exp(r3509368);
        double r3509372 = r3509370 - r3509371;
        double r3509373 = r3509366 * r3509372;
        return r3509373;
}

double f(double re, double im) {
        double r3509374 = -0.3333333333333333;
        double r3509375 = im;
        double r3509376 = r3509375 * r3509375;
        double r3509377 = r3509375 * r3509376;
        double r3509378 = r3509374 * r3509377;
        double r3509379 = 5.0;
        double r3509380 = pow(r3509375, r3509379);
        double r3509381 = 0.016666666666666666;
        double r3509382 = r3509375 + r3509375;
        double r3509383 = fma(r3509380, r3509381, r3509382);
        double r3509384 = r3509378 - r3509383;
        double r3509385 = 0.5;
        double r3509386 = re;
        double r3509387 = cos(r3509386);
        double r3509388 = r3509385 * r3509387;
        double r3509389 = r3509384 * r3509388;
        return r3509389;
}

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(\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(im \cdot \left(im \cdot im\right)\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 2019156 +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))))