Average Error: 58.0 → 0.9
Time: 11.7s
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(-\log \left(e^{\frac{1}{3} \cdot {im}^{3}}\right)\right) - \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(0.5 \cdot \cos re\right) \cdot \left(\left(-\log \left(e^{\frac{1}{3} \cdot {im}^{3}}\right)\right) - \mathsf{fma}\left(\frac{1}{60}, {im}^{5}, 2 \cdot im\right)\right)
double f(double re, double im) {
        double r223954 = 0.5;
        double r223955 = re;
        double r223956 = cos(r223955);
        double r223957 = r223954 * r223956;
        double r223958 = 0.0;
        double r223959 = im;
        double r223960 = r223958 - r223959;
        double r223961 = exp(r223960);
        double r223962 = exp(r223959);
        double r223963 = r223961 - r223962;
        double r223964 = r223957 * r223963;
        return r223964;
}

double f(double re, double im) {
        double r223965 = 0.5;
        double r223966 = re;
        double r223967 = cos(r223966);
        double r223968 = r223965 * r223967;
        double r223969 = 0.3333333333333333;
        double r223970 = im;
        double r223971 = 3.0;
        double r223972 = pow(r223970, r223971);
        double r223973 = r223969 * r223972;
        double r223974 = exp(r223973);
        double r223975 = log(r223974);
        double r223976 = -r223975;
        double r223977 = 0.016666666666666666;
        double r223978 = 5.0;
        double r223979 = pow(r223970, r223978);
        double r223980 = 2.0;
        double r223981 = r223980 * r223970;
        double r223982 = fma(r223977, r223979, r223981);
        double r223983 = r223976 - r223982;
        double r223984 = r223968 * r223983;
        return r223984;
}

Error

Bits error versus re

Bits error versus im

Target

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

Derivation

  1. Initial program 58.0

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

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

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

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

Reproduce

herbie shell --seed 2020035 +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))))