Average Error: 58.0 → 0.8
Time: 24.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, \mathsf{fma}\left(2, im, \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(-\cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, \mathsf{fma}\left(2, im, \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(-\cos re\right)
double f(double re, double im) {
        double r105372 = 0.5;
        double r105373 = re;
        double r105374 = cos(r105373);
        double r105375 = r105372 * r105374;
        double r105376 = 0.0;
        double r105377 = im;
        double r105378 = r105376 - r105377;
        double r105379 = exp(r105378);
        double r105380 = exp(r105377);
        double r105381 = r105379 - r105380;
        double r105382 = r105375 * r105381;
        return r105382;
}

double f(double re, double im) {
        double r105383 = 0.5;
        double r105384 = 0.016666666666666666;
        double r105385 = im;
        double r105386 = 5.0;
        double r105387 = pow(r105385, r105386);
        double r105388 = 2.0;
        double r105389 = 0.3333333333333333;
        double r105390 = 3.0;
        double r105391 = pow(r105385, r105390);
        double r105392 = r105389 * r105391;
        double r105393 = fma(r105388, r105385, r105392);
        double r105394 = fma(r105384, r105387, r105393);
        double r105395 = r105383 * r105394;
        double r105396 = re;
        double r105397 = cos(r105396);
        double r105398 = -r105397;
        double r105399 = r105395 * r105398;
        return r105399;
}

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(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.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
  2. Simplified58.0

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{0.0 - im} - e^{im}\right)\right)}\]
  3. Taylor expanded around 0 0.8

    \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\right)\]
  4. Simplified0.8

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 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))))