Average Error: 58.1 → 0.8
Time: 9.4s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(0.5 \cdot \cos re\right) \cdot \left(-\left(\left(\frac{1}{3} \cdot {im}^{3} + \frac{1}{60} \cdot {im}^{5}\right) + 2 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(0.5 \cdot \cos re\right) \cdot \left(-\left(\left(\frac{1}{3} \cdot {im}^{3} + \frac{1}{60} \cdot {im}^{5}\right) + 2 \cdot im\right)\right)
double f(double re, double im) {
        double r202641 = 0.5;
        double r202642 = re;
        double r202643 = cos(r202642);
        double r202644 = r202641 * r202643;
        double r202645 = 0.0;
        double r202646 = im;
        double r202647 = r202645 - r202646;
        double r202648 = exp(r202647);
        double r202649 = exp(r202646);
        double r202650 = r202648 - r202649;
        double r202651 = r202644 * r202650;
        return r202651;
}

double f(double re, double im) {
        double r202652 = 0.5;
        double r202653 = re;
        double r202654 = cos(r202653);
        double r202655 = r202652 * r202654;
        double r202656 = 0.3333333333333333;
        double r202657 = im;
        double r202658 = 3.0;
        double r202659 = pow(r202657, r202658);
        double r202660 = r202656 * r202659;
        double r202661 = 0.016666666666666666;
        double r202662 = 5.0;
        double r202663 = pow(r202657, r202662);
        double r202664 = r202661 * r202663;
        double r202665 = r202660 + r202664;
        double r202666 = 2.0;
        double r202667 = r202666 * r202657;
        double r202668 = r202665 + r202667;
        double r202669 = -r202668;
        double r202670 = r202655 * r202669;
        return r202670;
}

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

Derivation

  1. Initial program 58.1

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

    \[\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. Using strategy rm
  4. Applied associate-+r+0.8

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

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

Reproduce

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

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

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))