math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 7.3s
Alternatives: 13
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp(-im) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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 13 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp(-im) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 100.0% accurate, 0.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
	return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
im = abs(im)
function code(re, im)
	return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im))))
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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^{-im} + e^{im}\right) \]
    2. associate-*l*100.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \]

Alternative 2: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} im = |im|\\ \\ \left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right) \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (* (* (cos re) 0.5) (+ (exp im) (exp (- im)))))
im = abs(im);
double code(double re, double im) {
	return (cos(re) * 0.5) * (exp(im) + exp(-im));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (cos(re) * 0.5d0) * (exp(im) + exp(-im))
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return (Math.cos(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
im = abs(im)
def code(re, im):
	return (math.cos(re) * 0.5) * (math.exp(im) + math.exp(-im))
im = abs(im)
function code(re, im)
	return Float64(Float64(cos(re) * 0.5) * Float64(exp(im) + exp(Float64(-im))))
end
im = abs(im)
function tmp = code(re, im)
	tmp = (cos(re) * 0.5) * (exp(im) + exp(-im));
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
  2. Final simplification100.0%

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

Alternative 3: 96.4% accurate, 1.5× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 900:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 7.5 \cdot 10^{+76}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= im 900.0)
   (* (* (cos re) 0.5) (+ 2.0 (* im im)))
   (if (<= im 7.5e+76)
     (* 0.5 (log1p (expm1 (* im im))))
     (* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (im <= 900.0) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 7.5e+76) {
		tmp = 0.5 * log1p(expm1((im * im)));
	} else {
		tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	}
	return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (im <= 900.0) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 7.5e+76) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * im)));
	} else {
		tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if im <= 900.0:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 7.5e+76:
		tmp = 0.5 * math.log1p(math.expm1((im * im)))
	else:
		tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (im <= 900.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 7.5e+76)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * im))));
	else
		tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)));
	end
	return tmp
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[im, 900.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 7.5e+76], N[(0.5 * N[Log[1 + N[(Exp[N[(im * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 900:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 7.5 \cdot 10^{+76}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 900

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified85.0%

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

    if 900 < im < 7.4999999999999995e76

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified3.9%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 3.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. unpow23.9%

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*3.9%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*3.9%

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 3.3%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
    9. Step-by-step derivation
      1. pow23.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
      2. log1p-expm1-u84.2%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)} \]
    10. Applied egg-rr84.2%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)} \]

    if 7.4999999999999995e76 < im

    1. Initial program 100.0%

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right)\right) \]
    4. Simplified98.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)} \]
    5. Taylor expanded in im around inf 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 900:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 7.5 \cdot 10^{+76}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \end{array} \]

Alternative 4: 92.9% accurate, 1.5× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 900 \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (or (<= im 900.0) (not (<= im 2.6e+151)))
   (* (* (cos re) 0.5) (+ 2.0 (* im im)))
   (* 0.5 (log1p (expm1 (* im im))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if ((im <= 900.0) || !(im <= 2.6e+151)) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = 0.5 * log1p(expm1((im * im)));
	}
	return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if ((im <= 900.0) || !(im <= 2.6e+151)) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = 0.5 * Math.log1p(Math.expm1((im * im)));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if (im <= 900.0) or not (im <= 2.6e+151):
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	else:
		tmp = 0.5 * math.log1p(math.expm1((im * im)))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if ((im <= 900.0) || !(im <= 2.6e+151))
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(0.5 * log1p(expm1(Float64(im * im))));
	end
	return tmp
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[Or[LessEqual[im, 900.0], N[Not[LessEqual[im, 2.6e+151]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 900 \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 900 or 2.60000000000000013e151 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified86.7%

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

    if 900 < im < 2.60000000000000013e151

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified4.9%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 4.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. unpow24.9%

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*4.9%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*4.9%

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 3.6%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
    9. Step-by-step derivation
      1. pow23.6%

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
      2. log1p-expm1-u74.3%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)} \]
    10. Applied egg-rr74.3%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 900 \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 5: 87.2% accurate, 1.5× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 8.2 \cdot 10^{+42} \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt[3]{{im}^{6}}\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (or (<= im 8.2e+42) (not (<= im 2.6e+151)))
   (* (* (cos re) 0.5) (+ 2.0 (* im im)))
   (* 0.5 (cbrt (pow im 6.0)))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if ((im <= 8.2e+42) || !(im <= 2.6e+151)) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = 0.5 * cbrt(pow(im, 6.0));
	}
	return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if ((im <= 8.2e+42) || !(im <= 2.6e+151)) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = 0.5 * Math.cbrt(Math.pow(im, 6.0));
	}
	return tmp;
}
im = abs(im)
function code(re, im)
	tmp = 0.0
	if ((im <= 8.2e+42) || !(im <= 2.6e+151))
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(0.5 * cbrt((im ^ 6.0)));
	end
	return tmp
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[Or[LessEqual[im, 8.2e+42], N[Not[LessEqual[im, 2.6e+151]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[Power[im, 6.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8.2 \cdot 10^{+42} \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt[3]{{im}^{6}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 8.2000000000000001e42 or 2.60000000000000013e151 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified82.8%

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

    if 8.2000000000000001e42 < im < 2.60000000000000013e151

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified5.6%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 5.6%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*5.6%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*5.6%

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 3.9%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
    9. Step-by-step derivation
      1. add-cbrt-cube62.8%

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{\left({im}^{2} \cdot {im}^{2}\right) \cdot {im}^{2}}}\right) \]
      2. pow262.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\color{blue}{\left(im \cdot im\right)} \cdot {im}^{2}\right) \cdot {im}^{2}}\right) \]
      3. pow262.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right) \cdot {im}^{2}}\right) \]
      4. pow262.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right) \cdot \color{blue}{\left(im \cdot im\right)}}\right) \]
      5. pow362.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{\left(im \cdot im\right)}^{3}}}\right) \]
      6. pow262.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{\color{blue}{\left({im}^{2}\right)}}^{3}}\right) \]
      7. pow-pow62.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 3\right)}}}\right) \]
      8. metadata-eval62.8%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{im}^{\color{blue}{6}}}\right) \]
    10. Applied egg-rr62.8%

      \[\leadsto 0.5 \cdot \color{blue}{\sqrt[3]{{im}^{6}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 8.2 \cdot 10^{+42} \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt[3]{{im}^{6}}\\ \end{array} \]

Alternative 6: 98.8% accurate, 1.5× speedup?

\[\begin{array}{l} im = |im|\\ \\ \cos re \cdot \left(0.5 + 0.5 \cdot e^{im}\right) \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im) :precision binary64 (* (cos re) (+ 0.5 (* 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
	return cos(re) * (0.5 + (0.5 * exp(im)));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = cos(re) * (0.5d0 + (0.5d0 * exp(im)))
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return Math.cos(re) * (0.5 + (0.5 * Math.exp(im)));
}
im = abs(im)
def code(re, im):
	return math.cos(re) * (0.5 + (0.5 * math.exp(im)))
im = abs(im)
function code(re, im)
	return Float64(cos(re) * Float64(0.5 + Float64(0.5 * exp(im))))
end
im = abs(im)
function tmp = code(re, im)
	tmp = cos(re) * (0.5 + (0.5 * exp(im)));
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\cos re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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^{-im} + e^{im}\right) \]
    2. associate-*l*100.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{0.5}\right) \]
  5. Step-by-step derivation
    1. fma-udef78.6%

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

    \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5\right)} \]
  7. Final simplification78.6%

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

Alternative 7: 79.7% accurate, 2.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 350:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= im 350.0)
   (cos re)
   (if (<= im 1.35e+154)
     (* (* im im) (+ 0.5 (* (* re re) -0.25)))
     (* (cos re) (* 0.5 (* im im))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (im <= 350.0) {
		tmp = cos(re);
	} else if (im <= 1.35e+154) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = cos(re) * (0.5 * (im * im));
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 350.0d0) then
        tmp = cos(re)
    else if (im <= 1.35d+154) then
        tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = cos(re) * (0.5d0 * (im * im))
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (im <= 350.0) {
		tmp = Math.cos(re);
	} else if (im <= 1.35e+154) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = Math.cos(re) * (0.5 * (im * im));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if im <= 350.0:
		tmp = math.cos(re)
	elif im <= 1.35e+154:
		tmp = (im * im) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = math.cos(re) * (0.5 * (im * im))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (im <= 350.0)
		tmp = cos(re);
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(cos(re) * Float64(0.5 * Float64(im * im)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 350.0)
		tmp = cos(re);
	elseif (im <= 1.35e+154)
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	else
		tmp = cos(re) * (0.5 * (im * im));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[im, 350.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 350:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 350

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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^{-im} + e^{im}\right) \]
      2. associate-*l*100.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re} \]

    if 350 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified5.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 5.1%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*5.1%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*5.1%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    7. Simplified5.1%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 24.8%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2} + -0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*24.8%

        \[\leadsto 0.5 \cdot {im}^{2} + \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot {im}^{2}} \]
      2. distribute-rgt-out24.8%

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)} \]
      3. unpow224.8%

        \[\leadsto \color{blue}{\left(im \cdot im\right)} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right) \]
      4. +-commutative24.8%

        \[\leadsto \left(im \cdot im\right) \cdot \color{blue}{\left(-0.25 \cdot {re}^{2} + 0.5\right)} \]
      5. *-commutative24.8%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{{re}^{2} \cdot -0.25} + 0.5\right) \]
      6. unpow224.8%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    10. Simplified24.8%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. unpow2100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 350:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 8: 80.0% accurate, 2.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 390:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= im 390.0)
   (* (* (cos re) 0.5) (+ 2.0 (* im im)))
   (if (<= im 1.35e+154)
     (* (* im im) (+ 0.5 (* (* re re) -0.25)))
     (* (cos re) (* 0.5 (* im im))))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (im <= 390.0) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = cos(re) * (0.5 * (im * im));
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 390.0d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.35d+154) then
        tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = cos(re) * (0.5d0 * (im * im))
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (im <= 390.0) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = Math.cos(re) * (0.5 * (im * im));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if im <= 390.0:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.35e+154:
		tmp = (im * im) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = math.cos(re) * (0.5 * (im * im))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (im <= 390.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(cos(re) * Float64(0.5 * Float64(im * im)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 390.0)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.35e+154)
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	else
		tmp = cos(re) * (0.5 * (im * im));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[im, 390.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 390:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 390

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified85.5%

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

    if 390 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified5.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 5.1%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*5.1%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*5.1%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    7. Simplified5.1%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 24.8%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2} + -0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*24.8%

        \[\leadsto 0.5 \cdot {im}^{2} + \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot {im}^{2}} \]
      2. distribute-rgt-out24.8%

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)} \]
      3. unpow224.8%

        \[\leadsto \color{blue}{\left(im \cdot im\right)} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right) \]
      4. +-commutative24.8%

        \[\leadsto \left(im \cdot im\right) \cdot \color{blue}{\left(-0.25 \cdot {re}^{2} + 0.5\right)} \]
      5. *-commutative24.8%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{{re}^{2} \cdot -0.25} + 0.5\right) \]
      6. unpow224.8%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    10. Simplified24.8%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. unpow2100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 390:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 9: 73.6% accurate, 3.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 520

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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^{-im} + e^{im}\right) \]
      2. associate-*l*100.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re} \]

    if 520 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified47.6%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 47.6%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*47.6%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*47.6%

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 13.7%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2} + -0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*13.7%

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

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)} \]
      3. unpow248.0%

        \[\leadsto \color{blue}{\left(im \cdot im\right)} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right) \]
      4. +-commutative48.0%

        \[\leadsto \left(im \cdot im\right) \cdot \color{blue}{\left(-0.25 \cdot {re}^{2} + 0.5\right)} \]
      5. *-commutative48.0%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{{re}^{2} \cdot -0.25} + 0.5\right) \]
      6. unpow248.0%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    10. Simplified48.0%

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

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

Alternative 10: 51.5% accurate, 23.6× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;im \leq 125:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= im 125.0)
   (* 0.5 (+ 2.0 (* im im)))
   (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (im <= 125.0) {
		tmp = 0.5 * (2.0 + (im * im));
	} else {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 125.0d0) then
        tmp = 0.5d0 * (2.0d0 + (im * im))
    else
        tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (im <= 125.0) {
		tmp = 0.5 * (2.0 + (im * im));
	} else {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if im <= 125.0:
		tmp = 0.5 * (2.0 + (im * im))
	else:
		tmp = (im * im) * (0.5 + ((re * re) * -0.25))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (im <= 125.0)
		tmp = Float64(0.5 * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 125.0)
		tmp = 0.5 * (2.0 + (im * im));
	else
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[im, 125.0], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 125:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 125

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified85.5%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in re around 0 44.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. add-cbrt-cube52.5%

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{\left({im}^{2} \cdot {im}^{2}\right) \cdot {im}^{2}}}\right) \]
      2. pow252.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\color{blue}{\left(im \cdot im\right)} \cdot {im}^{2}\right) \cdot {im}^{2}}\right) \]
      3. pow252.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right) \cdot {im}^{2}}\right) \]
      4. pow252.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right) \cdot \color{blue}{\left(im \cdot im\right)}}\right) \]
      5. pow352.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{\left(im \cdot im\right)}^{3}}}\right) \]
      6. pow252.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{\color{blue}{\left({im}^{2}\right)}}^{3}}\right) \]
      7. pow-pow52.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 3\right)}}}\right) \]
      8. metadata-eval52.5%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{im}^{\color{blue}{6}}}\right) \]
    7. Applied egg-rr52.5%

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{{im}^{6}}}\right) \]
    8. Taylor expanded in im around 0 44.6%

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

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    10. Simplified44.6%

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]

    if 125 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified47.6%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 47.6%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*47.6%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*47.6%

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 13.7%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2} + -0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*13.7%

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

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)} \]
      3. unpow248.0%

        \[\leadsto \color{blue}{\left(im \cdot im\right)} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right) \]
      4. +-commutative48.0%

        \[\leadsto \left(im \cdot im\right) \cdot \color{blue}{\left(-0.25 \cdot {re}^{2} + 0.5\right)} \]
      5. *-commutative48.0%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{{re}^{2} \cdot -0.25} + 0.5\right) \]
      6. unpow248.0%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    10. Simplified48.0%

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

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

Alternative 11: 48.5% accurate, 27.8× speedup?

\[\begin{array}{l} im = |im|\\ \\ \begin{array}{l} \mathbf{if}\;re \leq 8.2 \cdot 10^{+16}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \left(\left(re \cdot im\right) \cdot \left(re \cdot im\right)\right)\\ \end{array} \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im)
 :precision binary64
 (if (<= re 8.2e+16)
   (* 0.5 (+ 2.0 (* im im)))
   (* -0.25 (* (* re im) (* re im)))))
im = abs(im);
double code(double re, double im) {
	double tmp;
	if (re <= 8.2e+16) {
		tmp = 0.5 * (2.0 + (im * im));
	} else {
		tmp = -0.25 * ((re * im) * (re * im));
	}
	return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= 8.2d+16) then
        tmp = 0.5d0 * (2.0d0 + (im * im))
    else
        tmp = (-0.25d0) * ((re * im) * (re * im))
    end if
    code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
	double tmp;
	if (re <= 8.2e+16) {
		tmp = 0.5 * (2.0 + (im * im));
	} else {
		tmp = -0.25 * ((re * im) * (re * im));
	}
	return tmp;
}
im = abs(im)
def code(re, im):
	tmp = 0
	if re <= 8.2e+16:
		tmp = 0.5 * (2.0 + (im * im))
	else:
		tmp = -0.25 * ((re * im) * (re * im))
	return tmp
im = abs(im)
function code(re, im)
	tmp = 0.0
	if (re <= 8.2e+16)
		tmp = Float64(0.5 * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(-0.25 * Float64(Float64(re * im) * Float64(re * im)));
	end
	return tmp
end
im = abs(im)
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= 8.2e+16)
		tmp = 0.5 * (2.0 + (im * im));
	else
		tmp = -0.25 * ((re * im) * (re * im));
	end
	tmp_2 = tmp;
end
NOTE: im should be positive before calling this function
code[re_, im_] := If[LessEqual[re, 8.2e+16], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.25 * N[(N[(re * im), $MachinePrecision] * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 8.2 \cdot 10^{+16}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 8.2e16

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified71.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in re around 0 46.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. add-cbrt-cube60.7%

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{\left({im}^{2} \cdot {im}^{2}\right) \cdot {im}^{2}}}\right) \]
      2. pow260.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\color{blue}{\left(im \cdot im\right)} \cdot {im}^{2}\right) \cdot {im}^{2}}\right) \]
      3. pow260.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right) \cdot {im}^{2}}\right) \]
      4. pow260.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right) \cdot \color{blue}{\left(im \cdot im\right)}}\right) \]
      5. pow360.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{\left(im \cdot im\right)}^{3}}}\right) \]
      6. pow260.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{\color{blue}{\left({im}^{2}\right)}}^{3}}\right) \]
      7. pow-pow60.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 3\right)}}}\right) \]
      8. metadata-eval60.7%

        \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{im}^{\color{blue}{6}}}\right) \]
    7. Applied egg-rr60.7%

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{{im}^{6}}}\right) \]
    8. Taylor expanded in im around 0 46.5%

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

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    10. Simplified46.5%

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]

    if 8.2e16 < re

    1. Initial program 100.0%

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified88.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 28.1%

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

        \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      2. associate-*r*28.1%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
      4. associate-*l*28.1%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    7. Simplified28.1%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 7.6%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2} + -0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*7.6%

        \[\leadsto 0.5 \cdot {im}^{2} + \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot {im}^{2}} \]
      2. distribute-rgt-out18.5%

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)} \]
      3. unpow218.5%

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

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

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{{re}^{2} \cdot -0.25} + 0.5\right) \]
      6. unpow218.5%

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    10. Simplified18.5%

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(\left(re \cdot re\right) \cdot -0.25 + 0.5\right)} \]
    11. Taylor expanded in re around inf 18.5%

      \[\leadsto \color{blue}{-0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    12. Step-by-step derivation
      1. unpow218.5%

        \[\leadsto -0.25 \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot {im}^{2}\right) \]
      2. unpow218.5%

        \[\leadsto -0.25 \cdot \left(\left(re \cdot re\right) \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      3. *-commutative18.5%

        \[\leadsto -0.25 \cdot \color{blue}{\left(\left(im \cdot im\right) \cdot \left(re \cdot re\right)\right)} \]
      4. unswap-sqr19.1%

        \[\leadsto -0.25 \cdot \color{blue}{\left(\left(im \cdot re\right) \cdot \left(im \cdot re\right)\right)} \]
    13. Simplified19.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 8.2 \cdot 10^{+16}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \left(\left(re \cdot im\right) \cdot \left(re \cdot im\right)\right)\\ \end{array} \]

Alternative 12: 47.1% accurate, 44.0× speedup?

\[\begin{array}{l} im = |im|\\ \\ 0.5 \cdot \left(2 + im \cdot im\right) \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im) :precision binary64 (* 0.5 (+ 2.0 (* im im))))
im = abs(im);
double code(double re, double im) {
	return 0.5 * (2.0 + (im * im));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.5d0 * (2.0d0 + (im * im))
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return 0.5 * (2.0 + (im * im));
}
im = abs(im)
def code(re, im):
	return 0.5 * (2.0 + (im * im))
im = abs(im)
function code(re, im)
	return Float64(0.5 * Float64(2.0 + Float64(im * im)))
end
im = abs(im)
function tmp = code(re, im)
	tmp = 0.5 * (2.0 + (im * im));
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \left(2 + im \cdot im\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified75.5%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in re around 0 40.0%

    \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. add-cbrt-cube51.4%

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{\left({im}^{2} \cdot {im}^{2}\right) \cdot {im}^{2}}}\right) \]
    2. pow251.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\color{blue}{\left(im \cdot im\right)} \cdot {im}^{2}\right) \cdot {im}^{2}}\right) \]
    3. pow251.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right) \cdot {im}^{2}}\right) \]
    4. pow251.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\left(\left(im \cdot im\right) \cdot \left(im \cdot im\right)\right) \cdot \color{blue}{\left(im \cdot im\right)}}\right) \]
    5. pow351.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{\left(im \cdot im\right)}^{3}}}\right) \]
    6. pow251.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{\color{blue}{\left({im}^{2}\right)}}^{3}}\right) \]
    7. pow-pow51.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 3\right)}}}\right) \]
    8. metadata-eval51.4%

      \[\leadsto 0.5 \cdot \left(2 + \sqrt[3]{{im}^{\color{blue}{6}}}\right) \]
  7. Applied egg-rr51.4%

    \[\leadsto 0.5 \cdot \left(2 + \color{blue}{\sqrt[3]{{im}^{6}}}\right) \]
  8. Taylor expanded in im around 0 40.0%

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

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  10. Simplified40.0%

    \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  11. Final simplification40.0%

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

Alternative 13: 21.4% accurate, 61.6× speedup?

\[\begin{array}{l} im = |im|\\ \\ 0.5 \cdot \left(im \cdot im\right) \end{array} \]
NOTE: im should be positive before calling this function
(FPCore (re im) :precision binary64 (* 0.5 (* im im)))
im = abs(im);
double code(double re, double im) {
	return 0.5 * (im * im);
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.5d0 * (im * im)
end function
im = Math.abs(im);
public static double code(double re, double im) {
	return 0.5 * (im * im);
}
im = abs(im)
def code(re, im):
	return 0.5 * (im * im)
im = abs(im)
function code(re, im)
	return Float64(0.5 * Float64(im * im))
end
im = abs(im)
function tmp = code(re, im)
	tmp = 0.5 * (im * im);
end
NOTE: im should be positive before calling this function
code[re_, im_] := N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \left(im \cdot im\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified75.5%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 25.4%

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

      \[\leadsto 0.5 \cdot \left(\cos re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
    2. associate-*r*25.4%

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im\right)} \]
    3. *-commutative25.4%

      \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(im \cdot im\right) \]
    4. associate-*l*25.4%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
  7. Simplified25.4%

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
  8. Taylor expanded in re around 0 16.2%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow216.2%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified16.2%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Final simplification16.2%

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

Reproduce

?
herbie shell --seed 2023222 
(FPCore (re im)
  :name "math.cos on complex, real part"
  :precision binary64
  (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))