Average Error: 58.3 → 0.7
Time: 38.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3}\right) \cdot \left(\cos re \cdot 0.5\right) + \mathsf{fma}\left(-2, im, \frac{-1}{60} \cdot {im}^{5}\right) \cdot \left(\cos re \cdot 0.5\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3}\right) \cdot \left(\cos re \cdot 0.5\right) + \mathsf{fma}\left(-2, im, \frac{-1}{60} \cdot {im}^{5}\right) \cdot \left(\cos re \cdot 0.5\right)
double f(double re, double im) {
        double r7163879 = 0.5;
        double r7163880 = re;
        double r7163881 = cos(r7163880);
        double r7163882 = r7163879 * r7163881;
        double r7163883 = 0.0;
        double r7163884 = im;
        double r7163885 = r7163883 - r7163884;
        double r7163886 = exp(r7163885);
        double r7163887 = exp(r7163884);
        double r7163888 = r7163886 - r7163887;
        double r7163889 = r7163882 * r7163888;
        return r7163889;
}

double f(double re, double im) {
        double r7163890 = im;
        double r7163891 = r7163890 * r7163890;
        double r7163892 = r7163891 * r7163890;
        double r7163893 = -0.3333333333333333;
        double r7163894 = r7163892 * r7163893;
        double r7163895 = re;
        double r7163896 = cos(r7163895);
        double r7163897 = 0.5;
        double r7163898 = r7163896 * r7163897;
        double r7163899 = r7163894 * r7163898;
        double r7163900 = -2.0;
        double r7163901 = -0.016666666666666666;
        double r7163902 = 5.0;
        double r7163903 = pow(r7163890, r7163902);
        double r7163904 = r7163901 * r7163903;
        double r7163905 = fma(r7163900, r7163890, r7163904);
        double r7163906 = r7163905 * r7163898;
        double r7163907 = r7163899 + r7163906;
        return r7163907;
}

Error

Bits error versus re

Bits error versus im

Target

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

    \[\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}{\mathsf{fma}\left(\frac{-1}{3}, \left(im \cdot im\right) \cdot im, {im}^{5} \cdot \frac{-1}{60} - \left(im + im\right)\right)}\]
  4. Using strategy rm
  5. Applied fma-udef0.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) + \left({im}^{5} \cdot \frac{-1}{60} - \left(im + im\right)\right)\right)}\]
  6. Applied distribute-rgt-in0.7

    \[\leadsto \color{blue}{\left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right) \cdot \left(0.5 \cdot \cos re\right) + \left({im}^{5} \cdot \frac{-1}{60} - \left(im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)}\]
  7. Simplified0.7

    \[\leadsto \left(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right)\right) \cdot \left(0.5 \cdot \cos re\right) + \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(-2, im, \frac{-1}{60} \cdot {im}^{5}\right)}\]
  8. Final simplification0.7

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

Reproduce

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