Average Error: 43.7 → 0.7
Time: 9.4s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - {\left(\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}^{1}\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - {\left(\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}^{1}\right)
double f(double re, double im) {
        double r233111 = 0.5;
        double r233112 = re;
        double r233113 = sin(r233112);
        double r233114 = r233111 * r233113;
        double r233115 = im;
        double r233116 = -r233115;
        double r233117 = exp(r233116);
        double r233118 = exp(r233115);
        double r233119 = r233117 - r233118;
        double r233120 = r233114 * r233119;
        return r233120;
}

double f(double re, double im) {
        double r233121 = 0.5;
        double r233122 = re;
        double r233123 = sin(r233122);
        double r233124 = r233121 * r233123;
        double r233125 = 0.3333333333333333;
        double r233126 = im;
        double r233127 = 3.0;
        double r233128 = pow(r233126, r233127);
        double r233129 = r233125 * r233128;
        double r233130 = -r233129;
        double r233131 = 0.016666666666666666;
        double r233132 = 5.0;
        double r233133 = pow(r233126, r233132);
        double r233134 = 2.0;
        double r233135 = r233134 * r233126;
        double r233136 = fma(r233131, r233133, r233135);
        double r233137 = 1.0;
        double r233138 = pow(r233136, r233137);
        double r233139 = r233130 - r233138;
        double r233140 = r233124 * r233139;
        return r233140;
}

Error

Bits error versus re

Bits error versus im

Target

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

Derivation

  1. Initial program 43.7

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

    \[\leadsto \left(0.5 \cdot \sin 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 \sin 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. Using strategy rm
  5. Applied pow10.7

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

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

Reproduce

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

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

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))