Average Error: 58.1 → 0.7
Time: 48.4s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\frac{im \cdot \left({\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)}^{3} + {1.0}^{3}\right)}{1.0 \cdot 1.0 + \left(\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) - 1.0 \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)\right)} + {im}^{5} \cdot 0.008333333333333333\right) \cdot \left(-\cos re\right)\]
double f(double re, double im) {
        double r23397755 = 0.5;
        double r23397756 = re;
        double r23397757 = cos(r23397756);
        double r23397758 = r23397755 * r23397757;
        double r23397759 = 0.0;
        double r23397760 = im;
        double r23397761 = r23397759 - r23397760;
        double r23397762 = exp(r23397761);
        double r23397763 = exp(r23397760);
        double r23397764 = r23397762 - r23397763;
        double r23397765 = r23397758 * r23397764;
        return r23397765;
}

double f(double re, double im) {
        double r23397766 = im;
        double r23397767 = 0.16666666666666666;
        double r23397768 = r23397766 * r23397766;
        double r23397769 = r23397767 * r23397768;
        double r23397770 = 3.0;
        double r23397771 = pow(r23397769, r23397770);
        double r23397772 = 1.0;
        double r23397773 = pow(r23397772, r23397770);
        double r23397774 = r23397771 + r23397773;
        double r23397775 = r23397766 * r23397774;
        double r23397776 = r23397772 * r23397772;
        double r23397777 = r23397769 * r23397769;
        double r23397778 = r23397772 * r23397769;
        double r23397779 = r23397777 - r23397778;
        double r23397780 = r23397776 + r23397779;
        double r23397781 = r23397775 / r23397780;
        double r23397782 = 5.0;
        double r23397783 = pow(r23397766, r23397782);
        double r23397784 = 0.008333333333333333;
        double r23397785 = r23397783 * r23397784;
        double r23397786 = r23397781 + r23397785;
        double r23397787 = re;
        double r23397788 = cos(r23397787);
        double r23397789 = -r23397788;
        double r23397790 = r23397786 * r23397789;
        return r23397790;
}

\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\frac{im \cdot \left({\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)}^{3} + {1.0}^{3}\right)}{1.0 \cdot 1.0 + \left(\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) - 1.0 \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)\right)} + {im}^{5} \cdot 0.008333333333333333\right) \cdot \left(-\cos re\right)

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.2
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.1

    \[\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}{60} \cdot {im}^{5} - \left(\left(\frac{1}{3} \cdot im\right) \cdot im + 2\right) \cdot im\right)}\]
  4. Taylor expanded around -inf 0.7

    \[\leadsto \color{blue}{-\left(1.0 \cdot \left(im \cdot \cos re\right) + \left(0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + 0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)\right)\right)}\]
  5. Simplified0.7

    \[\leadsto \color{blue}{\left(-\cos re\right) \cdot \left(im \cdot \left(1.0 + 0.16666666666666666 \cdot \left(im \cdot im\right)\right) + 0.008333333333333333 \cdot {im}^{5}\right)}\]
  6. Using strategy rm
  7. Applied flip3-+0.7

    \[\leadsto \left(-\cos re\right) \cdot \left(im \cdot \color{blue}{\frac{{1.0}^{3} + {\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)}^{3}}{1.0 \cdot 1.0 + \left(\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) - 1.0 \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)\right)}} + 0.008333333333333333 \cdot {im}^{5}\right)\]
  8. Applied associate-*r/0.7

    \[\leadsto \left(-\cos re\right) \cdot \left(\color{blue}{\frac{im \cdot \left({1.0}^{3} + {\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)}^{3}\right)}{1.0 \cdot 1.0 + \left(\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) - 1.0 \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)\right)}} + 0.008333333333333333 \cdot {im}^{5}\right)\]
  9. Final simplification0.7

    \[\leadsto \left(\frac{im \cdot \left({\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)}^{3} + {1.0}^{3}\right)}{1.0 \cdot 1.0 + \left(\left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right) - 1.0 \cdot \left(0.16666666666666666 \cdot \left(im \cdot im\right)\right)\right)} + {im}^{5} \cdot 0.008333333333333333\right) \cdot \left(-\cos re\right)\]

Reproduce

herbie shell --seed 2019102 
(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))))