Average Error: 58.1 → 0.7
Time: 34.6s
Precision: 64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)\]
\[\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0.0 - im} - e^{im}\right)
\left(\frac{-1}{3} \cdot {im}^{3}\right) \cdot \left(0.5 \cdot \cos re\right) + \left(0.5 \cdot \cos re\right) \cdot \left(-\mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r165208 = 0.5;
        double r165209 = re;
        double r165210 = cos(r165209);
        double r165211 = r165208 * r165210;
        double r165212 = 0.0;
        double r165213 = im;
        double r165214 = r165212 - r165213;
        double r165215 = exp(r165214);
        double r165216 = exp(r165213);
        double r165217 = r165215 - r165216;
        double r165218 = r165211 * r165217;
        return r165218;
}

double f(double re, double im) {
        double r165219 = -0.3333333333333333;
        double r165220 = im;
        double r165221 = 3.0;
        double r165222 = pow(r165220, r165221);
        double r165223 = r165219 * r165222;
        double r165224 = 0.5;
        double r165225 = re;
        double r165226 = cos(r165225);
        double r165227 = r165224 * r165226;
        double r165228 = r165223 * r165227;
        double r165229 = 0.016666666666666666;
        double r165230 = 5.0;
        double r165231 = pow(r165220, r165230);
        double r165232 = 2.0;
        double r165233 = r165232 * r165220;
        double r165234 = fma(r165229, r165231, r165233);
        double r165235 = -r165234;
        double r165236 = r165227 * r165235;
        double r165237 = r165228 + r165236;
        return r165237;
}

Error

Bits error versus re

Bits error versus im

Target

Original58.1
Target0.2
Herbie0.7
\[\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.7

    \[\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. Simplified0.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-\mathsf{fma}\left(\frac{1}{3}, {im}^{3}, \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)\right)}\]
  4. Using strategy rm
  5. Applied fma-udef0.7

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(-\color{blue}{\left(\frac{1}{3} \cdot {im}^{3} + \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)}\right)\]
  6. Applied distribute-neg-in0.7

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

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

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

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

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(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))))