Average Error: 58.1 → 0.7
Time: 10.5s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(-0.166666666666666657 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.00833333333333333322, \cos re \cdot {im}^{5}, 1 \cdot \left(\cos re \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(-0.166666666666666657 \cdot \left(\cos re \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(0.00833333333333333322, \cos re \cdot {im}^{5}, 1 \cdot \left(\cos re \cdot im\right)\right)
double f(double re, double im) {
        double r184938 = 0.5;
        double r184939 = re;
        double r184940 = cos(r184939);
        double r184941 = r184938 * r184940;
        double r184942 = 0.0;
        double r184943 = im;
        double r184944 = r184942 - r184943;
        double r184945 = exp(r184944);
        double r184946 = exp(r184943);
        double r184947 = r184945 - r184946;
        double r184948 = r184941 * r184947;
        return r184948;
}

double f(double re, double im) {
        double r184949 = 0.16666666666666666;
        double r184950 = re;
        double r184951 = cos(r184950);
        double r184952 = im;
        double r184953 = 3.0;
        double r184954 = pow(r184952, r184953);
        double r184955 = r184951 * r184954;
        double r184956 = r184949 * r184955;
        double r184957 = -r184956;
        double r184958 = 0.008333333333333333;
        double r184959 = 5.0;
        double r184960 = pow(r184952, r184959);
        double r184961 = r184951 * r184960;
        double r184962 = 1.0;
        double r184963 = r184951 * r184952;
        double r184964 = r184962 * r184963;
        double r184965 = fma(r184958, r184961, r184964);
        double r184966 = r184957 - r184965;
        return r184966;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \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(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\]
  4. Taylor expanded around inf 0.7

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

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

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

Reproduce

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