Average Error: 58.1 → 0.7
Time: 8.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 r214022 = 0.5;
        double r214023 = re;
        double r214024 = cos(r214023);
        double r214025 = r214022 * r214024;
        double r214026 = 0.0;
        double r214027 = im;
        double r214028 = r214026 - r214027;
        double r214029 = exp(r214028);
        double r214030 = exp(r214027);
        double r214031 = r214029 - r214030;
        double r214032 = r214025 * r214031;
        return r214032;
}

double f(double re, double im) {
        double r214033 = 0.16666666666666666;
        double r214034 = re;
        double r214035 = cos(r214034);
        double r214036 = im;
        double r214037 = 3.0;
        double r214038 = pow(r214036, r214037);
        double r214039 = r214035 * r214038;
        double r214040 = r214033 * r214039;
        double r214041 = -r214040;
        double r214042 = 0.008333333333333333;
        double r214043 = 5.0;
        double r214044 = pow(r214036, r214043);
        double r214045 = r214035 * r214044;
        double r214046 = 1.0;
        double r214047 = r214035 * r214036;
        double r214048 = r214046 * r214047;
        double r214049 = fma(r214042, r214045, r214048);
        double r214050 = r214041 - r214049;
        return r214050;
}

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 2020065 +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))))