Average Error: 43.7 → 0.8
Time: 22.8s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(\mathsf{fma}\left({im}^{5}, \frac{-1}{60}, {im}^{3} \cdot \frac{-1}{3}\right) - 2 \cdot im\right) \cdot 0.5\right) \cdot \sin re\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(\mathsf{fma}\left({im}^{5}, \frac{-1}{60}, {im}^{3} \cdot \frac{-1}{3}\right) - 2 \cdot im\right) \cdot 0.5\right) \cdot \sin re
double f(double re, double im) {
        double r110470 = 0.5;
        double r110471 = re;
        double r110472 = sin(r110471);
        double r110473 = r110470 * r110472;
        double r110474 = im;
        double r110475 = -r110474;
        double r110476 = exp(r110475);
        double r110477 = exp(r110474);
        double r110478 = r110476 - r110477;
        double r110479 = r110473 * r110478;
        return r110479;
}

double f(double re, double im) {
        double r110480 = im;
        double r110481 = 5.0;
        double r110482 = pow(r110480, r110481);
        double r110483 = -0.016666666666666666;
        double r110484 = 3.0;
        double r110485 = pow(r110480, r110484);
        double r110486 = -0.3333333333333333;
        double r110487 = r110485 * r110486;
        double r110488 = fma(r110482, r110483, r110487);
        double r110489 = 2.0;
        double r110490 = r110489 * r110480;
        double r110491 = r110488 - r110490;
        double r110492 = 0.5;
        double r110493 = r110491 * r110492;
        double r110494 = re;
        double r110495 = sin(r110494);
        double r110496 = r110493 * r110495;
        return r110496;
}

Error

Bits error versus re

Bits error versus im

Target

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

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Simplified43.7

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

    \[\leadsto \left(\color{blue}{\left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)} \cdot 0.5\right) \cdot \sin re\]
  4. Simplified0.8

    \[\leadsto \left(\color{blue}{\left(\frac{-1}{3} \cdot {im}^{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, 2 \cdot im\right)\right)} \cdot 0.5\right) \cdot \sin re\]
  5. Using strategy rm
  6. Applied fma-udef0.8

    \[\leadsto \left(\left(\frac{-1}{3} \cdot {im}^{3} - \color{blue}{\left({im}^{5} \cdot \frac{1}{60} + 2 \cdot im\right)}\right) \cdot 0.5\right) \cdot \sin re\]
  7. Applied associate--r+0.8

    \[\leadsto \left(\color{blue}{\left(\left(\frac{-1}{3} \cdot {im}^{3} - {im}^{5} \cdot \frac{1}{60}\right) - 2 \cdot im\right)} \cdot 0.5\right) \cdot \sin re\]
  8. Simplified0.8

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

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

Reproduce

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