Average Error: 58.1 → 0.9
Time: 34.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(\log \left(e^{\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}\right) - \mathsf{fma}\left(2, im, \left(\frac{1}{60} \cdot {im}^{5}\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(\log \left(e^{\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}\right) - \mathsf{fma}\left(2, im, \left(\frac{1}{60} \cdot {im}^{5}\right)\right)\right)
double f(double re, double im) {
        double r2442409 = 0.5;
        double r2442410 = re;
        double r2442411 = cos(r2442410);
        double r2442412 = r2442409 * r2442411;
        double r2442413 = 0.0;
        double r2442414 = im;
        double r2442415 = r2442413 - r2442414;
        double r2442416 = exp(r2442415);
        double r2442417 = exp(r2442414);
        double r2442418 = r2442416 - r2442417;
        double r2442419 = r2442412 * r2442418;
        return r2442419;
}

double f(double re, double im) {
        double r2442420 = 0.5;
        double r2442421 = re;
        double r2442422 = cos(r2442421);
        double r2442423 = r2442420 * r2442422;
        double r2442424 = -0.3333333333333333;
        double r2442425 = im;
        double r2442426 = r2442425 * r2442425;
        double r2442427 = r2442425 * r2442426;
        double r2442428 = r2442424 * r2442427;
        double r2442429 = exp(r2442428);
        double r2442430 = log(r2442429);
        double r2442431 = 2.0;
        double r2442432 = 0.016666666666666666;
        double r2442433 = 5.0;
        double r2442434 = pow(r2442425, r2442433);
        double r2442435 = r2442432 * r2442434;
        double r2442436 = fma(r2442431, r2442425, r2442435);
        double r2442437 = r2442430 - r2442436;
        double r2442438 = r2442423 * r2442437;
        return r2442438;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.9
\[\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(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left(2, im, \left(\frac{1}{60} \cdot {im}^{5}\right)\right)\right)}\]
  4. Using strategy rm
  5. Applied add-log-exp0.9

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\log \left(e^{\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3}}\right)} - \mathsf{fma}\left(2, im, \left(\frac{1}{60} \cdot {im}^{5}\right)\right)\right)\]
  6. Final simplification0.9

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\log \left(e^{\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right)}\right) - \mathsf{fma}\left(2, im, \left(\frac{1}{60} \cdot {im}^{5}\right)\right)\right)\]

Reproduce

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