Average Error: 58.1 → 0.8
Time: 26.1s
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(\cos re \cdot 0.5\right) + \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \left(\cos re \cdot 0.5\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(\cos re \cdot 0.5\right) + \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \left(\cos re \cdot 0.5\right)
double f(double re, double im) {
        double r109837 = 0.5;
        double r109838 = re;
        double r109839 = cos(r109838);
        double r109840 = r109837 * r109839;
        double r109841 = 0.0;
        double r109842 = im;
        double r109843 = r109841 - r109842;
        double r109844 = exp(r109843);
        double r109845 = exp(r109842);
        double r109846 = r109844 - r109845;
        double r109847 = r109840 * r109846;
        return r109847;
}

double f(double re, double im) {
        double r109848 = -0.3333333333333333;
        double r109849 = im;
        double r109850 = 3.0;
        double r109851 = pow(r109849, r109850);
        double r109852 = r109848 * r109851;
        double r109853 = re;
        double r109854 = cos(r109853);
        double r109855 = 0.5;
        double r109856 = r109854 * r109855;
        double r109857 = r109852 * r109856;
        double r109858 = 0.016666666666666666;
        double r109859 = 5.0;
        double r109860 = pow(r109849, r109859);
        double r109861 = 2.0;
        double r109862 = r109861 * r109849;
        double r109863 = fma(r109858, r109860, r109862);
        double r109864 = -r109863;
        double r109865 = r109864 * r109856;
        double r109866 = r109857 + r109865;
        return r109866;
}

Error

Bits error versus re

Bits error versus im

Target

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

Derivation

  1. Initial program 58.1

    \[\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(\cos re \cdot 0.5\right)} + \left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
  9. Simplified0.8

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

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

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (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))))