Average Error: 58.1 → 0.7
Time: 26.1s
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 r232640 = 0.5;
        double r232641 = re;
        double r232642 = cos(r232641);
        double r232643 = r232640 * r232642;
        double r232644 = 0.0;
        double r232645 = im;
        double r232646 = r232644 - r232645;
        double r232647 = exp(r232646);
        double r232648 = exp(r232645);
        double r232649 = r232647 - r232648;
        double r232650 = r232643 * r232649;
        return r232650;
}

double f(double re, double im) {
        double r232651 = 0.5;
        double r232652 = re;
        double r232653 = cos(r232652);
        double r232654 = r232651 * r232653;
        double r232655 = 0.3333333333333333;
        double r232656 = im;
        double r232657 = 3.0;
        double r232658 = pow(r232656, r232657);
        double r232659 = 0.016666666666666666;
        double r232660 = 5.0;
        double r232661 = pow(r232656, r232660);
        double r232662 = 2.0;
        double r232663 = r232662 * r232656;
        double r232664 = fma(r232659, r232661, r232663);
        double r232665 = fma(r232655, r232658, r232664);
        double r232666 = -r232665;
        double r232667 = r232654 * r232666;
        return r232667;
}

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