math.sin on complex, imaginary part

Percentage Accurate: 54.4% → 99.7%
Time: 11.3s
Alternatives: 9
Speedup: 2.8×

Specification

?
\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 54.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \cos re\\ t_1 := e^{-im} - e^{im}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0.01\right):\\ \;\;\;\;t_0 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (cos re))) (t_1 (- (exp (- im)) (exp im))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 0.01)))
     (* t_0 t_1)
     (*
      t_0
      (+
       (* im -2.0)
       (+
        (* -0.3333333333333333 (pow im 3.0))
        (* -0.016666666666666666 (pow im 5.0))))))))
double code(double re, double im) {
	double t_0 = 0.5 * cos(re);
	double t_1 = exp(-im) - exp(im);
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 0.01)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_0 * ((im * -2.0) + ((-0.3333333333333333 * pow(im, 3.0)) + (-0.016666666666666666 * pow(im, 5.0))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.cos(re);
	double t_1 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 0.01)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_0 * ((im * -2.0) + ((-0.3333333333333333 * Math.pow(im, 3.0)) + (-0.016666666666666666 * Math.pow(im, 5.0))));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.cos(re)
	t_1 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 0.01):
		tmp = t_0 * t_1
	else:
		tmp = t_0 * ((im * -2.0) + ((-0.3333333333333333 * math.pow(im, 3.0)) + (-0.016666666666666666 * math.pow(im, 5.0))))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * cos(re))
	t_1 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 0.01))
		tmp = Float64(t_0 * t_1);
	else
		tmp = Float64(t_0 * Float64(Float64(im * -2.0) + Float64(Float64(-0.3333333333333333 * (im ^ 3.0)) + Float64(-0.016666666666666666 * (im ^ 5.0)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * cos(re);
	t_1 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 0.01)))
		tmp = t_0 * t_1;
	else
		tmp = t_0 * ((im * -2.0) + ((-0.3333333333333333 * (im ^ 3.0)) + (-0.016666666666666666 * (im ^ 5.0))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 0.01]], $MachinePrecision]], N[(t$95$0 * t$95$1), $MachinePrecision], N[(t$95$0 * N[(N[(im * -2.0), $MachinePrecision] + N[(N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
t_1 := e^{-im} - e^{im}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 0.01\right):\\
\;\;\;\;t_0 \cdot t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0 or 0.0100000000000000002 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg100.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified100.0%

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 0.0100000000000000002

    1. Initial program 8.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg8.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified8.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 99.8%

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

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

Alternative 2: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 2 \cdot 10^{-6}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e-6)))
     (* (* 0.5 (cos re)) t_0)
     (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e-6)) {
		tmp = (0.5 * cos(re)) * t_0;
	} else {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 2e-6)) {
		tmp = (0.5 * Math.cos(re)) * t_0;
	} else {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 2e-6):
		tmp = (0.5 * math.cos(re)) * t_0
	else:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e-6))
		tmp = Float64(Float64(0.5 * cos(re)) * t_0);
	else
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 2e-6)))
		tmp = (0.5 * cos(re)) * t_0;
	else
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e-6]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 2 \cdot 10^{-6}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0 or 1.99999999999999991e-6 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 99.9%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg99.9%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified99.9%

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1.99999999999999991e-6

    1. Initial program 7.3%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg7.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 99.8%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg99.8%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg99.8%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) - im \cdot \cos re} \]
      4. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative99.8%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified99.8%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

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

Alternative 3: 97.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\ t_1 := {im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.0027:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 0.00094:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (- (exp (- im)) (exp im))))
        (t_1 (* (pow im 5.0) (* (cos re) -0.008333333333333333))))
   (if (<= im -4.5e+61)
     t_1
     (if (<= im -0.0027)
       t_0
       (if (<= im 0.00094)
         (* im (- (cos re)))
         (if (<= im 4.5e+61) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = 0.5 * (exp(-im) - exp(im));
	double t_1 = pow(im, 5.0) * (cos(re) * -0.008333333333333333);
	double tmp;
	if (im <= -4.5e+61) {
		tmp = t_1;
	} else if (im <= -0.0027) {
		tmp = t_0;
	} else if (im <= 0.00094) {
		tmp = im * -cos(re);
	} else if (im <= 4.5e+61) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * (exp(-im) - exp(im))
    t_1 = (im ** 5.0d0) * (cos(re) * (-0.008333333333333333d0))
    if (im <= (-4.5d+61)) then
        tmp = t_1
    else if (im <= (-0.0027d0)) then
        tmp = t_0
    else if (im <= 0.00094d0) then
        tmp = im * -cos(re)
    else if (im <= 4.5d+61) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * (Math.exp(-im) - Math.exp(im));
	double t_1 = Math.pow(im, 5.0) * (Math.cos(re) * -0.008333333333333333);
	double tmp;
	if (im <= -4.5e+61) {
		tmp = t_1;
	} else if (im <= -0.0027) {
		tmp = t_0;
	} else if (im <= 0.00094) {
		tmp = im * -Math.cos(re);
	} else if (im <= 4.5e+61) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (math.exp(-im) - math.exp(im))
	t_1 = math.pow(im, 5.0) * (math.cos(re) * -0.008333333333333333)
	tmp = 0
	if im <= -4.5e+61:
		tmp = t_1
	elif im <= -0.0027:
		tmp = t_0
	elif im <= 0.00094:
		tmp = im * -math.cos(re)
	elif im <= 4.5e+61:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)))
	t_1 = Float64((im ^ 5.0) * Float64(cos(re) * -0.008333333333333333))
	tmp = 0.0
	if (im <= -4.5e+61)
		tmp = t_1;
	elseif (im <= -0.0027)
		tmp = t_0;
	elseif (im <= 0.00094)
		tmp = Float64(im * Float64(-cos(re)));
	elseif (im <= 4.5e+61)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * (exp(-im) - exp(im));
	t_1 = (im ^ 5.0) * (cos(re) * -0.008333333333333333);
	tmp = 0.0;
	if (im <= -4.5e+61)
		tmp = t_1;
	elseif (im <= -0.0027)
		tmp = t_0;
	elseif (im <= 0.00094)
		tmp = im * -cos(re);
	elseif (im <= 4.5e+61)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 5.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.008333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -4.5e+61], t$95$1, If[LessEqual[im, -0.0027], t$95$0, If[LessEqual[im, 0.00094], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 4.5e+61], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\
t_1 := {im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\
\mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -0.0027:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 0.00094:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\

\mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.5e61 or 4.5e61 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg100.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 100.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
    5. Taylor expanded in im around inf 100.0%

      \[\leadsto \color{blue}{-0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)} \]
    6. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left({im}^{5} \cdot \cos re\right) \cdot -0.008333333333333333} \]
      2. associate-*l*100.0%

        \[\leadsto \color{blue}{{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)} \]

    if -4.5e61 < im < -0.0027000000000000001 or 9.39999999999999972e-4 < im < 4.5e61

    1. Initial program 99.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg99.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in re around 0 81.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]

    if -0.0027000000000000001 < im < 9.39999999999999972e-4

    1. Initial program 7.3%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg7.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 99.7%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. mul-1-neg99.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \mathbf{elif}\;im \leq -0.0027:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 0.00094:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \end{array} \]

Alternative 4: 97.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\ t_1 := {im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.0031:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 0.08:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (- (exp (- im)) (exp im))))
        (t_1 (* (pow im 5.0) (* (cos re) -0.008333333333333333))))
   (if (<= im -4.5e+61)
     t_1
     (if (<= im -0.0031)
       t_0
       (if (<= im 0.08)
         (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
         (if (<= im 4.5e+61) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = 0.5 * (exp(-im) - exp(im));
	double t_1 = pow(im, 5.0) * (cos(re) * -0.008333333333333333);
	double tmp;
	if (im <= -4.5e+61) {
		tmp = t_1;
	} else if (im <= -0.0031) {
		tmp = t_0;
	} else if (im <= 0.08) {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 4.5e+61) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * (exp(-im) - exp(im))
    t_1 = (im ** 5.0d0) * (cos(re) * (-0.008333333333333333d0))
    if (im <= (-4.5d+61)) then
        tmp = t_1
    else if (im <= (-0.0031d0)) then
        tmp = t_0
    else if (im <= 0.08d0) then
        tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    else if (im <= 4.5d+61) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * (Math.exp(-im) - Math.exp(im));
	double t_1 = Math.pow(im, 5.0) * (Math.cos(re) * -0.008333333333333333);
	double tmp;
	if (im <= -4.5e+61) {
		tmp = t_1;
	} else if (im <= -0.0031) {
		tmp = t_0;
	} else if (im <= 0.08) {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 4.5e+61) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (math.exp(-im) - math.exp(im))
	t_1 = math.pow(im, 5.0) * (math.cos(re) * -0.008333333333333333)
	tmp = 0
	if im <= -4.5e+61:
		tmp = t_1
	elif im <= -0.0031:
		tmp = t_0
	elif im <= 0.08:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	elif im <= 4.5e+61:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)))
	t_1 = Float64((im ^ 5.0) * Float64(cos(re) * -0.008333333333333333))
	tmp = 0.0
	if (im <= -4.5e+61)
		tmp = t_1;
	elseif (im <= -0.0031)
		tmp = t_0;
	elseif (im <= 0.08)
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	elseif (im <= 4.5e+61)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * (exp(-im) - exp(im));
	t_1 = (im ^ 5.0) * (cos(re) * -0.008333333333333333);
	tmp = 0.0;
	if (im <= -4.5e+61)
		tmp = t_1;
	elseif (im <= -0.0031)
		tmp = t_0;
	elseif (im <= 0.08)
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	elseif (im <= 4.5e+61)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 5.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.008333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -4.5e+61], t$95$1, If[LessEqual[im, -0.0031], t$95$0, If[LessEqual[im, 0.08], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.5e+61], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\
t_1 := {im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\
\mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -0.0031:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 0.08:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

\mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.5e61 or 4.5e61 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg100.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 100.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
    5. Taylor expanded in im around inf 100.0%

      \[\leadsto \color{blue}{-0.008333333333333333 \cdot \left({im}^{5} \cdot \cos re\right)} \]
    6. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left({im}^{5} \cdot \cos re\right) \cdot -0.008333333333333333} \]
      2. associate-*l*100.0%

        \[\leadsto \color{blue}{{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)} \]

    if -4.5e61 < im < -0.00309999999999999989 or 0.0800000000000000017 < im < 4.5e61

    1. Initial program 99.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg99.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in re around 0 81.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]

    if -0.00309999999999999989 < im < 0.0800000000000000017

    1. Initial program 7.3%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg7.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 99.8%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. +-commutative99.8%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg99.8%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg99.8%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) - im \cdot \cos re} \]
      4. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--99.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative99.8%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified99.8%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.5 \cdot 10^{+61}:\\ \;\;\;\;{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \mathbf{elif}\;im \leq -0.0031:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 0.08:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 4.5 \cdot 10^{+61}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{5} \cdot \left(\cos re \cdot -0.008333333333333333\right)\\ \end{array} \]

Alternative 5: 86.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.00058 \lor \neg \left(im \leq 0.0034\right):\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -0.00058) (not (<= im 0.0034)))
   (* 0.5 (- (exp (- im)) (exp im)))
   (* im (- (cos re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.00058) || !(im <= 0.0034)) {
		tmp = 0.5 * (exp(-im) - exp(im));
	} else {
		tmp = im * -cos(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-0.00058d0)) .or. (.not. (im <= 0.0034d0))) then
        tmp = 0.5d0 * (exp(-im) - exp(im))
    else
        tmp = im * -cos(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -0.00058) || !(im <= 0.0034)) {
		tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
	} else {
		tmp = im * -Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -0.00058) or not (im <= 0.0034):
		tmp = 0.5 * (math.exp(-im) - math.exp(im))
	else:
		tmp = im * -math.cos(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -0.00058) || !(im <= 0.0034))
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)));
	else
		tmp = Float64(im * Float64(-cos(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -0.00058) || ~((im <= 0.0034)))
		tmp = 0.5 * (exp(-im) - exp(im));
	else
		tmp = im * -cos(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -0.00058], N[Not[LessEqual[im, 0.0034]], $MachinePrecision]], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.00058 \lor \neg \left(im \leq 0.0034\right):\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -5.8e-4 or 0.00339999999999999981 < im

    1. Initial program 99.9%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg99.9%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in re around 0 78.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]

    if -5.8e-4 < im < 0.00339999999999999981

    1. Initial program 7.3%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg7.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 99.7%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. mul-1-neg99.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -0.00058 \lor \neg \left(im \leq 0.0034\right):\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \]

Alternative 6: 75.5% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.0008 \lor \neg \left(im \leq 5 \cdot 10^{+48}\right):\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -0.0008) (not (<= im 5e+48)))
   (- (* (pow im 3.0) -0.16666666666666666) im)
   (* im (- (cos re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.0008) || !(im <= 5e+48)) {
		tmp = (pow(im, 3.0) * -0.16666666666666666) - im;
	} else {
		tmp = im * -cos(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-0.0008d0)) .or. (.not. (im <= 5d+48))) then
        tmp = ((im ** 3.0d0) * (-0.16666666666666666d0)) - im
    else
        tmp = im * -cos(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -0.0008) || !(im <= 5e+48)) {
		tmp = (Math.pow(im, 3.0) * -0.16666666666666666) - im;
	} else {
		tmp = im * -Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -0.0008) or not (im <= 5e+48):
		tmp = (math.pow(im, 3.0) * -0.16666666666666666) - im
	else:
		tmp = im * -math.cos(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -0.0008) || !(im <= 5e+48))
		tmp = Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im);
	else
		tmp = Float64(im * Float64(-cos(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -0.0008) || ~((im <= 5e+48)))
		tmp = ((im ^ 3.0) * -0.16666666666666666) - im;
	else
		tmp = im * -cos(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -0.0008], N[Not[LessEqual[im, 5e+48]], $MachinePrecision]], N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.0008 \lor \neg \left(im \leq 5 \cdot 10^{+48}\right):\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -8.00000000000000038e-4 or 4.99999999999999973e48 < im

    1. Initial program 99.9%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg99.9%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 72.7%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. +-commutative72.7%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg72.7%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg72.7%

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) - im \cdot \cos re} \]
      4. associate-*r*72.7%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--72.7%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative72.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified72.7%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    7. Taylor expanded in re around 0 57.8%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
    8. Step-by-step derivation
      1. *-commutative57.8%

        \[\leadsto \color{blue}{{im}^{3} \cdot -0.16666666666666666} - im \]
    9. Simplified57.8%

      \[\leadsto \color{blue}{{im}^{3} \cdot -0.16666666666666666 - im} \]

    if -8.00000000000000038e-4 < im < 4.99999999999999973e48

    1. Initial program 12.3%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. sub0-neg12.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified12.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0 94.6%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*94.6%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. mul-1-neg94.6%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified94.6%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -0.0008 \lor \neg \left(im \leq 5 \cdot 10^{+48}\right):\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \]

Alternative 7: 52.0% accurate, 3.0× speedup?

\[\begin{array}{l} \\ im \cdot \left(-\cos re\right) \end{array} \]
(FPCore (re im) :precision binary64 (* im (- (cos re))))
double code(double re, double im) {
	return im * -cos(re);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = im * -cos(re)
end function
public static double code(double re, double im) {
	return im * -Math.cos(re);
}
def code(re, im):
	return im * -math.cos(re)
function code(re, im)
	return Float64(im * Float64(-cos(re)))
end
function tmp = code(re, im)
	tmp = im * -cos(re);
end
code[re_, im_] := N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}

\\
im \cdot \left(-\cos re\right)
\end{array}
Derivation
  1. Initial program 55.1%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. sub0-neg55.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
  3. Simplified55.1%

    \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
  4. Taylor expanded in im around 0 51.3%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  5. Step-by-step derivation
    1. associate-*r*51.3%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
    2. mul-1-neg51.3%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
  6. Simplified51.3%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  7. Final simplification51.3%

    \[\leadsto im \cdot \left(-\cos re\right) \]

Alternative 8: 29.6% accurate, 61.8× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(im \cdot -2\right) \end{array} \]
(FPCore (re im) :precision binary64 (* 0.5 (* im -2.0)))
double code(double re, double im) {
	return 0.5 * (im * -2.0);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.5d0 * (im * (-2.0d0))
end function
public static double code(double re, double im) {
	return 0.5 * (im * -2.0);
}
def code(re, im):
	return 0.5 * (im * -2.0)
function code(re, im)
	return Float64(0.5 * Float64(im * -2.0))
end
function tmp = code(re, im)
	tmp = 0.5 * (im * -2.0);
end
code[re_, im_] := N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(im \cdot -2\right)
\end{array}
Derivation
  1. Initial program 55.1%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. sub0-neg55.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
  3. Simplified55.1%

    \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
  4. Taylor expanded in re around 0 43.4%

    \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
  5. Taylor expanded in im around 0 31.7%

    \[\leadsto 0.5 \cdot \color{blue}{\left(-2 \cdot im\right)} \]
  6. Final simplification31.7%

    \[\leadsto 0.5 \cdot \left(im \cdot -2\right) \]

Alternative 9: 29.6% accurate, 154.5× speedup?

\[\begin{array}{l} \\ -im \end{array} \]
(FPCore (re im) :precision binary64 (- im))
double code(double re, double im) {
	return -im;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = -im
end function
public static double code(double re, double im) {
	return -im;
}
def code(re, im):
	return -im
function code(re, im)
	return Float64(-im)
end
function tmp = code(re, im)
	tmp = -im;
end
code[re_, im_] := (-im)
\begin{array}{l}

\\
-im
\end{array}
Derivation
  1. Initial program 55.1%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. sub0-neg55.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
  3. Simplified55.1%

    \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
  4. Taylor expanded in im around 0 51.3%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  5. Step-by-step derivation
    1. associate-*r*51.3%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
    2. mul-1-neg51.3%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
  6. Simplified51.3%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  7. Taylor expanded in re around 0 31.4%

    \[\leadsto \color{blue}{-1 \cdot im} \]
  8. Step-by-step derivation
    1. mul-1-neg31.4%

      \[\leadsto \color{blue}{-im} \]
  9. Simplified31.4%

    \[\leadsto \color{blue}{-im} \]
  10. Final simplification31.4%

    \[\leadsto -im \]

Developer target: 99.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (re im)
 :precision binary64
 (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)))))
double code(double re, double im) {
	double tmp;
	if (fabs(im) < 1.0) {
		tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	} else {
		tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (abs(im) < 1.0d0) then
        tmp = -(cos(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
    else
        tmp = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (Math.abs(im) < 1.0) {
		tmp = -(Math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	} else {
		tmp = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.fabs(im) < 1.0:
		tmp = -(math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)))
	else:
		tmp = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
	return tmp
function code(re, im)
	tmp = 0.0
	if (abs(im) < 1.0)
		tmp = Float64(-Float64(cos(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im))));
	else
		tmp = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (abs(im) < 1.0)
		tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	else
		tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Cos[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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}
\end{array}

Reproduce

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