Average Error: 58.2 → 0.9
Time: 10.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(\left(-\log \left(e^{\frac{1}{3} \cdot {im}^{3}}\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(\left(-\log \left(e^{\frac{1}{3} \cdot {im}^{3}}\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r196431 = 0.5;
        double r196432 = re;
        double r196433 = cos(r196432);
        double r196434 = r196431 * r196433;
        double r196435 = 0.0;
        double r196436 = im;
        double r196437 = r196435 - r196436;
        double r196438 = exp(r196437);
        double r196439 = exp(r196436);
        double r196440 = r196438 - r196439;
        double r196441 = r196434 * r196440;
        return r196441;
}

double f(double re, double im) {
        double r196442 = 0.5;
        double r196443 = re;
        double r196444 = cos(r196443);
        double r196445 = r196442 * r196444;
        double r196446 = 0.3333333333333333;
        double r196447 = im;
        double r196448 = 3.0;
        double r196449 = pow(r196447, r196448);
        double r196450 = r196446 * r196449;
        double r196451 = exp(r196450);
        double r196452 = log(r196451);
        double r196453 = -r196452;
        double r196454 = 0.016666666666666666;
        double r196455 = 5.0;
        double r196456 = pow(r196447, r196455);
        double r196457 = 2.0;
        double r196458 = r196457 * r196447;
        double r196459 = fma(r196454, r196456, r196458);
        double r196460 = r196453 - r196459;
        double r196461 = r196445 * r196460;
        return r196461;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.2
Target0.2
Herbie0.9
\[\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.2

    \[\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. Using strategy rm
  5. Applied add-log-exp0.9

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

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

Reproduce

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