math.sin on complex, imaginary part

Percentage Accurate: 53.4% → 99.6%
Time: 11.6s
Alternatives: 16
Speedup: 2.9×

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 16 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: 53.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.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := e^{im} \cdot -0.5\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(0.5 + t_1\right) \cdot \cos re\\ \mathbf{elif}\;t_0 \leq 0.001:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) - im \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \frac{0.5}{e^{im}} + t_1 \cdot \cos re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* (exp im) -0.5)))
   (if (<= t_0 (- INFINITY))
     (* (+ 0.5 t_1) (cos re))
     (if (<= t_0 0.001)
       (- (* -0.16666666666666666 (* (cos re) (pow im 3.0))) (* im (cos re)))
       (+ (* (cos re) (/ 0.5 (exp im))) (* t_1 (cos re)))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = exp(im) * -0.5;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (0.5 + t_1) * cos(re);
	} else if (t_0 <= 0.001) {
		tmp = (-0.16666666666666666 * (cos(re) * pow(im, 3.0))) - (im * cos(re));
	} else {
		tmp = (cos(re) * (0.5 / exp(im))) + (t_1 * cos(re));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = Math.exp(im) * -0.5;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = (0.5 + t_1) * Math.cos(re);
	} else if (t_0 <= 0.001) {
		tmp = (-0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0))) - (im * Math.cos(re));
	} else {
		tmp = (Math.cos(re) * (0.5 / Math.exp(im))) + (t_1 * Math.cos(re));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = math.exp(im) * -0.5
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (0.5 + t_1) * math.cos(re)
	elif t_0 <= 0.001:
		tmp = (-0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0))) - (im * math.cos(re))
	else:
		tmp = (math.cos(re) * (0.5 / math.exp(im))) + (t_1 * math.cos(re))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(exp(im) * -0.5)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(0.5 + t_1) * cos(re));
	elseif (t_0 <= 0.001)
		tmp = Float64(Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0))) - Float64(im * cos(re)));
	else
		tmp = Float64(Float64(cos(re) * Float64(0.5 / exp(im))) + Float64(t_1 * cos(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = exp(im) * -0.5;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (0.5 + t_1) * cos(re);
	elseif (t_0 <= 0.001)
		tmp = (-0.16666666666666666 * (cos(re) * (im ^ 3.0))) - (im * cos(re));
	else
		tmp = (cos(re) * (0.5 / exp(im))) + (t_1 * cos(re));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(0.5 + t$95$1), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.001], N[(N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(im * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \frac{0.5}{e^{im}} + t_1 \cdot \cos re\\


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

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1e-3

    1. Initial program 8.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*8.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative8.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def8.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-08.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval8.7%

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

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

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

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

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

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

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

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

    if 1e-3 < (-.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. *-commutative99.9%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*99.9%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative99.9%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def99.9%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-099.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval99.9%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 99.9%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/99.9%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative99.9%

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

      \[\leadsto \color{blue}{\left(\frac{0.5}{e^{im}} + e^{im} \cdot -0.5\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\cos re \cdot \left(\frac{0.5}{e^{im}} + e^{im} \cdot -0.5\right)} \]
      2. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{\frac{0.5}{e^{im}} \cdot \cos re + \left(e^{im} \cdot -0.5\right) \cdot \cos re} \]
    8. Applied egg-rr100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -\infty:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \mathbf{elif}\;e^{-im} - e^{im} \leq 0.001:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) - im \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \frac{0.5}{e^{im}} + \left(e^{im} \cdot -0.5\right) \cdot \cos re\\ \end{array} \]

Alternative 2: 99.7% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t_0 \leq 0.01:\\
\;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(t_1 + \frac{0.5}{e^{im}}\right)\\


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

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

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

    1. Initial program 9.3%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*9.3%

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

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out9.3%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in9.3%

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-09.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified9.3%

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

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

    if 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

Alternative 3: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := e^{im} \cdot -0.5\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(0.5 + t_1\right) \cdot \cos re\\ \mathbf{elif}\;t_0 \leq 0.001:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) - im \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(t_1 + \frac{0.5}{e^{im}}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* (exp im) -0.5)))
   (if (<= t_0 (- INFINITY))
     (* (+ 0.5 t_1) (cos re))
     (if (<= t_0 0.001)
       (- (* -0.16666666666666666 (* (cos re) (pow im 3.0))) (* im (cos re)))
       (* (cos re) (+ t_1 (/ 0.5 (exp im))))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = exp(im) * -0.5;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (0.5 + t_1) * cos(re);
	} else if (t_0 <= 0.001) {
		tmp = (-0.16666666666666666 * (cos(re) * pow(im, 3.0))) - (im * cos(re));
	} else {
		tmp = cos(re) * (t_1 + (0.5 / exp(im)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = Math.exp(im) * -0.5;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = (0.5 + t_1) * Math.cos(re);
	} else if (t_0 <= 0.001) {
		tmp = (-0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0))) - (im * Math.cos(re));
	} else {
		tmp = Math.cos(re) * (t_1 + (0.5 / Math.exp(im)));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = math.exp(im) * -0.5
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (0.5 + t_1) * math.cos(re)
	elif t_0 <= 0.001:
		tmp = (-0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0))) - (im * math.cos(re))
	else:
		tmp = math.cos(re) * (t_1 + (0.5 / math.exp(im)))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(exp(im) * -0.5)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(0.5 + t_1) * cos(re));
	elseif (t_0 <= 0.001)
		tmp = Float64(Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0))) - Float64(im * cos(re)));
	else
		tmp = Float64(cos(re) * Float64(t_1 + Float64(0.5 / exp(im))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = exp(im) * -0.5;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (0.5 + t_1) * cos(re);
	elseif (t_0 <= 0.001)
		tmp = (-0.16666666666666666 * (cos(re) * (im ^ 3.0))) - (im * cos(re));
	else
		tmp = cos(re) * (t_1 + (0.5 / exp(im)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(0.5 + t$95$1), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.001], N[(N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(im * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(t$95$1 + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(t_1 + \frac{0.5}{e^{im}}\right)\\


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

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1e-3

    1. Initial program 8.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*8.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative8.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def8.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-08.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval8.7%

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

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

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

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

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

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

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

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

    if 1e-3 < (-.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. *-commutative99.9%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*99.9%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative99.9%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def99.9%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-099.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval99.9%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 99.9%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/99.9%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -\infty:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \mathbf{elif}\;e^{-im} - e^{im} \leq 0.001:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) - im \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(e^{im} \cdot -0.5 + \frac{0.5}{e^{im}}\right)\\ \end{array} \]

Alternative 4: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := e^{im} \cdot -0.5\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(0.5 + t_1\right) \cdot \cos re\\ \mathbf{elif}\;t_0 \leq 0.001:\\ \;\;\;\;\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(t_1 + \frac{0.5}{e^{im}}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* (exp im) -0.5)))
   (if (<= t_0 (- INFINITY))
     (* (+ 0.5 t_1) (cos re))
     (if (<= t_0 0.001)
       (* (cos re) (- (* -0.16666666666666666 (pow im 3.0)) im))
       (* (cos re) (+ t_1 (/ 0.5 (exp im))))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = exp(im) * -0.5;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (0.5 + t_1) * cos(re);
	} else if (t_0 <= 0.001) {
		tmp = cos(re) * ((-0.16666666666666666 * pow(im, 3.0)) - im);
	} else {
		tmp = cos(re) * (t_1 + (0.5 / exp(im)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = Math.exp(im) * -0.5;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = (0.5 + t_1) * Math.cos(re);
	} else if (t_0 <= 0.001) {
		tmp = Math.cos(re) * ((-0.16666666666666666 * Math.pow(im, 3.0)) - im);
	} else {
		tmp = Math.cos(re) * (t_1 + (0.5 / Math.exp(im)));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = math.exp(im) * -0.5
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (0.5 + t_1) * math.cos(re)
	elif t_0 <= 0.001:
		tmp = math.cos(re) * ((-0.16666666666666666 * math.pow(im, 3.0)) - im)
	else:
		tmp = math.cos(re) * (t_1 + (0.5 / math.exp(im)))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(exp(im) * -0.5)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(0.5 + t_1) * cos(re));
	elseif (t_0 <= 0.001)
		tmp = Float64(cos(re) * Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) - im));
	else
		tmp = Float64(cos(re) * Float64(t_1 + Float64(0.5 / exp(im))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = exp(im) * -0.5;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (0.5 + t_1) * cos(re);
	elseif (t_0 <= 0.001)
		tmp = cos(re) * ((-0.16666666666666666 * (im ^ 3.0)) - im);
	else
		tmp = cos(re) * (t_1 + (0.5 / exp(im)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(0.5 + t$95$1), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.001], N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(t$95$1 + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(t_1 + \frac{0.5}{e^{im}}\right)\\


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

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1e-3

    1. Initial program 8.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*8.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative8.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def8.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-08.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval8.7%

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

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

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

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

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

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

    if 1e-3 < (-.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. *-commutative99.9%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*99.9%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative99.9%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval99.9%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def99.9%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/99.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-099.9%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval99.9%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 99.9%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/99.9%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -\infty:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \mathbf{elif}\;e^{-im} - e^{im} \leq 0.001:\\ \;\;\;\;\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(e^{im} \cdot -0.5 + \frac{0.5}{e^{im}}\right)\\ \end{array} \]

Alternative 5: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \mathbf{elif}\;t_0 \leq 0.001:\\ \;\;\;\;\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (<= t_0 (- INFINITY))
     (* (+ 0.5 (* (exp im) -0.5)) (cos re))
     (if (<= t_0 0.001)
       (* (cos re) (- (* -0.16666666666666666 (pow im 3.0)) im))
       (* (* 0.5 (cos re)) t_0)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (0.5 + (exp(im) * -0.5)) * cos(re);
	} else if (t_0 <= 0.001) {
		tmp = cos(re) * ((-0.16666666666666666 * pow(im, 3.0)) - im);
	} else {
		tmp = (0.5 * cos(re)) * t_0;
	}
	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) {
		tmp = (0.5 + (Math.exp(im) * -0.5)) * Math.cos(re);
	} else if (t_0 <= 0.001) {
		tmp = Math.cos(re) * ((-0.16666666666666666 * Math.pow(im, 3.0)) - im);
	} else {
		tmp = (0.5 * Math.cos(re)) * t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (0.5 + (math.exp(im) * -0.5)) * math.cos(re)
	elif t_0 <= 0.001:
		tmp = math.cos(re) * ((-0.16666666666666666 * math.pow(im, 3.0)) - im)
	else:
		tmp = (0.5 * math.cos(re)) * t_0
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(0.5 + Float64(exp(im) * -0.5)) * cos(re));
	elseif (t_0 <= 0.001)
		tmp = Float64(cos(re) * Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) - im));
	else
		tmp = Float64(Float64(0.5 * cos(re)) * t_0);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (0.5 + (exp(im) * -0.5)) * cos(re);
	elseif (t_0 <= 0.001)
		tmp = cos(re) * ((-0.16666666666666666 * (im ^ 3.0)) - im);
	else
		tmp = (0.5 * cos(re)) * t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(0.5 + N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.001], N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\


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

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 1e-3

    1. Initial program 8.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*8.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative8.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in8.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in8.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval8.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def8.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/8.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-08.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval8.7%

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

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

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

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

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

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

    if 1e-3 < (-.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)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.8%

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

Alternative 6: 96.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\ t_1 := \cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\ \mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.0038:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 165000:\\ \;\;\;\;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 (* (cos re) (* -0.008333333333333333 (pow im 5.0)))))
   (if (<= im -3.4e+53)
     t_1
     (if (<= im -0.0038)
       t_0
       (if (<= im 165000.0)
         (* 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 = cos(re) * (-0.008333333333333333 * pow(im, 5.0));
	double tmp;
	if (im <= -3.4e+53) {
		tmp = t_1;
	} else if (im <= -0.0038) {
		tmp = t_0;
	} else if (im <= 165000.0) {
		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 = cos(re) * ((-0.008333333333333333d0) * (im ** 5.0d0))
    if (im <= (-3.4d+53)) then
        tmp = t_1
    else if (im <= (-0.0038d0)) then
        tmp = t_0
    else if (im <= 165000.0d0) 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.cos(re) * (-0.008333333333333333 * Math.pow(im, 5.0));
	double tmp;
	if (im <= -3.4e+53) {
		tmp = t_1;
	} else if (im <= -0.0038) {
		tmp = t_0;
	} else if (im <= 165000.0) {
		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.cos(re) * (-0.008333333333333333 * math.pow(im, 5.0))
	tmp = 0
	if im <= -3.4e+53:
		tmp = t_1
	elif im <= -0.0038:
		tmp = t_0
	elif im <= 165000.0:
		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(cos(re) * Float64(-0.008333333333333333 * (im ^ 5.0)))
	tmp = 0.0
	if (im <= -3.4e+53)
		tmp = t_1;
	elseif (im <= -0.0038)
		tmp = t_0;
	elseif (im <= 165000.0)
		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 = cos(re) * (-0.008333333333333333 * (im ^ 5.0));
	tmp = 0.0;
	if (im <= -3.4e+53)
		tmp = t_1;
	elseif (im <= -0.0038)
		tmp = t_0;
	elseif (im <= 165000.0)
		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[Cos[re], $MachinePrecision] * N[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -3.4e+53], t$95$1, If[LessEqual[im, -0.0038], t$95$0, If[LessEqual[im, 165000.0], 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 := \cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\
\mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 165000:\\
\;\;\;\;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 < -3.39999999999999998e53 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -1 \cdot im\right)\right)} \cdot \cos re \]
    8. Taylor expanded in im around inf 99.1%

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

    if -3.39999999999999998e53 < im < -0.00379999999999999999 or 165000 < im < 4.5e61

    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 75.8%

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

    if -0.00379999999999999999 < im < 165000

    1. Initial program 10.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*10.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative10.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out10.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in10.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval10.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval10.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def10.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-010.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval10.7%

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(-1 \cdot im\right)} \]
    5. Step-by-step derivation
      1. neg-mul-197.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\ \;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\ \mathbf{elif}\;im \leq -0.0038:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 165000:\\ \;\;\;\;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}:\\ \;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\ \end{array} \]

Alternative 7: 97.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\ \;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\ \mathbf{elif}\;im \leq -0.0225:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 2.1:\\ \;\;\;\;\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -3.4e+53)
   (* (cos re) (* -0.008333333333333333 (pow im 5.0)))
   (if (<= im -0.0225)
     (* 0.5 (- (exp (- im)) (exp im)))
     (if (<= im 2.1)
       (* (cos re) (- (* -0.16666666666666666 (pow im 3.0)) im))
       (* (+ 0.5 (* (exp im) -0.5)) (cos re))))))
double code(double re, double im) {
	double tmp;
	if (im <= -3.4e+53) {
		tmp = cos(re) * (-0.008333333333333333 * pow(im, 5.0));
	} else if (im <= -0.0225) {
		tmp = 0.5 * (exp(-im) - exp(im));
	} else if (im <= 2.1) {
		tmp = cos(re) * ((-0.16666666666666666 * pow(im, 3.0)) - im);
	} else {
		tmp = (0.5 + (exp(im) * -0.5)) * 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 <= (-3.4d+53)) then
        tmp = cos(re) * ((-0.008333333333333333d0) * (im ** 5.0d0))
    else if (im <= (-0.0225d0)) then
        tmp = 0.5d0 * (exp(-im) - exp(im))
    else if (im <= 2.1d0) then
        tmp = cos(re) * (((-0.16666666666666666d0) * (im ** 3.0d0)) - im)
    else
        tmp = (0.5d0 + (exp(im) * (-0.5d0))) * cos(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -3.4e+53) {
		tmp = Math.cos(re) * (-0.008333333333333333 * Math.pow(im, 5.0));
	} else if (im <= -0.0225) {
		tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
	} else if (im <= 2.1) {
		tmp = Math.cos(re) * ((-0.16666666666666666 * Math.pow(im, 3.0)) - im);
	} else {
		tmp = (0.5 + (Math.exp(im) * -0.5)) * Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -3.4e+53:
		tmp = math.cos(re) * (-0.008333333333333333 * math.pow(im, 5.0))
	elif im <= -0.0225:
		tmp = 0.5 * (math.exp(-im) - math.exp(im))
	elif im <= 2.1:
		tmp = math.cos(re) * ((-0.16666666666666666 * math.pow(im, 3.0)) - im)
	else:
		tmp = (0.5 + (math.exp(im) * -0.5)) * math.cos(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -3.4e+53)
		tmp = Float64(cos(re) * Float64(-0.008333333333333333 * (im ^ 5.0)));
	elseif (im <= -0.0225)
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)));
	elseif (im <= 2.1)
		tmp = Float64(cos(re) * Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) - im));
	else
		tmp = Float64(Float64(0.5 + Float64(exp(im) * -0.5)) * cos(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -3.4e+53)
		tmp = cos(re) * (-0.008333333333333333 * (im ^ 5.0));
	elseif (im <= -0.0225)
		tmp = 0.5 * (exp(-im) - exp(im));
	elseif (im <= 2.1)
		tmp = cos(re) * ((-0.16666666666666666 * (im ^ 3.0)) - im);
	else
		tmp = (0.5 + (exp(im) * -0.5)) * cos(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -3.4e+53], N[(N[Cos[re], $MachinePrecision] * N[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -0.0225], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.1], N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\
\;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\

\mathbf{elif}\;im \leq -0.0225:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.39999999999999998e53

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -1 \cdot im\right)\right)} \cdot \cos re \]
    8. Taylor expanded in im around inf 98.5%

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

    if -3.39999999999999998e53 < im < -0.022499999999999999

    1. Initial program 99.8%

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

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

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

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

    if -0.022499999999999999 < im < 2.10000000000000009

    1. Initial program 9.3%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*9.3%

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

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out9.3%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in9.3%

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-09.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified9.3%

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

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

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

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

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

    if 2.10000000000000009 < 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

      \[\leadsto \left(\color{blue}{0.5} + e^{im} \cdot -0.5\right) \cdot \cos re \]
  3. Recombined 4 regimes into one program.
  4. Final simplification98.7%

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

Alternative 8: 97.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\ \;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\ \mathbf{elif}\;im \leq -0.0042:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.25:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + e^{im} \cdot -0.5\right) \cdot \cos re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -3.4e+53)
   (* (cos re) (* -0.008333333333333333 (pow im 5.0)))
   (if (<= im -0.0042)
     (* 0.5 (- (exp (- im)) (exp im)))
     (if (<= im 1.25)
       (* im (- (cos re)))
       (* (+ 0.5 (* (exp im) -0.5)) (cos re))))))
double code(double re, double im) {
	double tmp;
	if (im <= -3.4e+53) {
		tmp = cos(re) * (-0.008333333333333333 * pow(im, 5.0));
	} else if (im <= -0.0042) {
		tmp = 0.5 * (exp(-im) - exp(im));
	} else if (im <= 1.25) {
		tmp = im * -cos(re);
	} else {
		tmp = (0.5 + (exp(im) * -0.5)) * 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 <= (-3.4d+53)) then
        tmp = cos(re) * ((-0.008333333333333333d0) * (im ** 5.0d0))
    else if (im <= (-0.0042d0)) then
        tmp = 0.5d0 * (exp(-im) - exp(im))
    else if (im <= 1.25d0) then
        tmp = im * -cos(re)
    else
        tmp = (0.5d0 + (exp(im) * (-0.5d0))) * cos(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -3.4e+53) {
		tmp = Math.cos(re) * (-0.008333333333333333 * Math.pow(im, 5.0));
	} else if (im <= -0.0042) {
		tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
	} else if (im <= 1.25) {
		tmp = im * -Math.cos(re);
	} else {
		tmp = (0.5 + (Math.exp(im) * -0.5)) * Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -3.4e+53:
		tmp = math.cos(re) * (-0.008333333333333333 * math.pow(im, 5.0))
	elif im <= -0.0042:
		tmp = 0.5 * (math.exp(-im) - math.exp(im))
	elif im <= 1.25:
		tmp = im * -math.cos(re)
	else:
		tmp = (0.5 + (math.exp(im) * -0.5)) * math.cos(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -3.4e+53)
		tmp = Float64(cos(re) * Float64(-0.008333333333333333 * (im ^ 5.0)));
	elseif (im <= -0.0042)
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)));
	elseif (im <= 1.25)
		tmp = Float64(im * Float64(-cos(re)));
	else
		tmp = Float64(Float64(0.5 + Float64(exp(im) * -0.5)) * cos(re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -3.4e+53)
		tmp = cos(re) * (-0.008333333333333333 * (im ^ 5.0));
	elseif (im <= -0.0042)
		tmp = 0.5 * (exp(-im) - exp(im));
	elseif (im <= 1.25)
		tmp = im * -cos(re);
	else
		tmp = (0.5 + (exp(im) * -0.5)) * cos(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -3.4e+53], N[(N[Cos[re], $MachinePrecision] * N[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -0.0042], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.25], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], N[(N[(0.5 + N[(N[Exp[im], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.4 \cdot 10^{+53}:\\
\;\;\;\;\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5}\right)\\

\mathbf{elif}\;im \leq -0.0042:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.39999999999999998e53

    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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -1 \cdot im\right)\right)} \cdot \cos re \]
    8. Taylor expanded in im around inf 98.5%

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

    if -3.39999999999999998e53 < im < -0.00419999999999999974

    1. Initial program 99.8%

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

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

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

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

    if -0.00419999999999999974 < im < 1.25

    1. Initial program 9.3%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*9.3%

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

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out9.3%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in9.3%

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-09.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval9.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified9.3%

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

      \[\leadsto \cos re \cdot \color{blue}{\left(-1 \cdot im\right)} \]
    5. Step-by-step derivation
      1. neg-mul-198.9%

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

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

    if 1.25 < 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

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

Alternative 9: 86.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.007 \lor \neg \left(im \leq 165000\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.007) (not (<= im 165000.0)))
   (* 0.5 (- (exp (- im)) (exp im)))
   (* im (- (cos re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.007) || !(im <= 165000.0)) {
		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.007d0)) .or. (.not. (im <= 165000.0d0))) 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.007) || !(im <= 165000.0)) {
		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.007) or not (im <= 165000.0):
		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.007) || !(im <= 165000.0))
		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.007) || ~((im <= 165000.0)))
		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.007], N[Not[LessEqual[im, 165000.0]], $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.007 \lor \neg \left(im \leq 165000\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 < -0.00700000000000000015 or 165000 < 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 re around 0 68.1%

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

    if -0.00700000000000000015 < im < 165000

    1. Initial program 10.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*10.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative10.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in10.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out10.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in10.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval10.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval10.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def10.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/10.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-010.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval10.7%

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(-1 \cdot im\right)} \]
    5. Step-by-step derivation
      1. neg-mul-197.5%

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

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

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

Alternative 10: 39.9% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos re \leq -0.01:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{else}:\\ \;\;\;\;-im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (cos re) -0.01) (- (* im (* 0.5 (* re re))) im) (- im)))
double code(double re, double im) {
	double tmp;
	if (cos(re) <= -0.01) {
		tmp = (im * (0.5 * (re * re))) - im;
	} else {
		tmp = -im;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (cos(re) <= (-0.01d0)) then
        tmp = (im * (0.5d0 * (re * re))) - im
    else
        tmp = -im
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (Math.cos(re) <= -0.01) {
		tmp = (im * (0.5 * (re * re))) - im;
	} else {
		tmp = -im;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.cos(re) <= -0.01:
		tmp = (im * (0.5 * (re * re))) - im
	else:
		tmp = -im
	return tmp
function code(re, im)
	tmp = 0.0
	if (cos(re) <= -0.01)
		tmp = Float64(Float64(im * Float64(0.5 * Float64(re * re))) - im);
	else
		tmp = Float64(-im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (cos(re) <= -0.01)
		tmp = (im * (0.5 * (re * re))) - im;
	else
		tmp = -im;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -0.01], N[(N[(im * N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], (-im)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -0.01:\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\

\mathbf{else}:\\
\;\;\;\;-im\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 re) < -0.0100000000000000002

    1. Initial program 57.3%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*57.3%

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

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out57.3%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in57.3%

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval57.3%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff57.2%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/57.2%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-057.2%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval57.2%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified57.2%

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 57.2%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative57.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/57.2%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative57.2%

        \[\leadsto \left(\frac{0.5}{e^{im}} + \color{blue}{e^{im} \cdot -0.5}\right) \cdot \cos re \]
    6. Simplified57.2%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \cos re \]
    8. Step-by-step derivation
      1. neg-mul-150.2%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    9. Simplified50.2%

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

      \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left({re}^{2} \cdot im\right)} \]
    11. Step-by-step derivation
      1. +-commutative36.1%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) + -1 \cdot im} \]
      2. mul-1-neg36.1%

        \[\leadsto 0.5 \cdot \left({re}^{2} \cdot im\right) + \color{blue}{\left(-im\right)} \]
      3. unsub-neg36.1%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) - im} \]
      4. *-commutative36.1%

        \[\leadsto \color{blue}{\left({re}^{2} \cdot im\right) \cdot 0.5} - im \]
      5. *-commutative36.1%

        \[\leadsto \color{blue}{\left(im \cdot {re}^{2}\right)} \cdot 0.5 - im \]
      6. associate-*l*36.1%

        \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5\right)} - im \]
      7. unpow236.1%

        \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot 0.5\right) - im \]
    12. Simplified36.1%

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

    if -0.0100000000000000002 < (cos.f64 re)

    1. Initial program 53.0%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*53.0%

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in53.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in53.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in53.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out53.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in53.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval53.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval53.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def53.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval53.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff53.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/53.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-053.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval53.0%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 53.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative53.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/53.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative53.0%

        \[\leadsto \left(\frac{0.5}{e^{im}} + \color{blue}{e^{im} \cdot -0.5}\right) \cdot \cos re \]
    6. Simplified53.0%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \cos re \]
    8. Step-by-step derivation
      1. neg-mul-153.7%

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

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

      \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left({re}^{2} \cdot im\right)} \]
    11. Step-by-step derivation
      1. +-commutative38.4%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) + -1 \cdot im} \]
      2. mul-1-neg38.4%

        \[\leadsto 0.5 \cdot \left({re}^{2} \cdot im\right) + \color{blue}{\left(-im\right)} \]
      3. unsub-neg38.4%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) - im} \]
      4. *-commutative38.4%

        \[\leadsto \color{blue}{\left({re}^{2} \cdot im\right) \cdot 0.5} - im \]
      5. *-commutative38.4%

        \[\leadsto \color{blue}{\left(im \cdot {re}^{2}\right)} \cdot 0.5 - im \]
      6. associate-*l*38.4%

        \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5\right)} - im \]
      7. unpow238.4%

        \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot 0.5\right) - im \]
    12. Simplified38.4%

      \[\leadsto \color{blue}{im \cdot \left(\left(re \cdot re\right) \cdot 0.5\right) - im} \]
    13. Taylor expanded in re around 0 42.1%

      \[\leadsto \color{blue}{-1 \cdot im} \]
    14. Step-by-step derivation
      1. neg-mul-142.1%

        \[\leadsto \color{blue}{-im} \]
    15. Simplified42.1%

      \[\leadsto \color{blue}{-im} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification40.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos re \leq -0.01:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{else}:\\ \;\;\;\;-im\\ \end{array} \]

Alternative 11: 75.3% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -4.3 \cdot 10^{+64} \lor \neg \left(im \leq 8 \cdot 10^{+54}\right):\\
\;\;\;\;-0.16666666666666666 \cdot {im}^{3} - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -4.2999999999999998e64 or 8.0000000000000006e54 < 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

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

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

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

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

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

    if -4.2999999999999998e64 < im < 8.0000000000000006e54

    1. Initial program 24.1%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*24.1%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative24.1%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in24.1%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in24.1%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in24.1%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out24.1%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in24.1%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval24.1%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval24.1%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def24.1%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval24.1%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff24.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/24.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-024.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval24.0%

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(-1 \cdot im\right)} \]
    5. Step-by-step derivation
      1. neg-mul-183.4%

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

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

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

Alternative 12: 60.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -4.4 \cdot 10^{+39} \lor \neg \left(im \leq 600\right):\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -4.4e+39) (not (<= im 600.0)))
   (- (* im (* 0.5 (* re re))) im)
   (* im (- (cos re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -4.4e+39) || !(im <= 600.0)) {
		tmp = (im * (0.5 * (re * re))) - 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 <= (-4.4d+39)) .or. (.not. (im <= 600.0d0))) then
        tmp = (im * (0.5d0 * (re * re))) - im
    else
        tmp = im * -cos(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -4.4e+39) || !(im <= 600.0)) {
		tmp = (im * (0.5 * (re * re))) - im;
	} else {
		tmp = im * -Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -4.4e+39) or not (im <= 600.0):
		tmp = (im * (0.5 * (re * re))) - im
	else:
		tmp = im * -math.cos(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -4.4e+39) || !(im <= 600.0))
		tmp = Float64(Float64(im * Float64(0.5 * Float64(re * re))) - im);
	else
		tmp = Float64(im * Float64(-cos(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -4.4e+39) || ~((im <= 600.0)))
		tmp = (im * (0.5 * (re * re))) - im;
	else
		tmp = im * -cos(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -4.4e+39], N[Not[LessEqual[im, 600.0]], $MachinePrecision]], N[(N[(im * N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -4.4 \cdot 10^{+39} \lor \neg \left(im \leq 600\right):\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -4.4000000000000003e39 or 600 < 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

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

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

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/100.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \cos re \]
    8. Step-by-step derivation
      1. neg-mul-15.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left({re}^{2} \cdot im\right)} \]
    11. Step-by-step derivation
      1. +-commutative24.7%

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

        \[\leadsto 0.5 \cdot \left({re}^{2} \cdot im\right) + \color{blue}{\left(-im\right)} \]
      3. unsub-neg24.7%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) - im} \]
      4. *-commutative24.7%

        \[\leadsto \color{blue}{\left({re}^{2} \cdot im\right) \cdot 0.5} - im \]
      5. *-commutative24.7%

        \[\leadsto \color{blue}{\left(im \cdot {re}^{2}\right)} \cdot 0.5 - im \]
      6. associate-*l*24.7%

        \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5\right)} - im \]
      7. unpow224.7%

        \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot 0.5\right) - im \]
    12. Simplified24.7%

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

    if -4.4000000000000003e39 < im < 600

    1. Initial program 12.7%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*12.7%

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]
      4. +-commutative12.7%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in12.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in12.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in12.7%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out12.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in12.7%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval12.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval12.7%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def12.7%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval12.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff12.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/12.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-012.7%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval12.7%

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(-1 \cdot im\right)} \]
    5. Step-by-step derivation
      1. neg-mul-195.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.4 \cdot 10^{+39} \lor \neg \left(im \leq 600\right):\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \]

Alternative 13: 35.3% accurate, 33.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -680 \lor \neg \left(im \leq 520\right):\\
\;\;\;\;re \cdot \left(re \cdot 1.5\right)\\

\mathbf{else}:\\
\;\;\;\;-im\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -680 or 520 < 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. *-commutative100.0%

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-0100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Applied egg-rr1.8%

      \[\leadsto \cos re \cdot \color{blue}{-3} \]
    5. Taylor expanded in re around 0 15.8%

      \[\leadsto \color{blue}{1.5 \cdot {re}^{2} - 3} \]
    6. Step-by-step derivation
      1. *-commutative15.8%

        \[\leadsto \color{blue}{{re}^{2} \cdot 1.5} - 3 \]
      2. unpow215.8%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot 1.5 - 3 \]
      3. associate-*l*15.8%

        \[\leadsto \color{blue}{re \cdot \left(re \cdot 1.5\right)} - 3 \]
      4. fma-neg15.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(re, re \cdot 1.5, -3\right)} \]
      5. metadata-eval15.8%

        \[\leadsto \mathsf{fma}\left(re, re \cdot 1.5, \color{blue}{-3}\right) \]
    7. Simplified15.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, re \cdot 1.5, -3\right)} \]
    8. Taylor expanded in re around inf 15.9%

      \[\leadsto \color{blue}{1.5 \cdot {re}^{2}} \]
    9. Step-by-step derivation
      1. *-commutative15.9%

        \[\leadsto \color{blue}{{re}^{2} \cdot 1.5} \]
      2. unpow215.9%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot 1.5 \]
      3. associate-*r*15.9%

        \[\leadsto \color{blue}{re \cdot \left(re \cdot 1.5\right)} \]
    10. Simplified15.9%

      \[\leadsto \color{blue}{re \cdot \left(re \cdot 1.5\right)} \]

    if -680 < im < 520

    1. Initial program 10.0%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. associate-*l*10.0%

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + e^{0 - im}\right)}\right) \]
      5. distribute-lft-in10.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(-e^{im}\right) + 0.5 \cdot e^{0 - im}\right)} \]
      6. distribute-lft-in10.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(\left(-e^{im}\right) + e^{0 - im}\right)\right)} \]
      7. distribute-rgt-in10.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
      8. distribute-lft-neg-out10.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      9. distribute-rgt-neg-in10.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{e^{im} \cdot \left(-0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
      10. metadata-eval10.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{-0.5} + e^{0 - im} \cdot 0.5\right) \]
      11. metadata-eval10.0%

        \[\leadsto \cos re \cdot \left(e^{im} \cdot \color{blue}{\left(0.5 \cdot -1\right)} + e^{0 - im} \cdot 0.5\right) \]
      12. fma-def10.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
      13. metadata-eval10.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
      14. exp-diff10.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      15. associate-*l/10.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      16. exp-010.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      17. metadata-eval10.0%

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 10.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
    5. Step-by-step derivation
      1. *-commutative10.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
      2. associate-*r/10.0%

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

        \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
      4. *-commutative10.0%

        \[\leadsto \left(\frac{0.5}{e^{im}} + \color{blue}{e^{im} \cdot -0.5}\right) \cdot \cos re \]
    6. Simplified10.0%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \cos re \]
    8. Step-by-step derivation
      1. neg-mul-198.2%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    9. Simplified98.2%

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

      \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left({re}^{2} \cdot im\right)} \]
    11. Step-by-step derivation
      1. +-commutative51.0%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) + -1 \cdot im} \]
      2. mul-1-neg51.0%

        \[\leadsto 0.5 \cdot \left({re}^{2} \cdot im\right) + \color{blue}{\left(-im\right)} \]
      3. unsub-neg51.0%

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) - im} \]
      4. *-commutative51.0%

        \[\leadsto \color{blue}{\left({re}^{2} \cdot im\right) \cdot 0.5} - im \]
      5. *-commutative51.0%

        \[\leadsto \color{blue}{\left(im \cdot {re}^{2}\right)} \cdot 0.5 - im \]
      6. associate-*l*51.0%

        \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5\right)} - im \]
      7. unpow251.0%

        \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot 0.5\right) - im \]
    12. Simplified51.0%

      \[\leadsto \color{blue}{im \cdot \left(\left(re \cdot re\right) \cdot 0.5\right) - im} \]
    13. Taylor expanded in re around 0 55.0%

      \[\leadsto \color{blue}{-1 \cdot im} \]
    14. Step-by-step derivation
      1. neg-mul-155.0%

        \[\leadsto \color{blue}{-im} \]
    15. Simplified55.0%

      \[\leadsto \color{blue}{-im} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification35.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -680 \lor \neg \left(im \leq 520\right):\\ \;\;\;\;re \cdot \left(re \cdot 1.5\right)\\ \mathbf{else}:\\ \;\;\;\;-im\\ \end{array} \]

Alternative 14: 30.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 54.3%

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

      \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. associate-*l*54.3%

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

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

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
    8. distribute-lft-neg-out54.3%

      \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
    9. distribute-rgt-neg-in54.3%

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
    13. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
    14. exp-diff54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    15. associate-*l/54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    16. exp-054.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    17. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
  3. Simplified54.3%

    \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
  4. Taylor expanded in re around inf 54.3%

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
  5. Step-by-step derivation
    1. *-commutative54.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
    2. associate-*r/54.3%

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

      \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
    4. *-commutative54.3%

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

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

    \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \cos re \]
  8. Step-by-step derivation
    1. neg-mul-152.6%

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

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

    \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left({re}^{2} \cdot im\right)} \]
  11. Step-by-step derivation
    1. +-commutative37.7%

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

      \[\leadsto 0.5 \cdot \left({re}^{2} \cdot im\right) + \color{blue}{\left(-im\right)} \]
    3. unsub-neg37.7%

      \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) - im} \]
    4. *-commutative37.7%

      \[\leadsto \color{blue}{\left({re}^{2} \cdot im\right) \cdot 0.5} - im \]
    5. *-commutative37.7%

      \[\leadsto \color{blue}{\left(im \cdot {re}^{2}\right)} \cdot 0.5 - im \]
    6. associate-*l*37.7%

      \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5\right)} - im \]
    7. unpow237.7%

      \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot 0.5\right) - im \]
  12. Simplified37.7%

    \[\leadsto \color{blue}{im \cdot \left(\left(re \cdot re\right) \cdot 0.5\right) - im} \]
  13. Taylor expanded in re around 0 29.8%

    \[\leadsto \color{blue}{-1 \cdot im} \]
  14. Step-by-step derivation
    1. neg-mul-129.8%

      \[\leadsto \color{blue}{-im} \]
  15. Simplified29.8%

    \[\leadsto \color{blue}{-im} \]
  16. Final simplification29.8%

    \[\leadsto -im \]

Alternative 15: 2.9% accurate, 309.0× speedup?

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

\\
-3
\end{array}
Derivation
  1. Initial program 54.3%

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

      \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. associate-*l*54.3%

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

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

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
    8. distribute-lft-neg-out54.3%

      \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
    9. distribute-rgt-neg-in54.3%

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
    13. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
    14. exp-diff54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    15. associate-*l/54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    16. exp-054.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    17. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
  3. Simplified54.3%

    \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
  4. Applied egg-rr2.8%

    \[\leadsto \cos re \cdot \color{blue}{-3} \]
  5. Taylor expanded in re around 0 2.8%

    \[\leadsto \color{blue}{-3} \]
  6. Final simplification2.8%

    \[\leadsto -3 \]

Alternative 16: 3.5% accurate, 309.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 54.3%

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

      \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. associate-*l*54.3%

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

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

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(\left(-e^{im}\right) \cdot 0.5 + e^{0 - im} \cdot 0.5\right)} \]
    8. distribute-lft-neg-out54.3%

      \[\leadsto \cos re \cdot \left(\color{blue}{\left(-e^{im} \cdot 0.5\right)} + e^{0 - im} \cdot 0.5\right) \]
    9. distribute-rgt-neg-in54.3%

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(e^{im}, 0.5 \cdot -1, e^{0 - im} \cdot 0.5\right)} \]
    13. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, \color{blue}{-0.5}, e^{0 - im} \cdot 0.5\right) \]
    14. exp-diff54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    15. associate-*l/54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    16. exp-054.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    17. metadata-eval54.3%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
  3. Simplified54.3%

    \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(e^{im}, -0.5, \frac{0.5}{e^{im}}\right)} \]
  4. Taylor expanded in re around inf 54.3%

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right)} \]
  5. Step-by-step derivation
    1. *-commutative54.3%

      \[\leadsto \color{blue}{\left(0.5 \cdot \frac{1}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re} \]
    2. associate-*r/54.3%

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

      \[\leadsto \left(\frac{\color{blue}{0.5}}{e^{im}} + -0.5 \cdot e^{im}\right) \cdot \cos re \]
    4. *-commutative54.3%

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

    \[\leadsto \color{blue}{\left(\frac{0.5}{e^{im}} + e^{im} \cdot -0.5\right) \cdot \cos re} \]
  7. Step-by-step derivation
    1. *-commutative54.3%

      \[\leadsto \color{blue}{\cos re \cdot \left(\frac{0.5}{e^{im}} + e^{im} \cdot -0.5\right)} \]
    2. distribute-rgt-in54.3%

      \[\leadsto \color{blue}{\frac{0.5}{e^{im}} \cdot \cos re + \left(e^{im} \cdot -0.5\right) \cdot \cos re} \]
  8. Applied egg-rr54.3%

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

    \[\leadsto \color{blue}{0.5 \cdot \cos re + -0.5 \cdot \cos re} \]
  10. Step-by-step derivation
    1. distribute-rgt-out3.6%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 + -0.5\right)} \]
    2. metadata-eval3.6%

      \[\leadsto \cos re \cdot \color{blue}{0} \]
    3. mul0-rgt3.6%

      \[\leadsto \color{blue}{0} \]
  11. Simplified3.6%

    \[\leadsto \color{blue}{0} \]
  12. Final simplification3.6%

    \[\leadsto 0 \]

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 2023173 
(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))))