Average Error: 44.1 → 0.8
Time: 10.1s
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(-\left(\sqrt[3]{\frac{1}{3}} \cdot \sqrt[3]{\frac{1}{3}}\right) \cdot \left(\sqrt[3]{\frac{1}{3}} \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\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(-\left(\sqrt[3]{\frac{1}{3}} \cdot \sqrt[3]{\frac{1}{3}}\right) \cdot \left(\sqrt[3]{\frac{1}{3}} \cdot {im}^{3}\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r277234 = 0.5;
        double r277235 = re;
        double r277236 = sin(r277235);
        double r277237 = r277234 * r277236;
        double r277238 = im;
        double r277239 = -r277238;
        double r277240 = exp(r277239);
        double r277241 = exp(r277238);
        double r277242 = r277240 - r277241;
        double r277243 = r277237 * r277242;
        return r277243;
}

double f(double re, double im) {
        double r277244 = 0.5;
        double r277245 = re;
        double r277246 = sin(r277245);
        double r277247 = r277244 * r277246;
        double r277248 = 0.3333333333333333;
        double r277249 = cbrt(r277248);
        double r277250 = r277249 * r277249;
        double r277251 = im;
        double r277252 = 3.0;
        double r277253 = pow(r277251, r277252);
        double r277254 = r277249 * r277253;
        double r277255 = r277250 * r277254;
        double r277256 = -r277255;
        double r277257 = 0.016666666666666666;
        double r277258 = 5.0;
        double r277259 = pow(r277251, r277258);
        double r277260 = 2.0;
        double r277261 = r277260 * r277251;
        double r277262 = fma(r277257, r277259, r277261);
        double r277263 = r277256 - r277262;
        double r277264 = r277247 * r277263;
        return r277264;
}

Error

Bits error versus re

Bits error versus im

Target

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

Derivation

  1. Initial program 44.1

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

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

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\left(-\color{blue}{\left(\left(\sqrt[3]{\frac{1}{3}} \cdot \sqrt[3]{\frac{1}{3}}\right) \cdot \sqrt[3]{\frac{1}{3}}\right)} \cdot {im}^{3}\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
  6. Applied associate-*l*0.8

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

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

Reproduce

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