Average Error: 58.1 → 0.8
Time: 1.3m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[(\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(im \cdot \left(im \cdot \frac{-1}{3}\right) - 2\right)\right))_* \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
(\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(im \cdot \left(im \cdot \frac{-1}{3}\right) - 2\right)\right))_* \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r19259105 = 0.5;
        double r19259106 = re;
        double r19259107 = cos(r19259106);
        double r19259108 = r19259105 * r19259107;
        double r19259109 = 0.0;
        double r19259110 = im;
        double r19259111 = r19259109 - r19259110;
        double r19259112 = exp(r19259111);
        double r19259113 = exp(r19259110);
        double r19259114 = r19259112 - r19259113;
        double r19259115 = r19259108 * r19259114;
        return r19259115;
}

double f(double re, double im) {
        double r19259116 = im;
        double r19259117 = 5.0;
        double r19259118 = pow(r19259116, r19259117);
        double r19259119 = -0.016666666666666666;
        double r19259120 = -0.3333333333333333;
        double r19259121 = r19259116 * r19259120;
        double r19259122 = r19259116 * r19259121;
        double r19259123 = 2.0;
        double r19259124 = r19259122 - r19259123;
        double r19259125 = r19259116 * r19259124;
        double r19259126 = fma(r19259118, r19259119, r19259125);
        double r19259127 = 0.5;
        double r19259128 = re;
        double r19259129 = cos(r19259128);
        double r19259130 = r19259127 * r19259129;
        double r19259131 = r19259126 * r19259130;
        return r19259131;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
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 58.1

    \[\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}{(\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(\left(im \cdot \frac{-1}{3}\right) \cdot im - 2\right)\right))_*}\]
  4. Final simplification0.8

    \[\leadsto (\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(im \cdot \left(im \cdot \frac{-1}{3}\right) - 2\right)\right))_* \cdot \left(0.5 \cdot \cos re\right)\]

Reproduce

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