Average Error: 58.2 → 0.6
Time: 9.1s
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 r307348 = 0.5;
        double r307349 = re;
        double r307350 = cos(r307349);
        double r307351 = r307348 * r307350;
        double r307352 = 0.0;
        double r307353 = im;
        double r307354 = r307352 - r307353;
        double r307355 = exp(r307354);
        double r307356 = exp(r307353);
        double r307357 = r307355 - r307356;
        double r307358 = r307351 * r307357;
        return r307358;
}

double f(double re, double im) {
        double r307359 = 0.5;
        double r307360 = re;
        double r307361 = cos(r307360);
        double r307362 = r307359 * r307361;
        double r307363 = im;
        double r307364 = 3.0;
        double r307365 = pow(r307363, r307364);
        double r307366 = 0.3333333333333333;
        double r307367 = 0.016666666666666666;
        double r307368 = 5.0;
        double r307369 = pow(r307363, r307368);
        double r307370 = r307367 * r307369;
        double r307371 = fma(r307365, r307366, r307370);
        double r307372 = -r307371;
        double r307373 = 2.0;
        double r307374 = r307373 * r307363;
        double r307375 = r307372 - r307374;
        double r307376 = r307362 * r307375;
        return r307376;
}

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

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

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

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

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