math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 9.5s
Alternatives: 20
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 20 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} \\ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
	return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im)
	return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im))))
end
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}

\\
\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: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -365:\\ \;\;\;\;\cos re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot \left(0.5 \cdot im\right)\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -365.0)
   (* (cos re) (log1p (expm1 (* im (* 0.5 im)))))
   (if (<= im 1.3)
     (* (* (cos re) 0.5) (+ 2.0 (* im im)))
     (* (cos re) (+ (* 0.5 (exp im)) 0.001953125)))))
double code(double re, double im) {
	double tmp;
	if (im <= -365.0) {
		tmp = cos(re) * log1p(expm1((im * (0.5 * im))));
	} else if (im <= 1.3) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= -365.0) {
		tmp = Math.cos(re) * Math.log1p(Math.expm1((im * (0.5 * im))));
	} else if (im <= 1.3) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = Math.cos(re) * ((0.5 * Math.exp(im)) + 0.001953125);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -365.0:
		tmp = math.cos(re) * math.log1p(math.expm1((im * (0.5 * im))))
	elif im <= 1.3:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	else:
		tmp = math.cos(re) * ((0.5 * math.exp(im)) + 0.001953125)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -365.0)
		tmp = Float64(cos(re) * log1p(expm1(Float64(im * Float64(0.5 * im)))));
	elseif (im <= 1.3)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + 0.001953125));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, -365.0], N[(N[Cos[re], $MachinePrecision] * N[Log[1 + N[(Exp[N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.3], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 1.3:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

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


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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Step-by-step derivation
      1. log1p-expm1-u100.0%

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

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

        \[\leadsto \cos re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{im \cdot \left(im \cdot 0.5\right)}\right)\right) \]
    9. Applied egg-rr100.0%

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

    if -365 < im < 1.30000000000000004

    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)} \]

    if 1.30000000000000004 < im

    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. Applied egg-rr100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -365:\\ \;\;\;\;\cos re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot \left(0.5 \cdot im\right)\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \]

Alternative 3: 97.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -430:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(0.041666666666666664 \cdot {im}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.5e+85)
   (* 0.041666666666666664 (* (cos re) (pow im 4.0)))
   (if (<= im -430.0)
     (log1p (expm1 (* 0.041666666666666664 (pow im 4.0))))
     (if (<= im 1.3)
       (* (* (cos re) 0.5) (+ 2.0 (* im im)))
       (* (cos re) (+ (* 0.5 (exp im)) 0.001953125))))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	} else if (im <= -430.0) {
		tmp = log1p(expm1((0.041666666666666664 * pow(im, 4.0))));
	} else if (im <= 1.3) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	} else if (im <= -430.0) {
		tmp = Math.log1p(Math.expm1((0.041666666666666664 * Math.pow(im, 4.0))));
	} else if (im <= 1.3) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = Math.cos(re) * ((0.5 * Math.exp(im)) + 0.001953125);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -1.5e+85:
		tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0))
	elif im <= -430.0:
		tmp = math.log1p(math.expm1((0.041666666666666664 * math.pow(im, 4.0))))
	elif im <= 1.3:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	else:
		tmp = math.cos(re) * ((0.5 * math.exp(im)) + 0.001953125)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -1.5e+85)
		tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)));
	elseif (im <= -430.0)
		tmp = log1p(expm1(Float64(0.041666666666666664 * (im ^ 4.0))));
	elseif (im <= 1.3)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + 0.001953125));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, -1.5e+85], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -430.0], N[Log[1 + N[(Exp[N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 1.3], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\

\mathbf{elif}\;im \leq -430:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(0.041666666666666664 \cdot {im}^{4}\right)\right)\\

\mathbf{elif}\;im \leq 1.3:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

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


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

    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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 100.0%

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

    if -1.5e85 < im < -430

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

      \[\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. unpow221.9%

        \[\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. *-commutative21.9%

        \[\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. Simplified21.9%

      \[\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 21.9%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 21.3%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative21.3%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified21.3%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    9. Step-by-step derivation
      1. log1p-expm1-u82.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left({im}^{4} \cdot 0.041666666666666664\right)\right)} \]
    10. Applied egg-rr82.4%

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

    if -430 < im < 1.30000000000000004

    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)} \]

    if 1.30000000000000004 < im

    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. Applied egg-rr100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -430:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(0.041666666666666664 \cdot {im}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \]

Alternative 4: 100.0% accurate, 1.0× speedup?

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

\\
\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 5: 96.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\ \mathbf{elif}\;im \leq 1.92:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.5e+85)
   (* 0.041666666666666664 (* (cos re) (pow im 4.0)))
   (if (<= im -4.9e+25)
     (*
      0.5
      (+ 2.0 (+ (* im im) (cbrt (* (pow im 12.0) 0.0005787037037037037)))))
     (if (<= im 1.92)
       (*
        (* (cos re) 0.5)
        (+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333))))
       (* (cos re) (+ (* 0.5 (exp im)) 0.001953125))))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	} else if (im <= -4.9e+25) {
		tmp = 0.5 * (2.0 + ((im * im) + cbrt((pow(im, 12.0) * 0.0005787037037037037))));
	} else if (im <= 1.92) {
		tmp = (cos(re) * 0.5) * (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333)));
	} else {
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	} else if (im <= -4.9e+25) {
		tmp = 0.5 * (2.0 + ((im * im) + Math.cbrt((Math.pow(im, 12.0) * 0.0005787037037037037))));
	} else if (im <= 1.92) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333)));
	} else {
		tmp = Math.cos(re) * ((0.5 * Math.exp(im)) + 0.001953125);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= -1.5e+85)
		tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)));
	elseif (im <= -4.9e+25)
		tmp = Float64(0.5 * Float64(2.0 + Float64(Float64(im * im) + cbrt(Float64((im ^ 12.0) * 0.0005787037037037037)))));
	elseif (im <= 1.92)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333))));
	else
		tmp = Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + 0.001953125));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, -1.5e+85], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -4.9e+25], N[(0.5 * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[Power[N[(N[Power[im, 12.0], $MachinePrecision] * 0.0005787037037037037), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.92], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\

\mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\
\;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\

\mathbf{elif}\;im \leq 1.92:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\

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


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

    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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 100.0%

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

    if -1.5e85 < im < -4.9000000000000001e25

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

      \[\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. unpow231.9%

        \[\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. *-commutative31.9%

        \[\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. Simplified31.9%

      \[\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 re around 0 31.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity31.5%

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{\left(im \cdot im\right)} \cdot 1\right)\right) \]
    7. Applied egg-rr31.5%

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{\sqrt[3]{\left(\left(0.08333333333333333 \cdot {im}^{4}\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      2. pow1/390.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{{\left(\left(\left(0.08333333333333333 \cdot {im}^{4}\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right)}^{0.3333333333333333}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      3. pow390.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\color{blue}{\left({\left(0.08333333333333333 \cdot {im}^{4}\right)}^{3}\right)}}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      4. *-commutative90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\left({\color{blue}{\left({im}^{4} \cdot 0.08333333333333333\right)}}^{3}\right)}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      5. unpow-prod-down90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\color{blue}{\left({\left({im}^{4}\right)}^{3} \cdot {0.08333333333333333}^{3}\right)}}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      6. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\left({\left({im}^{4}\right)}^{3} \cdot \color{blue}{0.0005787037037037037}\right)}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    9. Applied egg-rr90.9%

      \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{{\left({\left({im}^{4}\right)}^{3} \cdot 0.0005787037037037037\right)}^{0.3333333333333333}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    10. Step-by-step derivation
      1. unpow1/390.9%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right)}^{3} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      6. cube-prod90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\color{blue}{\left({\left(im \cdot im\right)}^{3} \cdot {\left(im \cdot im\right)}^{3}\right)} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      7. cube-prod90.9%

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{\color{blue}{6}} \cdot {\left(im \cdot im\right)}^{3}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      10. cube-prod90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot \color{blue}{\left({im}^{3} \cdot {im}^{3}\right)}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      11. pow-sqr90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot \color{blue}{{im}^{\left(2 \cdot 3\right)}}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      12. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot {im}^{\color{blue}{6}}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      13. pow-sqr90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 6\right)}} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      14. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{{im}^{\color{blue}{12}} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    11. Simplified90.9%

      \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{\sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}} + \left(im \cdot im\right) \cdot 1\right)\right) \]

    if -4.9000000000000001e25 < im < 1.9199999999999999

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

      \[\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. unpow295.5%

        \[\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. *-commutative95.5%

        \[\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. Simplified95.5%

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

    if 1.9199999999999999 < im

    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. Applied egg-rr100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\ \mathbf{elif}\;im \leq 1.92:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \]

Alternative 6: 96.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1 \cdot 10^{+86}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1e+86)
   (* 0.041666666666666664 (* (cos re) (pow im 4.0)))
   (if (<= im -4.9e+25)
     (*
      0.5
      (+ 2.0 (+ (* im im) (cbrt (* (pow im 12.0) 0.0005787037037037037)))))
     (if (<= im 1.3)
       (* (* (cos re) 0.5) (+ 2.0 (* im im)))
       (* (cos re) (+ (* 0.5 (exp im)) 0.001953125))))))
double code(double re, double im) {
	double tmp;
	if (im <= -1e+86) {
		tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	} else if (im <= -4.9e+25) {
		tmp = 0.5 * (2.0 + ((im * im) + cbrt((pow(im, 12.0) * 0.0005787037037037037))));
	} else if (im <= 1.3) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= -1e+86) {
		tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	} else if (im <= -4.9e+25) {
		tmp = 0.5 * (2.0 + ((im * im) + Math.cbrt((Math.pow(im, 12.0) * 0.0005787037037037037))));
	} else if (im <= 1.3) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = Math.cos(re) * ((0.5 * Math.exp(im)) + 0.001953125);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= -1e+86)
		tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)));
	elseif (im <= -4.9e+25)
		tmp = Float64(0.5 * Float64(2.0 + Float64(Float64(im * im) + cbrt(Float64((im ^ 12.0) * 0.0005787037037037037)))));
	elseif (im <= 1.3)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + 0.001953125));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, -1e+86], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -4.9e+25], N[(0.5 * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[Power[N[(N[Power[im, 12.0], $MachinePrecision] * 0.0005787037037037037), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.3], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1 \cdot 10^{+86}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\

\mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\
\;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\

\mathbf{elif}\;im \leq 1.3:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

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


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

    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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 100.0%

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

    if -1e86 < im < -4.9000000000000001e25

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

      \[\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. unpow231.9%

        \[\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. *-commutative31.9%

        \[\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. Simplified31.9%

      \[\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 re around 0 31.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity31.5%

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{\left(im \cdot im\right)} \cdot 1\right)\right) \]
    7. Applied egg-rr31.5%

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{\sqrt[3]{\left(\left(0.08333333333333333 \cdot {im}^{4}\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      2. pow1/390.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{{\left(\left(\left(0.08333333333333333 \cdot {im}^{4}\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {im}^{4}\right)\right)}^{0.3333333333333333}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      3. pow390.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\color{blue}{\left({\left(0.08333333333333333 \cdot {im}^{4}\right)}^{3}\right)}}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      4. *-commutative90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\left({\color{blue}{\left({im}^{4} \cdot 0.08333333333333333\right)}}^{3}\right)}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      5. unpow-prod-down90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\color{blue}{\left({\left({im}^{4}\right)}^{3} \cdot {0.08333333333333333}^{3}\right)}}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      6. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left({\left({\left({im}^{4}\right)}^{3} \cdot \color{blue}{0.0005787037037037037}\right)}^{0.3333333333333333} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    9. Applied egg-rr90.9%

      \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{{\left({\left({im}^{4}\right)}^{3} \cdot 0.0005787037037037037\right)}^{0.3333333333333333}} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    10. Step-by-step derivation
      1. unpow1/390.9%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{{\left(\left(im \cdot im\right) \cdot \color{blue}{\left(im \cdot im\right)}\right)}^{3} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      6. cube-prod90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\color{blue}{\left({\left(im \cdot im\right)}^{3} \cdot {\left(im \cdot im\right)}^{3}\right)} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      7. cube-prod90.9%

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

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

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{\color{blue}{6}} \cdot {\left(im \cdot im\right)}^{3}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      10. cube-prod90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot \color{blue}{\left({im}^{3} \cdot {im}^{3}\right)}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      11. pow-sqr90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot \color{blue}{{im}^{\left(2 \cdot 3\right)}}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      12. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\left({im}^{6} \cdot {im}^{\color{blue}{6}}\right) \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      13. pow-sqr90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{\color{blue}{{im}^{\left(2 \cdot 6\right)}} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
      14. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(2 + \left(\sqrt[3]{{im}^{\color{blue}{12}} \cdot 0.0005787037037037037} + \left(im \cdot im\right) \cdot 1\right)\right) \]
    11. Simplified90.9%

      \[\leadsto 0.5 \cdot \left(2 + \left(\color{blue}{\sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}} + \left(im \cdot im\right) \cdot 1\right)\right) \]

    if -4.9000000000000001e25 < im < 1.30000000000000004

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

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

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

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

    if 1.30000000000000004 < im

    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. Applied egg-rr100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1 \cdot 10^{+86}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -4.9 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + \sqrt[3]{{im}^{12} \cdot 0.0005787037037037037}\right)\right)\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \]

Alternative 7: 93.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -2 \cdot 10^{+88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 2.2:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.16 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.041666666666666664 (* (cos re) (pow im 4.0)))))
   (if (<= im -2e+88)
     t_0
     (if (<= im -1.46e+41)
       (sqrt (* (pow im 8.0) 0.001736111111111111))
       (if (<= im 2.2)
         (* (* (cos re) 0.5) (+ 2.0 (* im im)))
         (if (<= im 1.16e+77) (+ (* 0.5 (exp im)) 0.001953125) t_0))))))
double code(double re, double im) {
	double t_0 = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	double tmp;
	if (im <= -2e+88) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = sqrt((pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 2.2) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.16e+77) {
		tmp = (0.5 * exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
    if (im <= (-2d+88)) then
        tmp = t_0
    else if (im <= (-1.46d+41)) then
        tmp = sqrt(((im ** 8.0d0) * 0.001736111111111111d0))
    else if (im <= 2.2d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.16d+77) then
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	double tmp;
	if (im <= -2e+88) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = Math.sqrt((Math.pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 2.2) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.16e+77) {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0))
	tmp = 0
	if im <= -2e+88:
		tmp = t_0
	elif im <= -1.46e+41:
		tmp = math.sqrt((math.pow(im, 8.0) * 0.001736111111111111))
	elif im <= 2.2:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.16e+77:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)))
	tmp = 0.0
	if (im <= -2e+88)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = sqrt(Float64((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 2.2)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.16e+77)
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.041666666666666664 * (cos(re) * (im ^ 4.0));
	tmp = 0.0;
	if (im <= -2e+88)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = sqrt(((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 2.2)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.16e+77)
		tmp = (0.5 * exp(im)) + 0.001953125;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2e+88], t$95$0, If[LessEqual[im, -1.46e+41], N[Sqrt[N[(N[Power[im, 8.0], $MachinePrecision] * 0.001736111111111111), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 2.2], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.16e+77], N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\mathbf{if}\;im \leq -2 \cdot 10^{+88}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\

\mathbf{elif}\;im \leq 2.2:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 1.16 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.99999999999999992e88 or 1.1600000000000001e77 < 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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 100.0%

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

    if -1.99999999999999992e88 < im < -1.4600000000000001e41

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

      \[\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. unpow238.0%

        \[\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. *-commutative38.0%

        \[\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. Simplified38.0%

      \[\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 38.0%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 38.0%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative38.0%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified38.0%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt38.0%

        \[\leadsto \color{blue}{\sqrt{{im}^{4} \cdot 0.041666666666666664} \cdot \sqrt{{im}^{4} \cdot 0.041666666666666664}} \]
      2. sqrt-unprod100.0%

        \[\leadsto \color{blue}{\sqrt{\left({im}^{4} \cdot 0.041666666666666664\right) \cdot \left({im}^{4} \cdot 0.041666666666666664\right)}} \]
      3. swap-sqr100.0%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{4} \cdot {im}^{4}\right) \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)}} \]
      4. pow-prod-up100.0%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(4 + 4\right)}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{\color{blue}{8}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      6. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{8} \cdot \color{blue}{0.001736111111111111}} \]
    10. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\sqrt{{im}^{8} \cdot 0.001736111111111111}} \]

    if -1.4600000000000001e41 < im < 2.2000000000000002

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

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

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

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

    if 2.2000000000000002 < im < 1.1600000000000001e77

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification96.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2 \cdot 10^{+88}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 2.2:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.16 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \end{array} \]

Alternative 8: 95.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.5e+85)
   (* 0.041666666666666664 (* (cos re) (pow im 4.0)))
   (if (<= im -1.46e+41)
     (sqrt (* (pow im 8.0) 0.001736111111111111))
     (if (<= im 1.3)
       (* (* (cos re) 0.5) (+ 2.0 (* im im)))
       (* (cos re) (+ (* 0.5 (exp im)) 0.001953125))))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	} else if (im <= -1.46e+41) {
		tmp = sqrt((pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 1.3) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= (-1.5d+85)) then
        tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
    else if (im <= (-1.46d+41)) then
        tmp = sqrt(((im ** 8.0d0) * 0.001736111111111111d0))
    else if (im <= 1.3d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else
        tmp = cos(re) * ((0.5d0 * exp(im)) + 0.001953125d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.5e+85) {
		tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
	} else if (im <= -1.46e+41) {
		tmp = Math.sqrt((Math.pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 1.3) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else {
		tmp = Math.cos(re) * ((0.5 * Math.exp(im)) + 0.001953125);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -1.5e+85:
		tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0))
	elif im <= -1.46e+41:
		tmp = math.sqrt((math.pow(im, 8.0) * 0.001736111111111111))
	elif im <= 1.3:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	else:
		tmp = math.cos(re) * ((0.5 * math.exp(im)) + 0.001953125)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -1.5e+85)
		tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)));
	elseif (im <= -1.46e+41)
		tmp = sqrt(Float64((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 1.3)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	else
		tmp = Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + 0.001953125));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -1.5e+85)
		tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0));
	elseif (im <= -1.46e+41)
		tmp = sqrt(((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 1.3)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	else
		tmp = cos(re) * ((0.5 * exp(im)) + 0.001953125);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -1.5e+85], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -1.46e+41], N[Sqrt[N[(N[Power[im, 8.0], $MachinePrecision] * 0.001736111111111111), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 1.3], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\

\mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\

\mathbf{elif}\;im \leq 1.3:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

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


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

    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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 100.0%

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

    if -1.5e85 < im < -1.4600000000000001e41

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

      \[\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. unpow238.0%

        \[\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. *-commutative38.0%

        \[\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. Simplified38.0%

      \[\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 38.0%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 38.0%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative38.0%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified38.0%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt38.0%

        \[\leadsto \color{blue}{\sqrt{{im}^{4} \cdot 0.041666666666666664} \cdot \sqrt{{im}^{4} \cdot 0.041666666666666664}} \]
      2. sqrt-unprod100.0%

        \[\leadsto \color{blue}{\sqrt{\left({im}^{4} \cdot 0.041666666666666664\right) \cdot \left({im}^{4} \cdot 0.041666666666666664\right)}} \]
      3. swap-sqr100.0%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{4} \cdot {im}^{4}\right) \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)}} \]
      4. pow-prod-up100.0%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(4 + 4\right)}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{\color{blue}{8}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      6. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{8} \cdot \color{blue}{0.001736111111111111}} \]
    10. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\sqrt{{im}^{8} \cdot 0.001736111111111111}} \]

    if -1.4600000000000001e41 < im < 1.30000000000000004

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

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

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

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

    if 1.30000000000000004 < im

    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. Applied egg-rr100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im} + 0.001953125\right)\\ \end{array} \]

Alternative 9: 90.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -5 \cdot 10^{+167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 2.35:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
   (if (<= im -5e+167)
     t_0
     (if (<= im -1.46e+41)
       (sqrt (* (pow im 8.0) 0.001736111111111111))
       (if (<= im 2.35)
         (* (* (cos re) 0.5) (+ 2.0 (* im im)))
         (if (<= im 1.35e+154) (+ (* 0.5 (exp im)) 0.001953125) t_0))))))
double code(double re, double im) {
	double t_0 = cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -5e+167) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = sqrt((pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 2.35) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(re) * (0.5d0 * (im * im))
    if (im <= (-5d+167)) then
        tmp = t_0
    else if (im <= (-1.46d+41)) then
        tmp = sqrt(((im ** 8.0d0) * 0.001736111111111111d0))
    else if (im <= 2.35d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.35d+154) then
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -5e+167) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = Math.sqrt((Math.pow(im, 8.0) * 0.001736111111111111));
	} else if (im <= 2.35) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.cos(re) * (0.5 * (im * im))
	tmp = 0
	if im <= -5e+167:
		tmp = t_0
	elif im <= -1.46e+41:
		tmp = math.sqrt((math.pow(im, 8.0) * 0.001736111111111111))
	elif im <= 2.35:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.35e+154:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im)))
	tmp = 0.0
	if (im <= -5e+167)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = sqrt(Float64((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 2.35)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = cos(re) * (0.5 * (im * im));
	tmp = 0.0;
	if (im <= -5e+167)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = sqrt(((im ^ 8.0) * 0.001736111111111111));
	elseif (im <= 2.35)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.35e+154)
		tmp = (0.5 * exp(im)) + 0.001953125;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5e+167], t$95$0, If[LessEqual[im, -1.46e+41], N[Sqrt[N[(N[Power[im, 8.0], $MachinePrecision] * 0.001736111111111111), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 2.35], 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[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\

\mathbf{elif}\;im \leq 2.35:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -4.9999999999999997e167 or 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-*r*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)} \]

    if -4.9999999999999997e167 < im < -1.4600000000000001e41

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

      \[\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. unpow275.7%

        \[\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. *-commutative75.7%

        \[\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. Simplified75.7%

      \[\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 75.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 62.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative62.7%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified62.7%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt62.7%

        \[\leadsto \color{blue}{\sqrt{{im}^{4} \cdot 0.041666666666666664} \cdot \sqrt{{im}^{4} \cdot 0.041666666666666664}} \]
      2. sqrt-unprod87.0%

        \[\leadsto \color{blue}{\sqrt{\left({im}^{4} \cdot 0.041666666666666664\right) \cdot \left({im}^{4} \cdot 0.041666666666666664\right)}} \]
      3. swap-sqr87.0%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{4} \cdot {im}^{4}\right) \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)}} \]
      4. pow-prod-up87.0%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(4 + 4\right)}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      5. metadata-eval87.0%

        \[\leadsto \sqrt{{im}^{\color{blue}{8}} \cdot \left(0.041666666666666664 \cdot 0.041666666666666664\right)} \]
      6. metadata-eval87.0%

        \[\leadsto \sqrt{{im}^{8} \cdot \color{blue}{0.001736111111111111}} \]
    10. Applied egg-rr87.0%

      \[\leadsto \color{blue}{\sqrt{{im}^{8} \cdot 0.001736111111111111}} \]

    if -1.4600000000000001e41 < im < 2.35000000000000009

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

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

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

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

    if 2.35000000000000009 < im < 1.35000000000000003e154

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification94.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5 \cdot 10^{+167}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;\sqrt{{im}^{8} \cdot 0.001736111111111111}\\ \mathbf{elif}\;im \leq 2.35:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 10: 87.9% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -1.6 \cdot 10^{+166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
   (if (<= im -1.6e+166)
     t_0
     (if (<= im -1.46e+41)
       (* 0.041666666666666664 (pow im 4.0))
       (if (<= im 1.3)
         (cos re)
         (if (<= im 1.35e+154) (+ (* 0.5 (exp im)) 0.001953125) t_0))))))
double code(double re, double im) {
	double t_0 = cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.6e+166) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = 0.041666666666666664 * pow(im, 4.0);
	} else if (im <= 1.3) {
		tmp = cos(re);
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(re) * (0.5d0 * (im * im))
    if (im <= (-1.6d+166)) then
        tmp = t_0
    else if (im <= (-1.46d+41)) then
        tmp = 0.041666666666666664d0 * (im ** 4.0d0)
    else if (im <= 1.3d0) then
        tmp = cos(re)
    else if (im <= 1.35d+154) then
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.6e+166) {
		tmp = t_0;
	} else if (im <= -1.46e+41) {
		tmp = 0.041666666666666664 * Math.pow(im, 4.0);
	} else if (im <= 1.3) {
		tmp = Math.cos(re);
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.cos(re) * (0.5 * (im * im))
	tmp = 0
	if im <= -1.6e+166:
		tmp = t_0
	elif im <= -1.46e+41:
		tmp = 0.041666666666666664 * math.pow(im, 4.0)
	elif im <= 1.3:
		tmp = math.cos(re)
	elif im <= 1.35e+154:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im)))
	tmp = 0.0
	if (im <= -1.6e+166)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = Float64(0.041666666666666664 * (im ^ 4.0));
	elseif (im <= 1.3)
		tmp = cos(re);
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = cos(re) * (0.5 * (im * im));
	tmp = 0.0;
	if (im <= -1.6e+166)
		tmp = t_0;
	elseif (im <= -1.46e+41)
		tmp = 0.041666666666666664 * (im ^ 4.0);
	elseif (im <= 1.3)
		tmp = cos(re);
	elseif (im <= 1.35e+154)
		tmp = (0.5 * exp(im)) + 0.001953125;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.6e+166], t$95$0, If[LessEqual[im, -1.46e+41], N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.3], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;0.041666666666666664 \cdot {im}^{4}\\

\mathbf{elif}\;im \leq 1.3:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.59999999999999984e166 or 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-*r*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)} \]

    if -1.59999999999999984e166 < im < -1.4600000000000001e41

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

      \[\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. unpow275.7%

        \[\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. *-commutative75.7%

        \[\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. Simplified75.7%

      \[\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 75.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 62.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative62.7%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified62.7%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]

    if -1.4600000000000001e41 < im < 1.30000000000000004

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

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

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

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

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

    if 1.30000000000000004 < im < 1.35000000000000003e154

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification92.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.6 \cdot 10^{+166}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 1.3:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 11: 88.2% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -1.6 \cdot 10^{+166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.85 \cdot 10^{+42}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 2.1:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
   (if (<= im -1.6e+166)
     t_0
     (if (<= im -1.85e+42)
       (* 0.041666666666666664 (pow im 4.0))
       (if (<= im 2.1)
         (* (* (cos re) 0.5) (+ 2.0 (* im im)))
         (if (<= im 1.35e+154) (+ (* 0.5 (exp im)) 0.001953125) t_0))))))
double code(double re, double im) {
	double t_0 = cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.6e+166) {
		tmp = t_0;
	} else if (im <= -1.85e+42) {
		tmp = 0.041666666666666664 * pow(im, 4.0);
	} else if (im <= 2.1) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(re) * (0.5d0 * (im * im))
    if (im <= (-1.6d+166)) then
        tmp = t_0
    else if (im <= (-1.85d+42)) then
        tmp = 0.041666666666666664d0 * (im ** 4.0d0)
    else if (im <= 2.1d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.35d+154) then
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.6e+166) {
		tmp = t_0;
	} else if (im <= -1.85e+42) {
		tmp = 0.041666666666666664 * Math.pow(im, 4.0);
	} else if (im <= 2.1) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.cos(re) * (0.5 * (im * im))
	tmp = 0
	if im <= -1.6e+166:
		tmp = t_0
	elif im <= -1.85e+42:
		tmp = 0.041666666666666664 * math.pow(im, 4.0)
	elif im <= 2.1:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.35e+154:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im)))
	tmp = 0.0
	if (im <= -1.6e+166)
		tmp = t_0;
	elseif (im <= -1.85e+42)
		tmp = Float64(0.041666666666666664 * (im ^ 4.0));
	elseif (im <= 2.1)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = cos(re) * (0.5 * (im * im));
	tmp = 0.0;
	if (im <= -1.6e+166)
		tmp = t_0;
	elseif (im <= -1.85e+42)
		tmp = 0.041666666666666664 * (im ^ 4.0);
	elseif (im <= 2.1)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.35e+154)
		tmp = (0.5 * exp(im)) + 0.001953125;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.6e+166], t$95$0, If[LessEqual[im, -1.85e+42], N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.1], 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[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -1.85 \cdot 10^{+42}:\\
\;\;\;\;0.041666666666666664 \cdot {im}^{4}\\

\mathbf{elif}\;im \leq 2.1:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.59999999999999984e166 or 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-*r*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)} \]

    if -1.59999999999999984e166 < im < -1.84999999999999998e42

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

      \[\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. unpow275.7%

        \[\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. *-commutative75.7%

        \[\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. Simplified75.7%

      \[\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 75.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 62.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative62.7%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified62.7%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]

    if -1.84999999999999998e42 < im < 2.10000000000000009

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

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

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

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

    if 2.10000000000000009 < im < 1.35000000000000003e154

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification92.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.6 \cdot 10^{+166}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -1.85 \cdot 10^{+42}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 2.1:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 12: 89.4% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -1.32 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -750:\\ \;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot \left(re \cdot re\right)\right)\\ \mathbf{elif}\;im \leq 1.82:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
   (if (<= im -1.32e+154)
     t_0
     (if (<= im -750.0)
       (*
        (pow im 4.0)
        (+ 0.041666666666666664 (* -0.020833333333333332 (* re re))))
       (if (<= im 1.82)
         (* (* (cos re) 0.5) (+ 2.0 (* im im)))
         (if (<= im 1.35e+154) (+ (* 0.5 (exp im)) 0.001953125) t_0))))))
double code(double re, double im) {
	double t_0 = cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.32e+154) {
		tmp = t_0;
	} else if (im <= -750.0) {
		tmp = pow(im, 4.0) * (0.041666666666666664 + (-0.020833333333333332 * (re * re)));
	} else if (im <= 1.82) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cos(re) * (0.5d0 * (im * im))
    if (im <= (-1.32d+154)) then
        tmp = t_0
    else if (im <= (-750.0d0)) then
        tmp = (im ** 4.0d0) * (0.041666666666666664d0 + ((-0.020833333333333332d0) * (re * re)))
    else if (im <= 1.82d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.35d+154) then
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.32e+154) {
		tmp = t_0;
	} else if (im <= -750.0) {
		tmp = Math.pow(im, 4.0) * (0.041666666666666664 + (-0.020833333333333332 * (re * re)));
	} else if (im <= 1.82) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.35e+154) {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.cos(re) * (0.5 * (im * im))
	tmp = 0
	if im <= -1.32e+154:
		tmp = t_0
	elif im <= -750.0:
		tmp = math.pow(im, 4.0) * (0.041666666666666664 + (-0.020833333333333332 * (re * re)))
	elif im <= 1.82:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.35e+154:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im)))
	tmp = 0.0
	if (im <= -1.32e+154)
		tmp = t_0;
	elseif (im <= -750.0)
		tmp = Float64((im ^ 4.0) * Float64(0.041666666666666664 + Float64(-0.020833333333333332 * Float64(re * re))));
	elseif (im <= 1.82)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = cos(re) * (0.5 * (im * im));
	tmp = 0.0;
	if (im <= -1.32e+154)
		tmp = t_0;
	elseif (im <= -750.0)
		tmp = (im ^ 4.0) * (0.041666666666666664 + (-0.020833333333333332 * (re * re)));
	elseif (im <= 1.82)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.35e+154)
		tmp = (0.5 * exp(im)) + 0.001953125;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.32e+154], t$95$0, If[LessEqual[im, -750.0], N[(N[Power[im, 4.0], $MachinePrecision] * N[(0.041666666666666664 + N[(-0.020833333333333332 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.82], 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[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -750:\\
\;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot \left(re \cdot re\right)\right)\\

\mathbf{elif}\;im \leq 1.82:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.31999999999999998e154 or 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-*r*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)} \]

    if -1.31999999999999998e154 < im < -750

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

      \[\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. unpow255.7%

        \[\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. *-commutative55.7%

        \[\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. Simplified55.7%

      \[\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 55.7%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 5.3%

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

        \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4} + -0.020833333333333332 \cdot \left({re}^{2} \cdot {im}^{4}\right)} \]
      2. associate-*r*5.3%

        \[\leadsto 0.041666666666666664 \cdot {im}^{4} + \color{blue}{\left(-0.020833333333333332 \cdot {re}^{2}\right) \cdot {im}^{4}} \]
      3. distribute-rgt-out52.0%

        \[\leadsto \color{blue}{{im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot {re}^{2}\right)} \]
      4. unpow252.0%

        \[\leadsto {im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot \color{blue}{\left(re \cdot re\right)}\right) \]
    8. Simplified52.0%

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot \left(re \cdot re\right)\right)} \]

    if -750 < im < 1.82000000000000006

    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)} \]

    if 1.82000000000000006 < im < 1.35000000000000003e154

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification93.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.32 \cdot 10^{+154}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -750:\\ \;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + -0.020833333333333332 \cdot \left(re \cdot re\right)\right)\\ \mathbf{elif}\;im \leq 1.82:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 13: 81.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.46e+41)
   (* 0.041666666666666664 (pow im 4.0))
   (if (<= im 2.0) (cos re) (+ (* 0.5 (exp im)) 0.001953125))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.46e+41) {
		tmp = 0.041666666666666664 * pow(im, 4.0);
	} else if (im <= 2.0) {
		tmp = cos(re);
	} else {
		tmp = (0.5 * exp(im)) + 0.001953125;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= (-1.46d+41)) then
        tmp = 0.041666666666666664d0 * (im ** 4.0d0)
    else if (im <= 2.0d0) then
        tmp = cos(re)
    else
        tmp = (0.5d0 * exp(im)) + 0.001953125d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.46e+41) {
		tmp = 0.041666666666666664 * Math.pow(im, 4.0);
	} else if (im <= 2.0) {
		tmp = Math.cos(re);
	} else {
		tmp = (0.5 * Math.exp(im)) + 0.001953125;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -1.46e+41:
		tmp = 0.041666666666666664 * math.pow(im, 4.0)
	elif im <= 2.0:
		tmp = math.cos(re)
	else:
		tmp = (0.5 * math.exp(im)) + 0.001953125
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -1.46e+41)
		tmp = Float64(0.041666666666666664 * (im ^ 4.0));
	elseif (im <= 2.0)
		tmp = cos(re);
	else
		tmp = Float64(Float64(0.5 * exp(im)) + 0.001953125);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -1.46e+41)
		tmp = 0.041666666666666664 * (im ^ 4.0);
	elseif (im <= 2.0)
		tmp = cos(re);
	else
		tmp = (0.5 * exp(im)) + 0.001953125;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -1.46e+41], N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.0], N[Cos[re], $MachinePrecision], N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + 0.001953125), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.46 \cdot 10^{+41}:\\
\;\;\;\;0.041666666666666664 \cdot {im}^{4}\\

\mathbf{elif}\;im \leq 2:\\
\;\;\;\;\cos re\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.001953125\\


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

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

      \[\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. unpow287.0%

        \[\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. *-commutative87.0%

        \[\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. Simplified87.0%

      \[\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 87.0%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 68.4%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative68.4%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified68.4%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]

    if -1.4600000000000001e41 < im < 2

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

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

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

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

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

    if 2 < im

    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. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.46 \cdot 10^{+41}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.001953125\\ \end{array} \]

Alternative 14: 77.3% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.7 \cdot 10^{+41} \lor \neg \left(im \leq 12.6\right):\\
\;\;\;\;0.041666666666666664 \cdot {im}^{4}\\

\mathbf{else}:\\
\;\;\;\;\cos re\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.69999999999999999e41 or 12.5999999999999996 < 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 76.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. unpow276.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. *-commutative76.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. Simplified76.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 76.2%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Taylor expanded in re around 0 59.5%

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
    7. Step-by-step derivation
      1. *-commutative59.5%

        \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]
    8. Simplified59.5%

      \[\leadsto \color{blue}{{im}^{4} \cdot 0.041666666666666664} \]

    if -1.69999999999999999e41 < im < 12.5999999999999996

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

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

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

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

      \[\leadsto \color{blue}{\cos re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.7 \cdot 10^{+41} \lor \neg \left(im \leq 12.6\right):\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{else}:\\ \;\;\;\;\cos re\\ \end{array} \]

Alternative 15: 73.6% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -510 \lor \neg \left(im \leq 2.2 \cdot 10^{+14}\right):\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;\cos re\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -510 or 2.2e14 < 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 48.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -510 < im < 2.2e14

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

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

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

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

      \[\leadsto \color{blue}{\cos re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -510 \lor \neg \left(im \leq 2.2 \cdot 10^{+14}\right):\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re\\ \end{array} \]

Alternative 16: 47.3% accurate, 23.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.7 \cdot 10^{+200}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -5.70000000000000007e200

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)} \]
    8. Taylor expanded in re around 0 9.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. +-commutative9.7%

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

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

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

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

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

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

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

    if -5.70000000000000007e200 < 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 85.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. unpow285.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. *-commutative85.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. Simplified85.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 re around 0 64.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
    6. Taylor expanded in im around 0 52.4%

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

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

      \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.9%

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

Alternative 17: 46.3% accurate, 33.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.42 \lor \neg \left(im \leq 1.4\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.4199999999999999 or 1.3999999999999999 < 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 71.9%

      \[\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. unpow271.9%

        \[\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. *-commutative71.9%

        \[\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. Simplified71.9%

      \[\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 re around 0 56.1%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
    6. Taylor expanded in im around 0 34.8%

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    11. Simplified34.8%

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

    if -1.4199999999999999 < im < 1.3999999999999999

    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 + \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)\right)} \]
    3. Step-by-step derivation
      1. unpow2100.0%

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

        \[\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. Simplified100.0%

      \[\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 re around 0 64.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
    6. Taylor expanded in im around 0 64.6%

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

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

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification48.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.42 \lor \neg \left(im \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 18: 46.4% accurate, 44.0× speedup?

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

\\
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 85.3%

    \[\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. unpow285.3%

      \[\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. *-commutative85.3%

      \[\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. Simplified85.3%

    \[\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 re around 0 60.1%

    \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
  6. Taylor expanded in im around 0 49.0%

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

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

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

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

Alternative 19: 8.6% accurate, 308.0× speedup?

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

\\
0.501953125
\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. Applied egg-rr42.0%

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

    \[\leadsto \color{blue}{0.001953125 + 0.5 \cdot e^{im}} \]
  6. Taylor expanded in im around 0 9.2%

    \[\leadsto \color{blue}{0.501953125} \]
  7. Final simplification9.2%

    \[\leadsto 0.501953125 \]

Alternative 20: 27.5% accurate, 308.0× speedup?

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

\\
1
\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 85.3%

    \[\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. unpow285.3%

      \[\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. *-commutative85.3%

      \[\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. Simplified85.3%

    \[\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 re around 0 60.1%

    \[\leadsto \color{blue}{0.5 \cdot \left(2 + \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)\right)} \]
  6. Taylor expanded in im around 0 49.0%

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

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

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

    \[\leadsto \color{blue}{1} \]
  10. Final simplification32.1%

    \[\leadsto 1 \]

Reproduce

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