Average Error: 58.0 → 0.7
Time: 32.9s
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 r3134171 = 0.5;
        double r3134172 = re;
        double r3134173 = cos(r3134172);
        double r3134174 = r3134171 * r3134173;
        double r3134175 = 0.0;
        double r3134176 = im;
        double r3134177 = r3134175 - r3134176;
        double r3134178 = exp(r3134177);
        double r3134179 = exp(r3134176);
        double r3134180 = r3134178 - r3134179;
        double r3134181 = r3134174 * r3134180;
        return r3134181;
}

double f(double re, double im) {
        double r3134182 = -0.3333333333333333;
        double r3134183 = im;
        double r3134184 = r3134183 * r3134183;
        double r3134185 = r3134183 * r3134184;
        double r3134186 = r3134182 * r3134185;
        double r3134187 = 5.0;
        double r3134188 = pow(r3134183, r3134187);
        double r3134189 = 0.016666666666666666;
        double r3134190 = r3134183 + r3134183;
        double r3134191 = fma(r3134188, r3134189, r3134190);
        double r3134192 = r3134186 - r3134191;
        double r3134193 = 0.5;
        double r3134194 = re;
        double r3134195 = cos(r3134194);
        double r3134196 = r3134193 * r3134195;
        double r3134197 = r3134192 * r3134196;
        return r3134197;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.3
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.0

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

    \[\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 2019151 +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))))