Average Error: 58.1 → 0.7
Time: 41.3s
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(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\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(2, im, \left({im}^{5} \cdot \frac{1}{60}\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)
double f(double re, double im) {
        double r6714813 = 0.5;
        double r6714814 = re;
        double r6714815 = cos(r6714814);
        double r6714816 = r6714813 * r6714815;
        double r6714817 = 0.0;
        double r6714818 = im;
        double r6714819 = r6714817 - r6714818;
        double r6714820 = exp(r6714819);
        double r6714821 = exp(r6714818);
        double r6714822 = r6714820 - r6714821;
        double r6714823 = r6714816 * r6714822;
        return r6714823;
}

double f(double re, double im) {
        double r6714824 = -0.3333333333333333;
        double r6714825 = im;
        double r6714826 = r6714825 * r6714825;
        double r6714827 = r6714825 * r6714826;
        double r6714828 = r6714824 * r6714827;
        double r6714829 = 2.0;
        double r6714830 = 5.0;
        double r6714831 = pow(r6714825, r6714830);
        double r6714832 = 0.016666666666666666;
        double r6714833 = r6714831 * r6714832;
        double r6714834 = fma(r6714829, r6714825, r6714833);
        double r6714835 = r6714828 - r6714834;
        double r6714836 = 0.5;
        double r6714837 = re;
        double r6714838 = cos(r6714837);
        double r6714839 = r6714836 * r6714838;
        double r6714840 = r6714835 * r6714839;
        return r6714840;
}

Error

Bits error versus re

Bits error versus im

Target

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

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

Reproduce

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