Average Error: 58.0 → 0.8
Time: 26.8s
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 r186096 = 0.5;
        double r186097 = re;
        double r186098 = cos(r186097);
        double r186099 = r186096 * r186098;
        double r186100 = 0.0;
        double r186101 = im;
        double r186102 = r186100 - r186101;
        double r186103 = exp(r186102);
        double r186104 = exp(r186101);
        double r186105 = r186103 - r186104;
        double r186106 = r186099 * r186105;
        return r186106;
}

double f(double re, double im) {
        double r186107 = 0.5;
        double r186108 = 0.016666666666666666;
        double r186109 = im;
        double r186110 = 5.0;
        double r186111 = pow(r186109, r186110);
        double r186112 = 2.0;
        double r186113 = 0.3333333333333333;
        double r186114 = 3.0;
        double r186115 = pow(r186109, r186114);
        double r186116 = r186113 * r186115;
        double r186117 = fma(r186112, r186109, r186116);
        double r186118 = fma(r186108, r186111, r186117);
        double r186119 = r186107 * r186118;
        double r186120 = re;
        double r186121 = cos(r186120);
        double r186122 = -r186121;
        double r186123 = r186119 * r186122;
        return r186123;
}

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 2019179 +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))))