Average Error: 43.6 → 0.8
Time: 26.6s
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 r216528 = 0.5;
        double r216529 = re;
        double r216530 = sin(r216529);
        double r216531 = r216528 * r216530;
        double r216532 = im;
        double r216533 = -r216532;
        double r216534 = exp(r216533);
        double r216535 = exp(r216532);
        double r216536 = r216534 - r216535;
        double r216537 = r216531 * r216536;
        return r216537;
}

double f(double re, double im) {
        double r216538 = 0.3333333333333333;
        double r216539 = im;
        double r216540 = 3.0;
        double r216541 = pow(r216539, r216540);
        double r216542 = 5.0;
        double r216543 = pow(r216539, r216542);
        double r216544 = 0.016666666666666666;
        double r216545 = r216539 + r216539;
        double r216546 = fma(r216543, r216544, r216545);
        double r216547 = fma(r216538, r216541, r216546);
        double r216548 = re;
        double r216549 = sin(r216548);
        double r216550 = 0.5;
        double r216551 = -r216550;
        double r216552 = r216549 * r216551;
        double r216553 = r216547 * r216552;
        return r216553;
}

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 2019174 +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))))