Average Error: 58.0 → 0.7
Time: 9.0s
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(\left(-\mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right) - 2 \cdot im\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(\left(-\mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right) - 2 \cdot im\right)
double f(double re, double im) {
        double r189977 = 0.5;
        double r189978 = re;
        double r189979 = cos(r189978);
        double r189980 = r189977 * r189979;
        double r189981 = 0.0;
        double r189982 = im;
        double r189983 = r189981 - r189982;
        double r189984 = exp(r189983);
        double r189985 = exp(r189982);
        double r189986 = r189984 - r189985;
        double r189987 = r189980 * r189986;
        return r189987;
}

double f(double re, double im) {
        double r189988 = 0.5;
        double r189989 = re;
        double r189990 = cos(r189989);
        double r189991 = r189988 * r189990;
        double r189992 = im;
        double r189993 = 3.0;
        double r189994 = pow(r189992, r189993);
        double r189995 = 0.3333333333333333;
        double r189996 = 0.016666666666666666;
        double r189997 = 5.0;
        double r189998 = pow(r189992, r189997);
        double r189999 = r189996 * r189998;
        double r190000 = fma(r189994, r189995, r189999);
        double r190001 = -r190000;
        double r190002 = 2.0;
        double r190003 = r190002 * r189992;
        double r190004 = r190001 - r190003;
        double r190005 = r189991 * r190004;
        return r190005;
}

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

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \color{blue}{\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)}\right)\]
  6. Applied associate--r+0.7

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

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

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

Reproduce

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