Average Error: 58.0 → 0.8
Time: 8.2s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(-0.1666666666666666574148081281236954964697 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.008333333333333333217685101601546193705872, \cos re \cdot {im}^{5}, 1 \cdot \left(\cos re \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(-0.1666666666666666574148081281236954964697 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.008333333333333333217685101601546193705872, \cos re \cdot {im}^{5}, 1 \cdot \left(\cos re \cdot im\right)\right)
double f(double re, double im) {
        double r213655 = 0.5;
        double r213656 = re;
        double r213657 = cos(r213656);
        double r213658 = r213655 * r213657;
        double r213659 = 0.0;
        double r213660 = im;
        double r213661 = r213659 - r213660;
        double r213662 = exp(r213661);
        double r213663 = exp(r213660);
        double r213664 = r213662 - r213663;
        double r213665 = r213658 * r213664;
        return r213665;
}

double f(double re, double im) {
        double r213666 = 0.16666666666666666;
        double r213667 = re;
        double r213668 = cos(r213667);
        double r213669 = im;
        double r213670 = 3.0;
        double r213671 = pow(r213669, r213670);
        double r213672 = r213668 * r213671;
        double r213673 = r213666 * r213672;
        double r213674 = -r213673;
        double r213675 = 0.008333333333333333;
        double r213676 = 5.0;
        double r213677 = pow(r213669, r213676);
        double r213678 = r213668 * r213677;
        double r213679 = 1.0;
        double r213680 = r213668 * r213669;
        double r213681 = r213679 * r213680;
        double r213682 = fma(r213675, r213678, r213681);
        double r213683 = r213674 - r213682;
        return r213683;
}

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(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.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.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}{\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.8

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

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

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

Reproduce

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