Average Error: 58.0 → 0.7
Time: 30.7s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\left(\left({im}^{5} \cdot \frac{-1}{60} - \left(2 + \left(im \cdot \frac{1}{3}\right) \cdot im\right) \cdot im\right) \cdot 0.5\right) \cdot \cos re\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\left({im}^{5} \cdot \frac{-1}{60} - \left(2 + \left(im \cdot \frac{1}{3}\right) \cdot im\right) \cdot im\right) \cdot 0.5\right) \cdot \cos re
double f(double re, double im) {
        double r9153829 = 0.5;
        double r9153830 = re;
        double r9153831 = cos(r9153830);
        double r9153832 = r9153829 * r9153831;
        double r9153833 = 0.0;
        double r9153834 = im;
        double r9153835 = r9153833 - r9153834;
        double r9153836 = exp(r9153835);
        double r9153837 = exp(r9153834);
        double r9153838 = r9153836 - r9153837;
        double r9153839 = r9153832 * r9153838;
        return r9153839;
}

double f(double re, double im) {
        double r9153840 = im;
        double r9153841 = 5.0;
        double r9153842 = pow(r9153840, r9153841);
        double r9153843 = -0.016666666666666666;
        double r9153844 = r9153842 * r9153843;
        double r9153845 = 2.0;
        double r9153846 = 0.3333333333333333;
        double r9153847 = r9153840 * r9153846;
        double r9153848 = r9153847 * r9153840;
        double r9153849 = r9153845 + r9153848;
        double r9153850 = r9153849 * r9153840;
        double r9153851 = r9153844 - r9153850;
        double r9153852 = 0.5;
        double r9153853 = r9153851 * r9153852;
        double r9153854 = re;
        double r9153855 = cos(r9153854);
        double r9153856 = r9153853 * r9153855;
        return r9153856;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

    \[\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}^{5} \cdot \frac{-1}{60} - \left(im + im\right)\right) - \left(im \cdot im\right) \cdot \left(im \cdot \frac{1}{3}\right)\right)}\]
  4. Using strategy rm
  5. Applied *-commutative0.7

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

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

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

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

Reproduce

herbie shell --seed 2019163 
(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))))