Average Error: 43.7 → 0.5
Time: 18.5s
Precision: binary64
Cost: 33025
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq 0.0001337472644404869:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(\sin re \cdot 0.5\right)\\ \end{array}\]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\begin{array}{l}
\mathbf{if}\;e^{-im} - e^{im} \leq 0.0001337472644404869:\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

\mathbf{else}:\\
\;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(\sin re \cdot 0.5\right)\\

\end{array}
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (if (<= (- (exp (- im)) (exp im)) 0.0001337472644404869)
   (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))
   (* (- (exp (- im)) (exp im)) (* (sin re) 0.5))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
	double tmp;
	if ((exp(-im) - exp(im)) <= 0.0001337472644404869) {
		tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else {
		tmp = (exp(-im) - exp(im)) * (sin(re) * 0.5);
	}
	return tmp;
}

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.7
Target0.3
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;\left|im\right| < 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \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}\]

Alternatives

Alternative 1
Error0.7
Cost20800
\[\left(\sin re \cdot 0.5\right) \cdot \left(\left(\left(im \cdot -2 - im \cdot \left(0.3333333333333333 \cdot \left(im \cdot im\right)\right)\right) - 0.016666666666666666 \cdot {im}^{5}\right) - 0.0003968253968253968 \cdot {im}^{7}\right)\]
Alternative 2
Error0.9
Cost13312
\[\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\]
Alternative 3
Error1.2
Cost6656
\[\left(-im\right) \cdot \sin re\]
Alternative 4
Error46.3
Cost64
\[0\]
Alternative 5
Error61.7
Cost64
\[1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 1.3374726444049e-4

    1. Initial program 44.3

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

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

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

      \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)}\]

    if 1.3374726444049e-4 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 3.1

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
    2. Simplified3.1

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq 0.0001337472644404869:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(\sin re \cdot 0.5\right)\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (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))))