Average Error: 58.0 → 0.8
Time: 8.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[0.5 \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \cos re\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
0.5 \cdot \left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right) \cdot \cos re\right)
double f(double re, double im) {
        double r290231 = 0.5;
        double r290232 = re;
        double r290233 = cos(r290232);
        double r290234 = r290231 * r290233;
        double r290235 = 0.0;
        double r290236 = im;
        double r290237 = r290235 - r290236;
        double r290238 = exp(r290237);
        double r290239 = exp(r290236);
        double r290240 = r290238 - r290239;
        double r290241 = r290234 * r290240;
        return r290241;
}

double f(double re, double im) {
        double r290242 = 0.5;
        double r290243 = 0.3333333333333333;
        double r290244 = im;
        double r290245 = 3.0;
        double r290246 = pow(r290244, r290245);
        double r290247 = 0.016666666666666666;
        double r290248 = 5.0;
        double r290249 = pow(r290244, r290248);
        double r290250 = 2.0;
        double r290251 = r290250 * r290244;
        double r290252 = fma(r290247, r290249, r290251);
        double r290253 = fma(r290243, r290246, r290252);
        double r290254 = re;
        double r290255 = cos(r290254);
        double r290256 = r290253 * r290255;
        double r290257 = -r290256;
        double r290258 = r290242 * r290257;
        return r290258;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.0
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.0

    \[\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(\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 associate-*l*0.8

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

    \[\leadsto 0.5 \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) \cdot \cos re\right)}\]
  7. Final simplification0.8

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

Reproduce

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