Average Error: 57.9 → 0.8
Time: 54.9s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3}\right) \cdot \left(\cos re \cdot 0.5\right) + \left(\left(-0.5\right) \cdot \cos re\right) \cdot \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\left(im \cdot \left(im \cdot im\right)\right) \cdot \frac{-1}{3}\right) \cdot \left(\cos re \cdot 0.5\right) + \left(\left(-0.5\right) \cdot \cos re\right) \cdot \mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)
double f(double re, double im) {
        double r6376306 = 0.5;
        double r6376307 = re;
        double r6376308 = cos(r6376307);
        double r6376309 = r6376306 * r6376308;
        double r6376310 = 0.0;
        double r6376311 = im;
        double r6376312 = r6376310 - r6376311;
        double r6376313 = exp(r6376312);
        double r6376314 = exp(r6376311);
        double r6376315 = r6376313 - r6376314;
        double r6376316 = r6376309 * r6376315;
        return r6376316;
}

double f(double re, double im) {
        double r6376317 = im;
        double r6376318 = r6376317 * r6376317;
        double r6376319 = r6376317 * r6376318;
        double r6376320 = -0.3333333333333333;
        double r6376321 = r6376319 * r6376320;
        double r6376322 = re;
        double r6376323 = cos(r6376322);
        double r6376324 = 0.5;
        double r6376325 = r6376323 * r6376324;
        double r6376326 = r6376321 * r6376325;
        double r6376327 = -r6376324;
        double r6376328 = r6376327 * r6376323;
        double r6376329 = 5.0;
        double r6376330 = pow(r6376317, r6376329);
        double r6376331 = 0.016666666666666666;
        double r6376332 = r6376317 + r6376317;
        double r6376333 = fma(r6376330, r6376331, r6376332);
        double r6376334 = r6376328 * r6376333;
        double r6376335 = r6376326 + r6376334;
        return r6376335;
}

Error

Bits error versus re

Bits error versus im

Target

Original57.9
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.1666666666666666574148081281236954964697 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333217685101601546193705872 \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 57.9

    \[\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(\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. Using strategy rm
  5. Applied sub-neg0.8

    \[\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} + \left(-\mathsf{fma}\left({im}^{5}, \frac{1}{60}, im + im\right)\right)\right)}\]
  6. Applied distribute-rgt-in0.8

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

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

Reproduce

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