Average Error: 44.2 → 0.7
Time: 23.6s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot \sin re, {im}^{5}, \sin re \cdot \left(1 \cdot im + 0.1666666666666666574148081281236954964697 \cdot {im}^{3}\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot \sin re, {im}^{5}, \sin re \cdot \left(1 \cdot im + 0.1666666666666666574148081281236954964697 \cdot {im}^{3}\right)\right)
double f(double re, double im) {
        double r139455 = 0.5;
        double r139456 = re;
        double r139457 = sin(r139456);
        double r139458 = r139455 * r139457;
        double r139459 = im;
        double r139460 = -r139459;
        double r139461 = exp(r139460);
        double r139462 = exp(r139459);
        double r139463 = r139461 - r139462;
        double r139464 = r139458 * r139463;
        return r139464;
}

double f(double re, double im) {
        double r139465 = 0.008333333333333333;
        double r139466 = re;
        double r139467 = sin(r139466);
        double r139468 = r139465 * r139467;
        double r139469 = im;
        double r139470 = 5.0;
        double r139471 = pow(r139469, r139470);
        double r139472 = 1.0;
        double r139473 = r139472 * r139469;
        double r139474 = 0.16666666666666666;
        double r139475 = 3.0;
        double r139476 = pow(r139469, r139475);
        double r139477 = r139474 * r139476;
        double r139478 = r139473 + r139477;
        double r139479 = r139467 * r139478;
        double r139480 = fma(r139468, r139471, r139479);
        double r139481 = -r139480;
        return r139481;
}

Error

Bits error versus re

Bits error versus im

Target

Original44.2
Target0.3
Herbie0.7
\[\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 44.2

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

    \[\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.7

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)}\]
  4. Taylor expanded around inf 0.7

    \[\leadsto \color{blue}{-\left(0.1666666666666666574148081281236954964697 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333217685101601546193705872 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot \sin re, {im}^{5}, \sin re \cdot \left(1 \cdot im + 0.1666666666666666574148081281236954964697 \cdot {im}^{3}\right)\right)}\]
  6. Final simplification0.7

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.166666666666666657 im) im) im)) (* (* (* (* (* 0.00833333333333333322 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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