Average Error: 58.0 → 0.7
Time: 25.5s
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 r184779 = 0.5;
        double r184780 = re;
        double r184781 = cos(r184780);
        double r184782 = r184779 * r184781;
        double r184783 = 0.0;
        double r184784 = im;
        double r184785 = r184783 - r184784;
        double r184786 = exp(r184785);
        double r184787 = exp(r184784);
        double r184788 = r184786 - r184787;
        double r184789 = r184782 * r184788;
        return r184789;
}

double f(double re, double im) {
        double r184790 = 0.5;
        double r184791 = 0.016666666666666666;
        double r184792 = im;
        double r184793 = 5.0;
        double r184794 = pow(r184792, r184793);
        double r184795 = 2.0;
        double r184796 = 0.3333333333333333;
        double r184797 = 3.0;
        double r184798 = pow(r184792, r184797);
        double r184799 = r184796 * r184798;
        double r184800 = fma(r184795, r184792, r184799);
        double r184801 = fma(r184791, r184794, r184800);
        double r184802 = r184790 * r184801;
        double r184803 = re;
        double r184804 = cos(r184803);
        double r184805 = -r184804;
        double r184806 = r184802 * r184805;
        return r184806;
}

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

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

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

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