Average Error: 43.0 → 0.8
Time: 30.1s
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 r140201 = 0.5;
        double r140202 = re;
        double r140203 = sin(r140202);
        double r140204 = r140201 * r140203;
        double r140205 = im;
        double r140206 = -r140205;
        double r140207 = exp(r140206);
        double r140208 = exp(r140205);
        double r140209 = r140207 - r140208;
        double r140210 = r140204 * r140209;
        return r140210;
}

double f(double re, double im) {
        double r140211 = 0.3333333333333333;
        double r140212 = im;
        double r140213 = 3.0;
        double r140214 = pow(r140212, r140213);
        double r140215 = 5.0;
        double r140216 = pow(r140212, r140215);
        double r140217 = 0.016666666666666666;
        double r140218 = r140212 + r140212;
        double r140219 = fma(r140216, r140217, r140218);
        double r140220 = fma(r140211, r140214, r140219);
        double r140221 = re;
        double r140222 = sin(r140221);
        double r140223 = 0.5;
        double r140224 = -r140223;
        double r140225 = r140222 * r140224;
        double r140226 = r140220 * r140225;
        return r140226;
}

Error

Bits error versus re

Bits error versus im

Target

Original43.0
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.0

    \[\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 2019195 +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))))