Average Error: 28.9 → 0.1
Time: 7.3s
Precision: binary64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
\[\begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \leq -0.1294210565445304 \lor \neg \left(t_0 \leq 1.558032003412535 \cdot 10^{-8}\right):\\ \;\;\;\;t_0 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \left({im}^{3} \cdot -0.3333333333333333 + im \cdot -2\right)\\ \end{array} \]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := 0.5 \cdot \cos re\\
\mathbf{if}\;t_0 \leq -0.1294210565445304 \lor \neg \left(t_0 \leq 1.558032003412535 \cdot 10^{-8}\right):\\
\;\;\;\;t_0 \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left({im}^{3} \cdot -0.3333333333333333 + im \cdot -2\right)\\


\end{array}
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* 0.5 (cos re))))
   (if (or (<= t_0 -0.1294210565445304) (not (<= t_0 1.558032003412535e-8)))
     (* t_0 t_1)
     (* t_1 (+ (* (pow im 3.0) -0.3333333333333333) (* im -2.0))))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp(0.0 - im) - exp(im));
}
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = 0.5 * cos(re);
	double tmp;
	if ((t_0 <= -0.1294210565445304) || !(t_0 <= 1.558032003412535e-8)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_1 * ((pow(im, 3.0) * -0.3333333333333333) + (im * -2.0));
	}
	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

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

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -0.1294210565445304 or 1.558032003e-8 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 0.1

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]

    if -0.1294210565445304 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1.558032003e-8

    1. Initial program 59.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -0.1294210565445304 \lor \neg \left(e^{-im} - e^{im} \leq 1.558032003412535 \cdot 10^{-8}\right):\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left({im}^{3} \cdot -0.3333333333333333 + im \cdot -2\right)\\ \end{array} \]

Reproduce

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

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