Average Error: 58.0 → 0.8
Time: 39.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[0.5 \cdot \left(\cos re \cdot \mathsf{fma}\left(\left(im \cdot im\right) \cdot \frac{-1}{3}, im, \mathsf{fma}\left(-2, im, \frac{-1}{60} \cdot \left(im \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right)\right)\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
0.5 \cdot \left(\cos re \cdot \mathsf{fma}\left(\left(im \cdot im\right) \cdot \frac{-1}{3}, im, \mathsf{fma}\left(-2, im, \frac{-1}{60} \cdot \left(im \cdot \left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right)\right)\right)\right)\right)
double f(double re, double im) {
        double r6112072 = 0.5;
        double r6112073 = re;
        double r6112074 = cos(r6112073);
        double r6112075 = r6112072 * r6112074;
        double r6112076 = 0.0;
        double r6112077 = im;
        double r6112078 = r6112076 - r6112077;
        double r6112079 = exp(r6112078);
        double r6112080 = exp(r6112077);
        double r6112081 = r6112079 - r6112080;
        double r6112082 = r6112075 * r6112081;
        return r6112082;
}

double f(double re, double im) {
        double r6112083 = 0.5;
        double r6112084 = re;
        double r6112085 = cos(r6112084);
        double r6112086 = im;
        double r6112087 = r6112086 * r6112086;
        double r6112088 = -0.3333333333333333;
        double r6112089 = r6112087 * r6112088;
        double r6112090 = -2.0;
        double r6112091 = -0.016666666666666666;
        double r6112092 = r6112087 * r6112087;
        double r6112093 = r6112086 * r6112092;
        double r6112094 = r6112091 * r6112093;
        double r6112095 = fma(r6112090, r6112086, r6112094);
        double r6112096 = fma(r6112089, r6112086, r6112095);
        double r6112097 = r6112085 * r6112096;
        double r6112098 = r6112083 * r6112097;
        return r6112098;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
Herbie0.8
\[\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.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

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

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{3}, im \cdot \left(im \cdot im\right), \mathsf{fma}\left(im, -2, \frac{-1}{60} \cdot {im}^{5}\right)\right)}\]
  4. Using strategy rm
  5. Applied add-log-exp0.9

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(\frac{-1}{3}, \color{blue}{\log \left(e^{im \cdot \left(im \cdot im\right)}\right)}, \mathsf{fma}\left(im, -2, \frac{-1}{60} \cdot {im}^{5}\right)\right)\]
  6. Using strategy rm
  7. Applied associate-*l*0.9

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

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

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

Reproduce

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