Average Error: 43.8 → 0.7
Time: 8.1s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(-0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(-0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)
double f(double re, double im) {
        double r227385 = 0.5;
        double r227386 = re;
        double r227387 = sin(r227386);
        double r227388 = r227385 * r227387;
        double r227389 = im;
        double r227390 = -r227389;
        double r227391 = exp(r227390);
        double r227392 = exp(r227389);
        double r227393 = r227391 - r227392;
        double r227394 = r227388 * r227393;
        return r227394;
}

double f(double re, double im) {
        double r227395 = 0.16666666666666666;
        double r227396 = re;
        double r227397 = sin(r227396);
        double r227398 = im;
        double r227399 = 3.0;
        double r227400 = pow(r227398, r227399);
        double r227401 = r227397 * r227400;
        double r227402 = r227395 * r227401;
        double r227403 = -r227402;
        double r227404 = 1.0;
        double r227405 = r227397 * r227398;
        double r227406 = 0.008333333333333333;
        double r227407 = 5.0;
        double r227408 = pow(r227398, r227407);
        double r227409 = r227397 * r227408;
        double r227410 = r227406 * r227409;
        double r227411 = fma(r227404, r227405, r227410);
        double r227412 = r227403 - r227411;
        return r227412;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.8
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.8

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

    \[\leadsto \left(0.5 \cdot \sin 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 \sin 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. Taylor expanded around inf 0.7

    \[\leadsto \color{blue}{-\left(0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{\left(-0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)}\]
  6. Final simplification0.7

    \[\leadsto \left(-0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(1, \sin re \cdot im, 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\]

Reproduce

herbie shell --seed 2020002 +o rules:numerics
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))