Average Error: 43.6 → 0.8
Time: 10.3s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)
double f(double re, double im) {
        double r425770 = 0.5;
        double r425771 = re;
        double r425772 = sin(r425771);
        double r425773 = r425770 * r425772;
        double r425774 = im;
        double r425775 = -r425774;
        double r425776 = exp(r425775);
        double r425777 = exp(r425774);
        double r425778 = r425776 - r425777;
        double r425779 = r425773 * r425778;
        return r425779;
}

double f(double re, double im) {
        double r425780 = 0.5;
        double r425781 = re;
        double r425782 = sin(r425781);
        double r425783 = r425780 * r425782;
        double r425784 = 0.3333333333333333;
        double r425785 = im;
        double r425786 = 3.0;
        double r425787 = pow(r425785, r425786);
        double r425788 = r425784 * r425787;
        double r425789 = 0.016666666666666666;
        double r425790 = 5.0;
        double r425791 = pow(r425785, r425790);
        double r425792 = r425789 * r425791;
        double r425793 = 2.0;
        double r425794 = r425793 * r425785;
        double r425795 = r425792 + r425794;
        double r425796 = r425788 + r425795;
        double r425797 = -r425796;
        double r425798 = r425783 * r425797;
        return r425798;
}

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.6
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.166666666666666657 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.00833333333333333322 \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.6

    \[\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. Final simplification0.8

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

Reproduce

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