Average Error: 43.2 → 31.7
Time: 32.4s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(-2 \cdot \left(re \cdot im\right)\right) \cdot 0.5\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(-2 \cdot \left(re \cdot im\right)\right) \cdot 0.5
double f(double re, double im) {
        double r9110052 = 0.5;
        double r9110053 = re;
        double r9110054 = sin(r9110053);
        double r9110055 = r9110052 * r9110054;
        double r9110056 = im;
        double r9110057 = -r9110056;
        double r9110058 = exp(r9110057);
        double r9110059 = exp(r9110056);
        double r9110060 = r9110058 - r9110059;
        double r9110061 = r9110055 * r9110060;
        return r9110061;
}

double f(double re, double im) {
        double r9110062 = -2.0;
        double r9110063 = re;
        double r9110064 = im;
        double r9110065 = r9110063 * r9110064;
        double r9110066 = r9110062 * r9110065;
        double r9110067 = 0.5;
        double r9110068 = r9110066 * r9110067;
        return r9110068;
}

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

Derivation

  1. Initial program 43.2

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Simplified43.2

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{\sin re}{e^{im}} - \sin re \cdot e^{im}\right)}\]
  3. Taylor expanded around 0 31.7

    \[\leadsto 0.5 \cdot \color{blue}{\left(-2 \cdot \left(re \cdot im\right)\right)}\]
  4. Final simplification31.7

    \[\leadsto \left(-2 \cdot \left(re \cdot im\right)\right) \cdot 0.5\]

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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