Average Error: 58.1 → 0.7
Time: 33.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
-\mathsf{fma}\left(0.008333333333333333217685101601546193705872 \cdot {im}^{5}, \cos re, \cos re \cdot \mathsf{fma}\left(0.1666666666666666574148081281236954964697, {im}^{3}, 1 \cdot im\right)\right)
double f(double re, double im) {
        double r123945 = 0.5;
        double r123946 = re;
        double r123947 = cos(r123946);
        double r123948 = r123945 * r123947;
        double r123949 = 0.0;
        double r123950 = im;
        double r123951 = r123949 - r123950;
        double r123952 = exp(r123951);
        double r123953 = exp(r123950);
        double r123954 = r123952 - r123953;
        double r123955 = r123948 * r123954;
        return r123955;
}

double f(double re, double im) {
        double r123956 = 0.008333333333333333;
        double r123957 = im;
        double r123958 = 5.0;
        double r123959 = pow(r123957, r123958);
        double r123960 = r123956 * r123959;
        double r123961 = re;
        double r123962 = cos(r123961);
        double r123963 = 0.16666666666666666;
        double r123964 = 3.0;
        double r123965 = pow(r123957, r123964);
        double r123966 = 1.0;
        double r123967 = r123966 * r123957;
        double r123968 = fma(r123963, r123965, r123967);
        double r123969 = r123962 * r123968;
        double r123970 = fma(r123960, r123962, r123969);
        double r123971 = -r123970;
        return r123971;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
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.1

    \[\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 inf 0.7

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

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

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

Reproduce

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