Average Error: 43.6 → 0.8
Time: 29.2s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(\sin re \cdot \left(-0.5\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(\sin re \cdot \left(-0.5\right)\right)
double f(double re, double im) {
        double r221388 = 0.5;
        double r221389 = re;
        double r221390 = sin(r221389);
        double r221391 = r221388 * r221390;
        double r221392 = im;
        double r221393 = -r221392;
        double r221394 = exp(r221393);
        double r221395 = exp(r221392);
        double r221396 = r221394 - r221395;
        double r221397 = r221391 * r221396;
        return r221397;
}

double f(double re, double im) {
        double r221398 = 0.3333333333333333;
        double r221399 = im;
        double r221400 = 3.0;
        double r221401 = pow(r221399, r221400);
        double r221402 = 5.0;
        double r221403 = pow(r221399, r221402);
        double r221404 = 0.016666666666666666;
        double r221405 = r221399 + r221399;
        double r221406 = fma(r221403, r221404, r221405);
        double r221407 = fma(r221398, r221401, r221406);
        double r221408 = re;
        double r221409 = sin(r221408);
        double r221410 = 0.5;
        double r221411 = -r221410;
        double r221412 = r221409 * r221411;
        double r221413 = r221407 * r221412;
        return r221413;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.6
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.6

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin 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 \sin re\right) \cdot \color{blue}{\left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)\right)}\]
  4. Final simplification0.8

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

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))