Average Error: 58.2 → 0.6
Time: 27.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[-\mathsf{fma}\left(\cos re \cdot {im}^{5}, 0.00833333333333333322, \cos re \cdot \mathsf{fma}\left(0.166666666666666657, {im}^{3}, 1 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
-\mathsf{fma}\left(\cos re \cdot {im}^{5}, 0.00833333333333333322, \cos re \cdot \mathsf{fma}\left(0.166666666666666657, {im}^{3}, 1 \cdot im\right)\right)
double f(double re, double im) {
        double r219032 = 0.5;
        double r219033 = re;
        double r219034 = cos(r219033);
        double r219035 = r219032 * r219034;
        double r219036 = 0.0;
        double r219037 = im;
        double r219038 = r219036 - r219037;
        double r219039 = exp(r219038);
        double r219040 = exp(r219037);
        double r219041 = r219039 - r219040;
        double r219042 = r219035 * r219041;
        return r219042;
}

double f(double re, double im) {
        double r219043 = re;
        double r219044 = cos(r219043);
        double r219045 = im;
        double r219046 = 5.0;
        double r219047 = pow(r219045, r219046);
        double r219048 = r219044 * r219047;
        double r219049 = 0.008333333333333333;
        double r219050 = 0.16666666666666666;
        double r219051 = 3.0;
        double r219052 = pow(r219045, r219051);
        double r219053 = 1.0;
        double r219054 = r219053 * r219045;
        double r219055 = fma(r219050, r219052, r219054);
        double r219056 = r219044 * r219055;
        double r219057 = fma(r219048, r219049, r219056);
        double r219058 = -r219057;
        return r219058;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.2
Target0.2
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \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.6

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

    \[\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. Taylor expanded around inf 0.6

    \[\leadsto \color{blue}{-\left(0.166666666666666657 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(0.00833333333333333322 \cdot \left(\cos re \cdot {im}^{5}\right) + 1 \cdot \left(\cos re \cdot im\right)\right)\right)}\]
  5. Simplified0.6

    \[\leadsto \color{blue}{-\mathsf{fma}\left(\cos re \cdot {im}^{5}, 0.00833333333333333322, \cos re \cdot \mathsf{fma}\left(0.166666666666666657, {im}^{3}, 1 \cdot im\right)\right)}\]
  6. Final simplification0.6

    \[\leadsto -\mathsf{fma}\left(\cos re \cdot {im}^{5}, 0.00833333333333333322, \cos re \cdot \mathsf{fma}\left(0.166666666666666657, {im}^{3}, 1 \cdot im\right)\right)\]

Reproduce

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