math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 8.7s
Alternatives: 15
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 15 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, 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}
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(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]

Alternative 2: 86.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

    if 2.5 < im < 1.1999999999999999e77

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
    5. Simplified76.9%

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

    if 1.1999999999999999e77 < 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. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.5:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \end{array} \]

Alternative 3: 92.5% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.5:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot im\right) + 0.08333333333333333 \cdot {im}^{4}\right)\\

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

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


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

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

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

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

    if 2.5 < im < 1.1999999999999999e77

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
    5. Simplified76.9%

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

    if 1.1999999999999999e77 < 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. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.5:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot im\right) + 0.08333333333333333 \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \end{array} \]

Alternative 4: 85.6% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 0.053:\\
\;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(im \cdot im\right)\\


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

    1. Initial program 100.0%

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

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

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

    if 0.0529999999999999985 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 5: 87.0% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\

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


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

    1. Initial program 100.0%

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

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

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

    if 0.0389999999999999999 < im < 1.1999999999999999e77

    1. Initial program 100.0%

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

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

    if 1.1999999999999999e77 < 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. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.039:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \end{array} \]

Alternative 6: 81.7% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 250:\\
\;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(im \cdot im\right)\\


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

    1. Initial program 100.0%

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

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

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

    if 250 < im < 1.35000000000000003e154

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 57.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. Simplified57.5%

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified57.5%

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

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

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

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

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

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

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

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 7: 68.8% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 250:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.45 \cdot 10^{+76}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\

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


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

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

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

    if 250 < im < 1.4500000000000001e76

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 11.0%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)\right)} \]
      2. expm1-udef2.0%

        \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)} - 1\right)} \]
      3. *-commutative2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{{re}^{2} \cdot -0.5}\right)} - 1\right) \]
      4. unpow22.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(re \cdot re\right)} \cdot -0.5\right)} - 1\right) \]
      5. associate-*l*2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{re \cdot \left(re \cdot -0.5\right)}\right)} - 1\right) \]
    5. Applied egg-rr2.0%

      \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)} - 1\right)} \]
    6. Step-by-step derivation
      1. expm1-def2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)\right)} \]
      2. expm1-log1p11.0%

        \[\leadsto 1 + \color{blue}{re \cdot \left(re \cdot -0.5\right)} \]
    7. Simplified11.0%

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

    if 1.4500000000000001e76 < im < 1.35000000000000003e154

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 95.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. Simplified95.0%

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      2. metadata-eval71.4%

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

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

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
    6. Simplified71.4%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)} \]
    7. Taylor expanded in im around inf 71.4%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 8: 69.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 700:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+76}:\\ \;\;\;\;{im}^{4} \cdot \left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 700.0)
   (cos re)
   (if (<= im 8.2e+76)
     (* (pow im 4.0) (* re (* re -0.020833333333333332)))
     (if (<= im 1.35e+154)
       (+ (* (pow im 4.0) 0.041666666666666664) 1.0)
       (* (* 0.5 (cos re)) (* im im))))))
double code(double re, double im) {
	double tmp;
	if (im <= 700.0) {
		tmp = cos(re);
	} else if (im <= 8.2e+76) {
		tmp = pow(im, 4.0) * (re * (re * -0.020833333333333332));
	} else if (im <= 1.35e+154) {
		tmp = (pow(im, 4.0) * 0.041666666666666664) + 1.0;
	} else {
		tmp = (0.5 * cos(re)) * (im * im);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 700.0d0) then
        tmp = cos(re)
    else if (im <= 8.2d+76) then
        tmp = (im ** 4.0d0) * (re * (re * (-0.020833333333333332d0)))
    else if (im <= 1.35d+154) then
        tmp = ((im ** 4.0d0) * 0.041666666666666664d0) + 1.0d0
    else
        tmp = (0.5d0 * cos(re)) * (im * im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 700.0) {
		tmp = Math.cos(re);
	} else if (im <= 8.2e+76) {
		tmp = Math.pow(im, 4.0) * (re * (re * -0.020833333333333332));
	} else if (im <= 1.35e+154) {
		tmp = (Math.pow(im, 4.0) * 0.041666666666666664) + 1.0;
	} else {
		tmp = (0.5 * Math.cos(re)) * (im * im);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 700.0:
		tmp = math.cos(re)
	elif im <= 8.2e+76:
		tmp = math.pow(im, 4.0) * (re * (re * -0.020833333333333332))
	elif im <= 1.35e+154:
		tmp = (math.pow(im, 4.0) * 0.041666666666666664) + 1.0
	else:
		tmp = (0.5 * math.cos(re)) * (im * im)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 700.0)
		tmp = cos(re);
	elseif (im <= 8.2e+76)
		tmp = Float64((im ^ 4.0) * Float64(re * Float64(re * -0.020833333333333332)));
	elseif (im <= 1.35e+154)
		tmp = Float64(Float64((im ^ 4.0) * 0.041666666666666664) + 1.0);
	else
		tmp = Float64(Float64(0.5 * cos(re)) * Float64(im * im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 700.0)
		tmp = cos(re);
	elseif (im <= 8.2e+76)
		tmp = (im ^ 4.0) * (re * (re * -0.020833333333333332));
	elseif (im <= 1.35e+154)
		tmp = ((im ^ 4.0) * 0.041666666666666664) + 1.0;
	else
		tmp = (0.5 * cos(re)) * (im * im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 700.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 8.2e+76], N[(N[Power[im, 4.0], $MachinePrecision] * N[(re * N[(re * -0.020833333333333332), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 700:\\
\;\;\;\;\cos re\\

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

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\

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


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

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

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

    if 700 < im < 8.1999999999999997e76

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 4.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. Simplified4.3%

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

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

        \[\leadsto \color{blue}{\left(0.041666666666666664 \cdot \cos re\right) \cdot {im}^{4}} \]
      2. *-commutative4.3%

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified4.3%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)} \]
    10. Taylor expanded in re around inf 10.9%

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

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

        \[\leadsto \color{blue}{\left(-0.020833333333333332 \cdot \left(re \cdot re\right)\right) \cdot {im}^{4}} \]
      3. *-commutative10.9%

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

        \[\leadsto \color{blue}{\left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)} \cdot {im}^{4} \]
      5. *-commutative10.9%

        \[\leadsto \color{blue}{{im}^{4} \cdot \left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)} \]
    12. Simplified10.9%

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

    if 8.1999999999999997e76 < im < 1.35000000000000003e154

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 95.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. Simplified95.0%

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      2. metadata-eval71.4%

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

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

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
    6. Simplified71.4%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)} \]
    7. Taylor expanded in im around inf 71.4%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 700:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+76}:\\ \;\;\;\;{im}^{4} \cdot \left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 9: 82.0% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 700:\\
\;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\

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

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(im \cdot im\right)\\


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

    1. Initial program 100.0%

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

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

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

    if 700 < im < 2.2e76

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 4.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. Simplified4.3%

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

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

        \[\leadsto \color{blue}{\left(0.041666666666666664 \cdot \cos re\right) \cdot {im}^{4}} \]
      2. *-commutative4.3%

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified4.3%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)} \]
    10. Taylor expanded in re around inf 10.9%

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

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

        \[\leadsto \color{blue}{\left(-0.020833333333333332 \cdot \left(re \cdot re\right)\right) \cdot {im}^{4}} \]
      3. *-commutative10.9%

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

        \[\leadsto \color{blue}{\left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)} \cdot {im}^{4} \]
      5. *-commutative10.9%

        \[\leadsto \color{blue}{{im}^{4} \cdot \left(re \cdot \left(re \cdot -0.020833333333333332\right)\right)} \]
    12. Simplified10.9%

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

    if 2.2e76 < im < 1.35000000000000003e154

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 95.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. Simplified95.0%

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      2. metadata-eval71.4%

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

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

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
    6. Simplified71.4%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)} \]
    7. Taylor expanded in im around inf 71.4%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

Alternative 10: 65.4% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 250:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.15 \cdot 10^{+74}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\


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

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

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

    if 250 < im < 1.1499999999999999e74

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 11.0%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)\right)} \]
      2. expm1-udef2.0%

        \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)} - 1\right)} \]
      3. *-commutative2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{{re}^{2} \cdot -0.5}\right)} - 1\right) \]
      4. unpow22.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(re \cdot re\right)} \cdot -0.5\right)} - 1\right) \]
      5. associate-*l*2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{re \cdot \left(re \cdot -0.5\right)}\right)} - 1\right) \]
    5. Applied egg-rr2.0%

      \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)} - 1\right)} \]
    6. Step-by-step derivation
      1. expm1-def2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)\right)} \]
      2. expm1-log1p11.0%

        \[\leadsto 1 + \color{blue}{re \cdot \left(re \cdot -0.5\right)} \]
    7. Simplified11.0%

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

    if 1.1499999999999999e74 < 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 97.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. Simplified97.9%

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left({im}^{2} + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      2. metadata-eval66.2%

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

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

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

      \[\leadsto \color{blue}{1 + 0.5 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)} \]
    7. Taylor expanded in im around inf 66.2%

      \[\leadsto 1 + \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 250:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+74}:\\ \;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664 + 1\\ \end{array} \]

Alternative 11: 65.4% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 250:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 4.3 \cdot 10^{+73}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664\\


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

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

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

    if 250 < im < 4.30000000000000013e73

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 11.0%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)\right)} \]
      2. expm1-udef2.0%

        \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)} - 1\right)} \]
      3. *-commutative2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{{re}^{2} \cdot -0.5}\right)} - 1\right) \]
      4. unpow22.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(re \cdot re\right)} \cdot -0.5\right)} - 1\right) \]
      5. associate-*l*2.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{re \cdot \left(re \cdot -0.5\right)}\right)} - 1\right) \]
    5. Applied egg-rr2.0%

      \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)} - 1\right)} \]
    6. Step-by-step derivation
      1. expm1-def2.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)\right)} \]
      2. expm1-log1p11.0%

        \[\leadsto 1 + \color{blue}{re \cdot \left(re \cdot -0.5\right)} \]
    7. Simplified11.0%

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

    if 4.30000000000000013e73 < 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 97.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. Simplified97.9%

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

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

        \[\leadsto \color{blue}{\left(0.041666666666666664 \cdot \cos re\right) \cdot {im}^{4}} \]
      2. *-commutative97.9%

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

        \[\leadsto \color{blue}{\cos re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)} \]
    6. Simplified97.9%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)} \]
    10. Taylor expanded in re around 0 66.2%

      \[\leadsto {im}^{4} \cdot \color{blue}{0.041666666666666664} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 250:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 4.3 \cdot 10^{+73}:\\ \;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664\\ \end{array} \]

Alternative 12: 61.4% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 250:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 5.8 \cdot 10^{+150}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\

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


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

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

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

    if 250 < im < 5.80000000000000022e150

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 9.7%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u1.8%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)\right)} \]
      2. expm1-udef1.8%

        \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)} - 1\right)} \]
      3. *-commutative1.8%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{{re}^{2} \cdot -0.5}\right)} - 1\right) \]
      4. unpow21.8%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(re \cdot re\right)} \cdot -0.5\right)} - 1\right) \]
      5. associate-*l*1.8%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{re \cdot \left(re \cdot -0.5\right)}\right)} - 1\right) \]
    5. Applied egg-rr1.8%

      \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)} - 1\right)} \]
    6. Step-by-step derivation
      1. expm1-def1.8%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)\right)} \]
      2. expm1-log1p9.7%

        \[\leadsto 1 + \color{blue}{re \cdot \left(re \cdot -0.5\right)} \]
    7. Simplified9.7%

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

    if 5.80000000000000022e150 < 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 96.5%

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot {im}^{2}} \]
      2. metadata-eval60.5%

        \[\leadsto \color{blue}{1} + 0.5 \cdot {im}^{2} \]
      3. unpow260.5%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    6. Simplified60.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 250:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 5.8 \cdot 10^{+150}:\\ \;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 13: 47.1% accurate, 27.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.4 \cdot 10^{+157} \lor \neg \left(re \leq 5.3 \cdot 10^{+247}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 3.39999999999999979e157 or 5.3000000000000002e247 < 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 75.7%

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot {im}^{2}} \]
      2. metadata-eval52.5%

        \[\leadsto \color{blue}{1} + 0.5 \cdot {im}^{2} \]
      3. unpow252.5%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    6. Simplified52.5%

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

    if 3.39999999999999979e157 < re < 5.3000000000000002e247

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 39.3%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. expm1-log1p-u0.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)\right)} \]
      2. expm1-udef0.0%

        \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(-0.5 \cdot {re}^{2}\right)} - 1\right)} \]
      3. *-commutative0.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{{re}^{2} \cdot -0.5}\right)} - 1\right) \]
      4. unpow20.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(re \cdot re\right)} \cdot -0.5\right)} - 1\right) \]
      5. associate-*l*0.0%

        \[\leadsto 1 + \left(e^{\mathsf{log1p}\left(\color{blue}{re \cdot \left(re \cdot -0.5\right)}\right)} - 1\right) \]
    5. Applied egg-rr0.0%

      \[\leadsto 1 + \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)} - 1\right)} \]
    6. Step-by-step derivation
      1. expm1-def0.0%

        \[\leadsto 1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(re \cdot -0.5\right)\right)\right)} \]
      2. expm1-log1p39.3%

        \[\leadsto 1 + \color{blue}{re \cdot \left(re \cdot -0.5\right)} \]
    7. Simplified39.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 3.4 \cdot 10^{+157} \lor \neg \left(re \leq 5.3 \cdot 10^{+247}\right):\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\ \end{array} \]

Alternative 14: 46.8% accurate, 44.0× speedup?

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

\\
1 + 0.5 \cdot \left(im \cdot im\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot {im}^{2}} \]
    2. metadata-eval50.5%

      \[\leadsto \color{blue}{1} + 0.5 \cdot {im}^{2} \]
    3. unpow250.5%

      \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  6. Simplified50.5%

    \[\leadsto \color{blue}{1 + 0.5 \cdot \left(im \cdot im\right)} \]
  7. Final simplification50.5%

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

Alternative 15: 28.3% 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 56.3%

    \[\leadsto \color{blue}{\cos re} \]
  3. Taylor expanded in re around 0 35.7%

    \[\leadsto \color{blue}{1} \]
  4. Final simplification35.7%

    \[\leadsto 1 \]

Reproduce

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