Average Error: 58.0 → 0.8
Time: 19.2s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r218240 = 0.5;
        double r218241 = re;
        double r218242 = cos(r218241);
        double r218243 = r218240 * r218242;
        double r218244 = 0.0;
        double r218245 = im;
        double r218246 = r218244 - r218245;
        double r218247 = exp(r218246);
        double r218248 = exp(r218245);
        double r218249 = r218247 - r218248;
        double r218250 = r218243 * r218249;
        return r218250;
}

double f(double re, double im) {
        double r218251 = -0.3333333333333333;
        double r218252 = im;
        double r218253 = 3.0;
        double r218254 = pow(r218252, r218253);
        double r218255 = r218251 * r218254;
        double r218256 = 0.5;
        double r218257 = re;
        double r218258 = cos(r218257);
        double r218259 = r218256 * r218258;
        double r218260 = r218255 * r218259;
        double r218261 = 0.016666666666666666;
        double r218262 = 5.0;
        double r218263 = pow(r218252, r218262);
        double r218264 = 2.0;
        double r218265 = r218264 * r218252;
        double r218266 = fma(r218261, r218263, r218265);
        double r218267 = -r218266;
        double r218268 = r218259 * r218267;
        double r218269 = r218260 + r218268;
        return r218269;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.2
Herbie0.8
\[\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.8

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

    \[\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. Using strategy rm
  5. Applied fma-udef0.8

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(-\color{blue}{\left(\frac{1}{3} \cdot {im}^{3} + \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\right)\]
  6. Applied distribute-neg-in0.8

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) + \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)}\]
  7. Applied distribute-lft-in0.8

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

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

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

Reproduce

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