Average Error: 58.1 → 0.7
Time: 1.3m
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[(\left((\left(im \cdot \frac{-1}{3}\right) \cdot im + -2)_*\right) \cdot im + \left({im}^{5} \cdot \frac{-1}{60}\right))_* \cdot \left(\cos re \cdot 0.5\right)\]
double f(double re, double im) {
        double r21394549 = 0.5;
        double r21394550 = re;
        double r21394551 = cos(r21394550);
        double r21394552 = r21394549 * r21394551;
        double r21394553 = 0.0;
        double r21394554 = im;
        double r21394555 = r21394553 - r21394554;
        double r21394556 = exp(r21394555);
        double r21394557 = exp(r21394554);
        double r21394558 = r21394556 - r21394557;
        double r21394559 = r21394552 * r21394558;
        return r21394559;
}

double f(double re, double im) {
        double r21394560 = im;
        double r21394561 = -0.3333333333333333;
        double r21394562 = r21394560 * r21394561;
        double r21394563 = -2.0;
        double r21394564 = fma(r21394562, r21394560, r21394563);
        double r21394565 = 5.0;
        double r21394566 = pow(r21394560, r21394565);
        double r21394567 = -0.016666666666666666;
        double r21394568 = r21394566 * r21394567;
        double r21394569 = fma(r21394564, r21394560, r21394568);
        double r21394570 = re;
        double r21394571 = cos(r21394570);
        double r21394572 = 0.5;
        double r21394573 = r21394571 * r21394572;
        double r21394574 = r21394569 * r21394573;
        return r21394574;
}

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

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.2
Herbie0.7
\[\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.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({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(\left(im \cdot \frac{-1}{3}\right) \cdot im - 2\right)\right))_*}\]
  4. Using strategy rm
  5. Applied pow10.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{{\left((\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(\left(im \cdot \frac{-1}{3}\right) \cdot im - 2\right)\right))_*\right)}^{1}}\]
  6. Applied pow10.7

    \[\leadsto \color{blue}{{\left(0.5 \cdot \cos re\right)}^{1}} \cdot {\left((\left({im}^{5}\right) \cdot \frac{-1}{60} + \left(im \cdot \left(\left(im \cdot \frac{-1}{3}\right) \cdot im - 2\right)\right))_*\right)}^{1}\]
  7. Applied pow-prod-down0.7

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

    \[\leadsto {\color{blue}{\left((\left((\left(im \cdot \frac{-1}{3}\right) \cdot im + -2)_*\right) \cdot im + \left(\frac{-1}{60} \cdot {im}^{5}\right))_* \cdot \left(0.5 \cdot \cos re\right)\right)}}^{1}\]
  9. Final simplification0.7

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

Reproduce

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