Average Error: 58.1 → 0.7
Time: 8.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(-0.166666666666666657 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.00833333333333333322, \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.166666666666666657 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.00833333333333333322, \cos re \cdot {im}^{5}, 1 \cdot \left(\cos re \cdot im\right)\right)
double f(double re, double im) {
        double r174123 = 0.5;
        double r174124 = re;
        double r174125 = cos(r174124);
        double r174126 = r174123 * r174125;
        double r174127 = 0.0;
        double r174128 = im;
        double r174129 = r174127 - r174128;
        double r174130 = exp(r174129);
        double r174131 = exp(r174128);
        double r174132 = r174130 - r174131;
        double r174133 = r174126 * r174132;
        return r174133;
}

double f(double re, double im) {
        double r174134 = 0.16666666666666666;
        double r174135 = re;
        double r174136 = cos(r174135);
        double r174137 = im;
        double r174138 = 3.0;
        double r174139 = pow(r174137, r174138);
        double r174140 = r174136 * r174139;
        double r174141 = r174134 * r174140;
        double r174142 = -r174141;
        double r174143 = 0.008333333333333333;
        double r174144 = 5.0;
        double r174145 = pow(r174137, r174144);
        double r174146 = r174136 * r174145;
        double r174147 = 1.0;
        double r174148 = r174136 * r174137;
        double r174149 = r174147 * r174148;
        double r174150 = fma(r174143, r174146, r174149);
        double r174151 = r174142 - r174150;
        return r174151;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.7
\[\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.1

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

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

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

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

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

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

Reproduce

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