Average Error: 43.5 → 0.8
Time: 10.4s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\left(0.5 \cdot \sin re\right) \cdot {im}^{3}\right) \cdot \frac{-1}{3} + \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(0.5 \cdot \sin re\right) \cdot {im}^{3}\right) \cdot \frac{-1}{3} + \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r270957 = 0.5;
        double r270958 = re;
        double r270959 = sin(r270958);
        double r270960 = r270957 * r270959;
        double r270961 = im;
        double r270962 = -r270961;
        double r270963 = exp(r270962);
        double r270964 = exp(r270961);
        double r270965 = r270963 - r270964;
        double r270966 = r270960 * r270965;
        return r270966;
}

double f(double re, double im) {
        double r270967 = 0.5;
        double r270968 = re;
        double r270969 = sin(r270968);
        double r270970 = r270967 * r270969;
        double r270971 = im;
        double r270972 = 3.0;
        double r270973 = pow(r270971, r270972);
        double r270974 = r270970 * r270973;
        double r270975 = -0.3333333333333333;
        double r270976 = r270974 * r270975;
        double r270977 = 0.016666666666666666;
        double r270978 = 5.0;
        double r270979 = pow(r270971, r270978);
        double r270980 = r270977 * r270979;
        double r270981 = 2.0;
        double r270982 = r270981 * r270971;
        double r270983 = r270980 + r270982;
        double r270984 = -r270983;
        double r270985 = r270970 * r270984;
        double r270986 = r270976 + r270985;
        return r270986;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.5
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.5

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin 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. Using strategy rm
  4. Applied distribute-neg-in0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) + \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  5. Applied distribute-lft-in0.8

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

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

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

Reproduce

herbie shell --seed 2019354 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))