Average Error: 58.2 → 0.6
Time: 1.4m
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 r43166206 = 0.5;
        double r43166207 = re;
        double r43166208 = cos(r43166207);
        double r43166209 = r43166206 * r43166208;
        double r43166210 = 0.0;
        double r43166211 = im;
        double r43166212 = r43166210 - r43166211;
        double r43166213 = exp(r43166212);
        double r43166214 = exp(r43166211);
        double r43166215 = r43166213 - r43166214;
        double r43166216 = r43166209 * r43166215;
        return r43166216;
}

double f(double re, double im) {
        double r43166217 = im;
        double r43166218 = 5.0;
        double r43166219 = pow(r43166217, r43166218);
        double r43166220 = -0.016666666666666666;
        double r43166221 = -0.3333333333333333;
        double r43166222 = r43166217 * r43166221;
        double r43166223 = r43166217 * r43166222;
        double r43166224 = 2.0;
        double r43166225 = r43166223 - r43166224;
        double r43166226 = r43166217 * r43166225;
        double r43166227 = fma(r43166219, r43166220, r43166226);
        double r43166228 = 0.5;
        double r43166229 = re;
        double r43166230 = cos(r43166229);
        double r43166231 = r43166228 * r43166230;
        double r43166232 = r43166227 * r43166231;
        return r43166232;
}

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

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

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