Average Error: 43.5 → 0.9
Time: 53.5s
Precision: 64
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(\sin re \cdot \left(im \cdot -0.16666666666666666\right)\right) \cdot \left(im \cdot im\right) - \left(im \cdot 1.0 + \log \left(e^{0.008333333333333333 \cdot {im}^{5}}\right)\right) \cdot \sin re\]
double f(double re, double im) {
        double r46308457 = 0.5;
        double r46308458 = re;
        double r46308459 = sin(r46308458);
        double r46308460 = r46308457 * r46308459;
        double r46308461 = im;
        double r46308462 = -r46308461;
        double r46308463 = exp(r46308462);
        double r46308464 = exp(r46308461);
        double r46308465 = r46308463 - r46308464;
        double r46308466 = r46308460 * r46308465;
        return r46308466;
}

double f(double re, double im) {
        double r46308467 = re;
        double r46308468 = sin(r46308467);
        double r46308469 = im;
        double r46308470 = -0.16666666666666666;
        double r46308471 = r46308469 * r46308470;
        double r46308472 = r46308468 * r46308471;
        double r46308473 = r46308469 * r46308469;
        double r46308474 = r46308472 * r46308473;
        double r46308475 = 1.0;
        double r46308476 = r46308469 * r46308475;
        double r46308477 = 0.008333333333333333;
        double r46308478 = 5.0;
        double r46308479 = pow(r46308469, r46308478);
        double r46308480 = r46308477 * r46308479;
        double r46308481 = exp(r46308480);
        double r46308482 = log(r46308481);
        double r46308483 = r46308476 + r46308482;
        double r46308484 = r46308483 * r46308468;
        double r46308485 = r46308474 - r46308484;
        return r46308485;
}

\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\sin re \cdot \left(im \cdot -0.16666666666666666\right)\right) \cdot \left(im \cdot im\right) - \left(im \cdot 1.0 + \log \left(e^{0.008333333333333333 \cdot {im}^{5}}\right)\right) \cdot \sin re

Error

Bits error versus re

Bits error versus im

Target

Original43.5
Target0.3
Herbie0.9
\[\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.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. Simplified0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\frac{-1}{60} \cdot {im}^{5} - \left(\left(\frac{1}{3} \cdot im\right) \cdot im + 2\right) \cdot im\right)}\]
  4. Taylor expanded around -inf 0.8

    \[\leadsto \color{blue}{-\left(0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(1.0 \cdot \left(\sin re \cdot im\right) + 0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right)\right)\right)}\]
  5. Simplified0.8

    \[\leadsto \color{blue}{\left(\left(-im\right) \cdot \left(im \cdot im\right)\right) \cdot \left(0.16666666666666666 \cdot \sin re\right) - \sin re \cdot \left(0.008333333333333333 \cdot {im}^{5} + 1.0 \cdot im\right)}\]
  6. Taylor expanded around inf 0.8

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)} - \sin re \cdot \left(0.008333333333333333 \cdot {im}^{5} + 1.0 \cdot im\right)\]
  7. Simplified0.8

    \[\leadsto \color{blue}{\left(\sin re \cdot \left(im \cdot -0.16666666666666666\right)\right) \cdot \left(im \cdot im\right)} - \sin re \cdot \left(0.008333333333333333 \cdot {im}^{5} + 1.0 \cdot im\right)\]
  8. Using strategy rm
  9. Applied add-log-exp0.9

    \[\leadsto \left(\sin re \cdot \left(im \cdot -0.16666666666666666\right)\right) \cdot \left(im \cdot im\right) - \sin re \cdot \left(\color{blue}{\log \left(e^{0.008333333333333333 \cdot {im}^{5}}\right)} + 1.0 \cdot im\right)\]
  10. Final simplification0.9

    \[\leadsto \left(\sin re \cdot \left(im \cdot -0.16666666666666666\right)\right) \cdot \left(im \cdot im\right) - \left(im \cdot 1.0 + \log \left(e^{0.008333333333333333 \cdot {im}^{5}}\right)\right) \cdot \sin re\]

Reproduce

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