Average Error: 58.1 → 0.7
Time: 18.6s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)
double f(double re, double im) {
        double r212408 = 0.5;
        double r212409 = re;
        double r212410 = cos(r212409);
        double r212411 = r212408 * r212410;
        double r212412 = 0.0;
        double r212413 = im;
        double r212414 = r212412 - r212413;
        double r212415 = exp(r212414);
        double r212416 = exp(r212413);
        double r212417 = r212415 - r212416;
        double r212418 = r212411 * r212417;
        return r212418;
}

double f(double re, double im) {
        double r212419 = 0.5;
        double r212420 = re;
        double r212421 = cos(r212420);
        double r212422 = r212419 * r212421;
        double r212423 = 0.3333333333333333;
        double r212424 = im;
        double r212425 = 3.0;
        double r212426 = pow(r212424, r212425);
        double r212427 = 0.016666666666666666;
        double r212428 = 5.0;
        double r212429 = pow(r212424, r212428);
        double r212430 = 2.0;
        double r212431 = r212430 * r212424;
        double r212432 = fma(r212427, r212429, r212431);
        double r212433 = fma(r212423, r212426, r212432);
        double r212434 = -r212433;
        double r212435 = r212422 * r212434;
        return r212435;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.2
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \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.1

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.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(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)}\]
  4. Final simplification0.7

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (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))))