Average Error: 57.9 → 0.8
Time: 29.9s
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 r8193161 = 0.5;
        double r8193162 = re;
        double r8193163 = cos(r8193162);
        double r8193164 = r8193161 * r8193163;
        double r8193165 = 0.0;
        double r8193166 = im;
        double r8193167 = r8193165 - r8193166;
        double r8193168 = exp(r8193167);
        double r8193169 = exp(r8193166);
        double r8193170 = r8193168 - r8193169;
        double r8193171 = r8193164 * r8193170;
        return r8193171;
}

double f(double re, double im) {
        double r8193172 = im;
        double r8193173 = r8193172 * r8193172;
        double r8193174 = r8193173 * r8193172;
        double r8193175 = -0.3333333333333333;
        double r8193176 = r8193174 * r8193175;
        double r8193177 = re;
        double r8193178 = cos(r8193177);
        double r8193179 = 0.5;
        double r8193180 = r8193178 * r8193179;
        double r8193181 = r8193176 * r8193180;
        double r8193182 = -2.0;
        double r8193183 = -0.016666666666666666;
        double r8193184 = 5.0;
        double r8193185 = pow(r8193172, r8193184);
        double r8193186 = r8193183 * r8193185;
        double r8193187 = fma(r8193182, r8193172, r8193186);
        double r8193188 = r8193187 * r8193180;
        double r8193189 = r8193181 + r8193188;
        return r8193189;
}

Error

Bits error versus re

Bits error versus im

Target

Original57.9
Target0.3
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 57.9

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

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

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

    \[\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, {im}^{5} \cdot \frac{-1}{60}\right)}\]
  8. Final simplification0.8

    \[\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 2019168 +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))))