Average Error: 58.1 → 0.7
Time: 8.8s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(\left(-\mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right) - 2 \cdot im\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(\left(-\mathsf{fma}\left({im}^{3}, \frac{1}{3}, \frac{1}{60} \cdot {im}^{5}\right)\right) - 2 \cdot im\right)
double f(double re, double im) {
        double r212872 = 0.5;
        double r212873 = re;
        double r212874 = cos(r212873);
        double r212875 = r212872 * r212874;
        double r212876 = 0.0;
        double r212877 = im;
        double r212878 = r212876 - r212877;
        double r212879 = exp(r212878);
        double r212880 = exp(r212877);
        double r212881 = r212879 - r212880;
        double r212882 = r212875 * r212881;
        return r212882;
}

double f(double re, double im) {
        double r212883 = 0.5;
        double r212884 = re;
        double r212885 = cos(r212884);
        double r212886 = r212883 * r212885;
        double r212887 = im;
        double r212888 = 3.0;
        double r212889 = pow(r212887, r212888);
        double r212890 = 0.3333333333333333;
        double r212891 = 0.016666666666666666;
        double r212892 = 5.0;
        double r212893 = pow(r212887, r212892);
        double r212894 = r212891 * r212893;
        double r212895 = fma(r212889, r212890, r212894);
        double r212896 = -r212895;
        double r212897 = 2.0;
        double r212898 = r212897 * r212887;
        double r212899 = r212896 - r212898;
        double r212900 = r212886 * r212899;
        return r212900;
}

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(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.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(\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 fma-udef0.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \color{blue}{\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)}\right)\]
  6. Applied associate--r+0.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) - \frac{1}{60} \cdot {im}^{5}\right) - 2 \cdot im\right)}\]
  7. Simplified0.7

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

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

Reproduce

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

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