Average Error: 58.0 → 0.9
Time: 40.3s
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(\frac{1}{60}, {im}^{5}, im \cdot 2\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(\frac{1}{60}, {im}^{5}, im \cdot 2\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r8623148 = 0.5;
        double r8623149 = re;
        double r8623150 = cos(r8623149);
        double r8623151 = r8623148 * r8623150;
        double r8623152 = 0.0;
        double r8623153 = im;
        double r8623154 = r8623152 - r8623153;
        double r8623155 = exp(r8623154);
        double r8623156 = exp(r8623153);
        double r8623157 = r8623155 - r8623156;
        double r8623158 = r8623151 * r8623157;
        return r8623158;
}

double f(double re, double im) {
        double r8623159 = -0.3333333333333333;
        double r8623160 = im;
        double r8623161 = r8623160 * r8623160;
        double r8623162 = r8623160 * r8623161;
        double r8623163 = r8623159 * r8623162;
        double r8623164 = 0.016666666666666666;
        double r8623165 = 5.0;
        double r8623166 = pow(r8623160, r8623165);
        double r8623167 = 2.0;
        double r8623168 = r8623160 * r8623167;
        double r8623169 = fma(r8623164, r8623166, r8623168);
        double r8623170 = r8623163 - r8623169;
        double r8623171 = 0.5;
        double r8623172 = re;
        double r8623173 = cos(r8623172);
        double r8623174 = r8623171 * r8623173;
        double r8623175 = r8623170 * r8623174;
        return r8623175;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.3
Herbie0.9
\[\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.9

    \[\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.9

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

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

Reproduce

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