Average Error: 58.1 → 0.7
Time: 31.1s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \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(\frac{-1}{3} \cdot \left(im \cdot \left(im \cdot im\right)\right) - \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 r3052140 = 0.5;
        double r3052141 = re;
        double r3052142 = cos(r3052141);
        double r3052143 = r3052140 * r3052142;
        double r3052144 = 0.0;
        double r3052145 = im;
        double r3052146 = r3052144 - r3052145;
        double r3052147 = exp(r3052146);
        double r3052148 = exp(r3052145);
        double r3052149 = r3052147 - r3052148;
        double r3052150 = r3052143 * r3052149;
        return r3052150;
}

double f(double re, double im) {
        double r3052151 = -0.3333333333333333;
        double r3052152 = im;
        double r3052153 = r3052152 * r3052152;
        double r3052154 = r3052152 * r3052153;
        double r3052155 = r3052151 * r3052154;
        double r3052156 = 5.0;
        double r3052157 = pow(r3052152, r3052156);
        double r3052158 = 0.016666666666666666;
        double r3052159 = r3052152 + r3052152;
        double r3052160 = fma(r3052157, r3052158, r3052159);
        double r3052161 = r3052155 - r3052160;
        double r3052162 = 0.5;
        double r3052163 = re;
        double r3052164 = cos(r3052163);
        double r3052165 = r3052162 * r3052164;
        double r3052166 = r3052161 * r3052165;
        return r3052166;
}

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(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3} - \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)}\]
  4. Final simplification0.7

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

Reproduce

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