Average Error: 58.0 → 0.7
Time: 32.5s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r7304985 = 0.5;
        double r7304986 = re;
        double r7304987 = cos(r7304986);
        double r7304988 = r7304985 * r7304987;
        double r7304989 = 0.0;
        double r7304990 = im;
        double r7304991 = r7304989 - r7304990;
        double r7304992 = exp(r7304991);
        double r7304993 = exp(r7304990);
        double r7304994 = r7304992 - r7304993;
        double r7304995 = r7304988 * r7304994;
        return r7304995;
}

double f(double re, double im) {
        double r7304996 = im;
        double r7304997 = r7304996 * r7304996;
        double r7304998 = r7304996 * r7304997;
        double r7304999 = -0.3333333333333333;
        double r7305000 = r7304998 * r7304999;
        double r7305001 = 5.0;
        double r7305002 = pow(r7304996, r7305001);
        double r7305003 = 0.016666666666666666;
        double r7305004 = r7304996 + r7304996;
        double r7305005 = fma(r7305002, r7305003, r7305004);
        double r7305006 = r7305000 - r7305005;
        double r7305007 = 0.5;
        double r7305008 = re;
        double r7305009 = cos(r7305008);
        double r7305010 = r7305007 * r7305009;
        double r7305011 = r7305006 * r7305010;
        return r7305011;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
Target0.3
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \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 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 58.0

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{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(\frac{-1}{3} \cdot \left(\left(im \cdot im\right) \cdot im\right) - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)}\]
  4. Using strategy rm
  5. Applied associate-*l*0.7

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

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

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (re im)
  :name "math.sin on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))