Average Error: 58.0 → 0.7
Time: 29.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(2, im, \mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(2, im, \mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right)\right)
double f(double re, double im) {
        double r160480 = 0.5;
        double r160481 = re;
        double r160482 = cos(r160481);
        double r160483 = r160480 * r160482;
        double r160484 = 0.0;
        double r160485 = im;
        double r160486 = r160484 - r160485;
        double r160487 = exp(r160486);
        double r160488 = exp(r160485);
        double r160489 = r160487 - r160488;
        double r160490 = r160483 * r160489;
        return r160490;
}

double f(double re, double im) {
        double r160491 = 0.5;
        double r160492 = re;
        double r160493 = cos(r160492);
        double r160494 = r160491 * r160493;
        double r160495 = 2.0;
        double r160496 = im;
        double r160497 = 3.0;
        double r160498 = pow(r160496, r160497);
        double r160499 = 0.3333333333333333;
        double r160500 = 0.016666666666666666;
        double r160501 = 5.0;
        double r160502 = pow(r160496, r160501);
        double r160503 = r160500 * r160502;
        double r160504 = fma(r160498, r160499, r160503);
        double r160505 = fma(r160495, r160496, r160504);
        double r160506 = -r160505;
        double r160507 = r160494 * r160506;
        return r160507;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.0

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

    \[\leadsto \left(0.5 \cdot \cos 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 \cos 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 0 0.7

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

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))