Average Error: 58.2 → 0.7
Time: 27.4s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r162984 = 0.5;
        double r162985 = re;
        double r162986 = cos(r162985);
        double r162987 = r162984 * r162986;
        double r162988 = 0.0;
        double r162989 = im;
        double r162990 = r162988 - r162989;
        double r162991 = exp(r162990);
        double r162992 = exp(r162989);
        double r162993 = r162991 - r162992;
        double r162994 = r162987 * r162993;
        return r162994;
}

double f(double re, double im) {
        double r162995 = -0.3333333333333333;
        double r162996 = im;
        double r162997 = 3.0;
        double r162998 = pow(r162996, r162997);
        double r162999 = r162995 * r162998;
        double r163000 = 0.5;
        double r163001 = re;
        double r163002 = cos(r163001);
        double r163003 = r163000 * r163002;
        double r163004 = r162999 * r163003;
        double r163005 = 0.016666666666666666;
        double r163006 = 5.0;
        double r163007 = pow(r162996, r163006);
        double r163008 = 2.0;
        double r163009 = r163008 * r162996;
        double r163010 = fma(r163005, r163007, r163009);
        double r163011 = -r163010;
        double r163012 = r163011 * r163003;
        double r163013 = r163004 + r163012;
        return r163013;
}

Error

Bits error versus re

Bits error versus im

Target

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

    \[\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. Using strategy rm
  5. Applied fma-udef0.7

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019212 +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.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 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))))