math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 11.9s
Alternatives: 26
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 26 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} \\ \cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (cos re) (+ (* 0.5 (/ 1.0 (exp im))) (* 0.5 (exp im)))))
double code(double re, double im) {
	return cos(re) * ((0.5 * (1.0 / exp(im))) + (0.5 * exp(im)));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = cos(re) * ((0.5d0 * (1.0d0 / exp(im))) + (0.5d0 * exp(im)))
end function
public static double code(double re, double im) {
	return Math.cos(re) * ((0.5 * (1.0 / Math.exp(im))) + (0.5 * Math.exp(im)));
}
def code(re, im):
	return math.cos(re) * ((0.5 * (1.0 / math.exp(im))) + (0.5 * math.exp(im)))
function code(re, im)
	return Float64(cos(re) * Float64(Float64(0.5 * Float64(1.0 / exp(im))) + Float64(0.5 * exp(im))))
end
function tmp = code(re, im)
	tmp = cos(re) * ((0.5 * (1.0 / exp(im))) + (0.5 * exp(im)));
end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(1.0 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
  5. Final simplification100.0%

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

Alternative 2: 93.7% accurate, 1.0× speedup?

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

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

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


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

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

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

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

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

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

    if 0.99999850000000001 < (cos.f64 re)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos re \leq 0.9999985:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\\ \end{array} \]

Alternative 3: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 4: 94.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

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

\mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot e^{im} + -1\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.14999999999999997e77 < im < -3.1e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp80.0%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*80.0%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 3.39999999999999991

    1. Initial program 100.0%

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

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

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

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

    if 3.39999999999999991 < im < 1.14999999999999997e77

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr83.3%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 83.3%

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

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

Alternative 5: 96.4% accurate, 1.4× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.14999999999999997e77 or 9.99999999999999983e76 < im

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.14999999999999997e77 < im < -0.0184999999999999991

    1. Initial program 99.7%

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

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

    if -0.0184999999999999991 < im < 3.89999999999999991

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

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

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

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

    if 3.89999999999999991 < im < 9.99999999999999983e76

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr83.3%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 83.3%

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

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

Alternative 6: 98.1% accurate, 1.4× speedup?

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

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.14999999999999997e77 < im < -0.0529999999999999985

    1. Initial program 99.7%

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

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

    if -0.0529999999999999985 < im < 1.30000000000000004

    1. Initial program 100.0%

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

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

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

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

    if 1.30000000000000004 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
    5. Applied egg-rr99.2%

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

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

Alternative 7: 98.1% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;im \leq -0.014:\\
\;\;\;\;0.5 \cdot \frac{1}{e^{im}} + t_0\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.14999999999999997e77 < im < -0.0140000000000000003

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]

    if -0.0140000000000000003 < im < 1.30000000000000004

    1. Initial program 100.0%

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

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

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

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

    if 1.30000000000000004 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
    5. Applied egg-rr99.2%

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

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

Alternative 8: 90.5% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{if}\;im \leq -3.1 \cdot 10^{+181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.25 \cdot 10^{+76}:\\ \;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.9:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + -1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (* (cos re) (* 0.5 im)))))
   (if (<= im -3.1e+181)
     t_0
     (if (<= im -1.25e+76)
       (*
        (pow im 4.0)
        (+ 0.041666666666666664 (* (* re re) -0.020833333333333332)))
       (if (<= im -31000000.0)
         (pow re -512.0)
         (if (<= im 2.9)
           (* (* (cos re) 0.5) (+ 2.0 (* im im)))
           (if (<= im 1.9e+154) (+ (* 0.5 (exp im)) -1.0) t_0)))))))
double code(double re, double im) {
	double t_0 = im * (cos(re) * (0.5 * im));
	double tmp;
	if (im <= -3.1e+181) {
		tmp = t_0;
	} else if (im <= -1.25e+76) {
		tmp = pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332));
	} else if (im <= -31000000.0) {
		tmp = pow(re, -512.0);
	} else if (im <= 2.9) {
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.9e+154) {
		tmp = (0.5 * exp(im)) + -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = im * (cos(re) * (0.5d0 * im))
    if (im <= (-3.1d+181)) then
        tmp = t_0
    else if (im <= (-1.25d+76)) then
        tmp = (im ** 4.0d0) * (0.041666666666666664d0 + ((re * re) * (-0.020833333333333332d0)))
    else if (im <= (-31000000.0d0)) then
        tmp = re ** (-512.0d0)
    else if (im <= 2.9d0) then
        tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
    else if (im <= 1.9d+154) then
        tmp = (0.5d0 * exp(im)) + (-1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = im * (Math.cos(re) * (0.5 * im));
	double tmp;
	if (im <= -3.1e+181) {
		tmp = t_0;
	} else if (im <= -1.25e+76) {
		tmp = Math.pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332));
	} else if (im <= -31000000.0) {
		tmp = Math.pow(re, -512.0);
	} else if (im <= 2.9) {
		tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
	} else if (im <= 1.9e+154) {
		tmp = (0.5 * Math.exp(im)) + -1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (math.cos(re) * (0.5 * im))
	tmp = 0
	if im <= -3.1e+181:
		tmp = t_0
	elif im <= -1.25e+76:
		tmp = math.pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332))
	elif im <= -31000000.0:
		tmp = math.pow(re, -512.0)
	elif im <= 2.9:
		tmp = (math.cos(re) * 0.5) * (2.0 + (im * im))
	elif im <= 1.9e+154:
		tmp = (0.5 * math.exp(im)) + -1.0
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(cos(re) * Float64(0.5 * im)))
	tmp = 0.0
	if (im <= -3.1e+181)
		tmp = t_0;
	elseif (im <= -1.25e+76)
		tmp = Float64((im ^ 4.0) * Float64(0.041666666666666664 + Float64(Float64(re * re) * -0.020833333333333332)));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.9)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im)));
	elseif (im <= 1.9e+154)
		tmp = Float64(Float64(0.5 * exp(im)) + -1.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (cos(re) * (0.5 * im));
	tmp = 0.0;
	if (im <= -3.1e+181)
		tmp = t_0;
	elseif (im <= -1.25e+76)
		tmp = (im ^ 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.9)
		tmp = (cos(re) * 0.5) * (2.0 + (im * im));
	elseif (im <= 1.9e+154)
		tmp = (0.5 * exp(im)) + -1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(N[Cos[re], $MachinePrecision] * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -3.1e+181], t$95$0, If[LessEqual[im, -1.25e+76], N[(N[Power[im, 4.0], $MachinePrecision] * N[(0.041666666666666664 + N[(N[(re * re), $MachinePrecision] * -0.020833333333333332), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -31000000.0], N[Power[re, -512.0], $MachinePrecision], If[LessEqual[im, 2.9], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.9e+154], N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

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

\mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if im < -3.09999999999999989e181 or 1.8999999999999999e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.09999999999999989e181 < im < -1.24999999999999998e76

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.24999999999999998e76 < im < -3.1e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp80.0%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*80.0%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 2.89999999999999991

    1. Initial program 100.0%

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

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

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

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

    if 2.89999999999999991 < im < 1.8999999999999999e154

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr78.2%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 78.2%

      \[\leadsto \color{blue}{0.5 \cdot e^{im} - 1} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification94.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.1 \cdot 10^{+181}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -1.25 \cdot 10^{+76}:\\ \;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.9:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + -1\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 9: 88.4% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

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

\mathbf{elif}\;im \leq 2.05 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -6.1999999999999998e176 or 2.05e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.1999999999999998e176 < im < -3.1e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp88.2%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*88.2%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 1.94999999999999996

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.94999999999999996 < im < 2.05e154

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr78.2%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 78.2%

      \[\leadsto \color{blue}{0.5 \cdot e^{im} - 1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.2 \cdot 10^{+176}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 1.95:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 2.05 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + -1\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 10: 88.7% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

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

\mathbf{elif}\;im \leq 2.7 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot e^{im} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -6.1999999999999998e176 or 2.70000000000000006e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.1999999999999998e176 < im < -3.1e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp88.2%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*88.2%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 4.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 97.7%

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

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

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

    if 4.5 < im < 2.70000000000000006e154

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr78.2%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 78.2%

      \[\leadsto \color{blue}{0.5 \cdot e^{im} - 1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.2 \cdot 10^{+176}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 4.5:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 2.7 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot e^{im} + -1\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 11: 80.4% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -3.15 \cdot 10^{+128}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.26 \cdot 10^{+77}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -3.15e+128)
   (* (* im im) (+ 0.5 (* re (* re -0.25))))
   (if (<= im -31000000.0)
     (pow re -512.0)
     (if (<= im 2.1e+21)
       (cos re)
       (if (<= im 1.26e+77)
         (pow re -512.0)
         (* (pow im 4.0) 0.041666666666666664))))))
double code(double re, double im) {
	double tmp;
	if (im <= -3.15e+128) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else if (im <= -31000000.0) {
		tmp = pow(re, -512.0);
	} else if (im <= 2.1e+21) {
		tmp = cos(re);
	} else if (im <= 1.26e+77) {
		tmp = pow(re, -512.0);
	} 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 <= (-3.15d+128)) then
        tmp = (im * im) * (0.5d0 + (re * (re * (-0.25d0))))
    else if (im <= (-31000000.0d0)) then
        tmp = re ** (-512.0d0)
    else if (im <= 2.1d+21) then
        tmp = cos(re)
    else if (im <= 1.26d+77) then
        tmp = re ** (-512.0d0)
    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 <= -3.15e+128) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else if (im <= -31000000.0) {
		tmp = Math.pow(re, -512.0);
	} else if (im <= 2.1e+21) {
		tmp = Math.cos(re);
	} else if (im <= 1.26e+77) {
		tmp = Math.pow(re, -512.0);
	} else {
		tmp = Math.pow(im, 4.0) * 0.041666666666666664;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -3.15e+128:
		tmp = (im * im) * (0.5 + (re * (re * -0.25)))
	elif im <= -31000000.0:
		tmp = math.pow(re, -512.0)
	elif im <= 2.1e+21:
		tmp = math.cos(re)
	elif im <= 1.26e+77:
		tmp = math.pow(re, -512.0)
	else:
		tmp = math.pow(im, 4.0) * 0.041666666666666664
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -3.15e+128)
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(re * Float64(re * -0.25))));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.1e+21)
		tmp = cos(re);
	elseif (im <= 1.26e+77)
		tmp = re ^ -512.0;
	else
		tmp = Float64((im ^ 4.0) * 0.041666666666666664);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -3.15e+128)
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.1e+21)
		tmp = cos(re);
	elseif (im <= 1.26e+77)
		tmp = re ^ -512.0;
	else
		tmp = (im ^ 4.0) * 0.041666666666666664;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -3.15e+128], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -31000000.0], N[Power[re, -512.0], $MachinePrecision], If[LessEqual[im, 2.1e+21], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.26e+77], N[Power[re, -512.0], $MachinePrecision], N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

\mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.26 \cdot 10^{+77}:\\
\;\;\;\;{re}^{-512}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.1499999999999999e128 < im < -3.1e7 or 2.1e21 < im < 1.25999999999999998e77

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(\left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} \]
      7. distribute-rgt-out83.3%

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

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*83.3%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 2.1e21

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.25999999999999998e77 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.15 \cdot 10^{+128}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.26 \cdot 10^{+77}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664\\ \end{array} \]

Alternative 12: 82.6% accurate, 2.8× speedup?

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

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9999999999999998e131 < im < -3.1e7

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp87.0%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*87.0%

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

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

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 2.5

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr81.6%

      \[\leadsto 0.5 \cdot \color{blue}{-2} + 0.5 \cdot e^{im} \]
    6. Taylor expanded in im around inf 81.6%

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

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

Alternative 13: 79.4% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.7 \cdot 10^{+131}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.26 \cdot 10^{+131}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;-0.5 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.7e+131)
   (* (* im im) (+ 0.5 (* re (* re -0.25))))
   (if (<= im -31000000.0)
     (pow re -512.0)
     (if (<= im 2.1e+21)
       (cos re)
       (if (<= im 1.26e+131)
         (pow re -512.0)
         (+
          -0.5
          (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333)))))))))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.7e+131) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else if (im <= -31000000.0) {
		tmp = pow(re, -512.0);
	} else if (im <= 2.1e+21) {
		tmp = cos(re);
	} else if (im <= 1.26e+131) {
		tmp = pow(re, -512.0);
	} else {
		tmp = -0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= (-1.7d+131)) then
        tmp = (im * im) * (0.5d0 + (re * (re * (-0.25d0))))
    else if (im <= (-31000000.0d0)) then
        tmp = re ** (-512.0d0)
    else if (im <= 2.1d+21) then
        tmp = cos(re)
    else if (im <= 1.26d+131) then
        tmp = re ** (-512.0d0)
    else
        tmp = (-0.5d0) + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0)))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.7e+131) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else if (im <= -31000000.0) {
		tmp = Math.pow(re, -512.0);
	} else if (im <= 2.1e+21) {
		tmp = Math.cos(re);
	} else if (im <= 1.26e+131) {
		tmp = Math.pow(re, -512.0);
	} else {
		tmp = -0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -1.7e+131:
		tmp = (im * im) * (0.5 + (re * (re * -0.25)))
	elif im <= -31000000.0:
		tmp = math.pow(re, -512.0)
	elif im <= 2.1e+21:
		tmp = math.cos(re)
	elif im <= 1.26e+131:
		tmp = math.pow(re, -512.0)
	else:
		tmp = -0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -1.7e+131)
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(re * Float64(re * -0.25))));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.1e+21)
		tmp = cos(re);
	elseif (im <= 1.26e+131)
		tmp = re ^ -512.0;
	else
		tmp = Float64(-0.5 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333))))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -1.7e+131)
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	elseif (im <= -31000000.0)
		tmp = re ^ -512.0;
	elseif (im <= 2.1e+21)
		tmp = cos(re);
	elseif (im <= 1.26e+131)
		tmp = re ^ -512.0;
	else
		tmp = -0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -1.7e+131], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -31000000.0], N[Power[re, -512.0], $MachinePrecision], If[LessEqual[im, 2.1e+21], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.26e+131], N[Power[re, -512.0], $MachinePrecision], N[(-0.5 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -31000000:\\
\;\;\;\;{re}^{-512}\\

\mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.26 \cdot 10^{+131}:\\
\;\;\;\;{re}^{-512}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.69999999999999993e131 < im < -3.1e7 or 2.1e21 < im < 1.26e131

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp82.1%

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

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

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

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

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*82.1%

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

      \[\leadsto \color{blue}{\left(e^{im} + e^{-im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    8. Applied egg-rr62.1%

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -3.1e7 < im < 2.1e21

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.26e131 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr84.6%

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

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

        \[\leadsto \color{blue}{\left(0.25 \cdot {im}^{2} + \left(0.5 \cdot im + 0.08333333333333333 \cdot {im}^{3}\right)\right) + \left(-0.5\right)} \]
      2. metadata-eval84.6%

        \[\leadsto \left(0.25 \cdot {im}^{2} + \left(0.5 \cdot im + 0.08333333333333333 \cdot {im}^{3}\right)\right) + \color{blue}{-0.5} \]
      3. +-commutative84.6%

        \[\leadsto \color{blue}{-0.5 + \left(0.25 \cdot {im}^{2} + \left(0.5 \cdot im + 0.08333333333333333 \cdot {im}^{3}\right)\right)} \]
      4. +-commutative84.6%

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

        \[\leadsto -0.5 + \color{blue}{\left(0.5 \cdot im + \left(0.08333333333333333 \cdot {im}^{3} + 0.25 \cdot {im}^{2}\right)\right)} \]
      6. *-commutative84.6%

        \[\leadsto -0.5 + \left(\color{blue}{im \cdot 0.5} + \left(0.08333333333333333 \cdot {im}^{3} + 0.25 \cdot {im}^{2}\right)\right) \]
      7. *-commutative84.6%

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

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\color{blue}{\left(im \cdot \left(im \cdot im\right)\right)} \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      9. unpow284.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\left(im \cdot \color{blue}{{im}^{2}}\right) \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      10. associate-*l*84.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\color{blue}{im \cdot \left({im}^{2} \cdot 0.08333333333333333\right)} + 0.25 \cdot {im}^{2}\right)\right) \]
      11. *-commutative84.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{{im}^{2} \cdot 0.25}\right)\right) \]
      12. unpow284.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{\left(im \cdot im\right)} \cdot 0.25\right)\right) \]
      13. associate-*l*84.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{im \cdot \left(im \cdot 0.25\right)}\right)\right) \]
      14. distribute-lft-out84.6%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \color{blue}{im \cdot \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)}\right) \]
      15. distribute-lft-out84.6%

        \[\leadsto -0.5 + \color{blue}{im \cdot \left(0.5 + \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right)} \]
      16. unpow284.6%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right) \]
      17. associate-*l*84.6%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{im \cdot \left(im \cdot 0.08333333333333333\right)} + im \cdot 0.25\right)\right) \]
      18. distribute-lft-out84.6%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \color{blue}{im \cdot \left(im \cdot 0.08333333333333333 + 0.25\right)}\right) \]
      19. +-commutative84.6%

        \[\leadsto -0.5 + im \cdot \left(0.5 + im \cdot \color{blue}{\left(0.25 + im \cdot 0.08333333333333333\right)}\right) \]
    8. Simplified84.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.7 \cdot 10^{+131}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq -31000000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.26 \cdot 10^{+131}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;-0.5 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\\ \end{array} \]

Alternative 14: 72.9% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;im \leq 3.3 \cdot 10^{+27}:\\
\;\;\;\;\cos re\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5999999999999994e42 < im < 3.2999999999999998e27

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.2999999999999998e27 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr83.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\color{blue}{\left(im \cdot \left(im \cdot im\right)\right)} \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      9. unpow264.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\left(im \cdot \color{blue}{{im}^{2}}\right) \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      10. associate-*l*64.8%

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

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{{im}^{2} \cdot 0.25}\right)\right) \]
      12. unpow264.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{\left(im \cdot im\right)} \cdot 0.25\right)\right) \]
      13. associate-*l*64.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{im \cdot \left(im \cdot 0.25\right)}\right)\right) \]
      14. distribute-lft-out64.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \color{blue}{im \cdot \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)}\right) \]
      15. distribute-lft-out64.8%

        \[\leadsto -0.5 + \color{blue}{im \cdot \left(0.5 + \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right)} \]
      16. unpow264.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right) \]
      17. associate-*l*64.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{im \cdot \left(im \cdot 0.08333333333333333\right)} + im \cdot 0.25\right)\right) \]
      18. distribute-lft-out64.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \color{blue}{im \cdot \left(im \cdot 0.08333333333333333 + 0.25\right)}\right) \]
      19. +-commutative64.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -9.6 \cdot 10^{+42}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq 3.3 \cdot 10^{+27}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;-0.5 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\\ \end{array} \]

Alternative 15: 49.8% accurate, 17.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -7.5 \cdot 10^{+42} \lor \neg \left(im \leq 1.96 \cdot 10^{+87}\right) \land im \leq 4 \cdot 10^{+175}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -7.5e+42) (and (not (<= im 1.96e+87)) (<= im 4e+175)))
   (* (* im im) (+ 0.5 (* re (* re -0.25))))
   (* 0.5 (+ 2.0 (* im im)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -7.5e+42) || (!(im <= 1.96e+87) && (im <= 4e+175))) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else {
		tmp = 0.5 * (2.0 + (im * im));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-7.5d+42)) .or. (.not. (im <= 1.96d+87)) .and. (im <= 4d+175)) then
        tmp = (im * im) * (0.5d0 + (re * (re * (-0.25d0))))
    else
        tmp = 0.5d0 * (2.0d0 + (im * im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -7.5e+42) || (!(im <= 1.96e+87) && (im <= 4e+175))) {
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	} else {
		tmp = 0.5 * (2.0 + (im * im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -7.5e+42) or (not (im <= 1.96e+87) and (im <= 4e+175)):
		tmp = (im * im) * (0.5 + (re * (re * -0.25)))
	else:
		tmp = 0.5 * (2.0 + (im * im))
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -7.5e+42) || (!(im <= 1.96e+87) && (im <= 4e+175)))
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(re * Float64(re * -0.25))));
	else
		tmp = Float64(0.5 * Float64(2.0 + Float64(im * im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -7.5e+42) || (~((im <= 1.96e+87)) && (im <= 4e+175)))
		tmp = (im * im) * (0.5 + (re * (re * -0.25)));
	else
		tmp = 0.5 * (2.0 + (im * im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -7.5e+42], And[N[Not[LessEqual[im, 1.96e+87]], $MachinePrecision], LessEqual[im, 4e+175]]], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -7.5 \cdot 10^{+42} \lor \neg \left(im \leq 1.96 \cdot 10^{+87}\right) \land im \leq 4 \cdot 10^{+175}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -7.50000000000000041e42 or 1.96e87 < im < 3.9999999999999997e175

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.50000000000000041e42 < im < 1.96e87 or 3.9999999999999997e175 < im

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -7.5 \cdot 10^{+42} \lor \neg \left(im \leq 1.96 \cdot 10^{+87}\right) \land im \leq 4 \cdot 10^{+175}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \end{array} \]

Alternative 16: 51.2% accurate, 18.0× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.50000000000000041e42 < im < 3

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

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

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

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

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

    if 3 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}} \]
    5. Applied egg-rr81.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\color{blue}{\left(im \cdot \left(im \cdot im\right)\right)} \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      9. unpow261.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(\left(im \cdot \color{blue}{{im}^{2}}\right) \cdot 0.08333333333333333 + 0.25 \cdot {im}^{2}\right)\right) \]
      10. associate-*l*61.8%

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

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{{im}^{2} \cdot 0.25}\right)\right) \]
      12. unpow261.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{\left(im \cdot im\right)} \cdot 0.25\right)\right) \]
      13. associate-*l*61.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \left(im \cdot \left({im}^{2} \cdot 0.08333333333333333\right) + \color{blue}{im \cdot \left(im \cdot 0.25\right)}\right)\right) \]
      14. distribute-lft-out61.8%

        \[\leadsto -0.5 + \left(im \cdot 0.5 + \color{blue}{im \cdot \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)}\right) \]
      15. distribute-lft-out61.8%

        \[\leadsto -0.5 + \color{blue}{im \cdot \left(0.5 + \left({im}^{2} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right)} \]
      16. unpow261.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.08333333333333333 + im \cdot 0.25\right)\right) \]
      17. associate-*l*61.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \left(\color{blue}{im \cdot \left(im \cdot 0.08333333333333333\right)} + im \cdot 0.25\right)\right) \]
      18. distribute-lft-out61.8%

        \[\leadsto -0.5 + im \cdot \left(0.5 + \color{blue}{im \cdot \left(im \cdot 0.08333333333333333 + 0.25\right)}\right) \]
      19. +-commutative61.8%

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

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

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

Alternative 17: 49.4% accurate, 20.3× speedup?

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

\\
\begin{array}{l}
t_0 := -0.25 \cdot \left(im \cdot \left(re \cdot \left(re \cdot im\right)\right)\right)\\
\mathbf{if}\;re \leq -4.85 \cdot 10^{+27}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;re \leq 3.2 \cdot 10^{+95}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;re \leq 1.5 \cdot 10^{+191}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;re \cdot re - re\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -4.8500000000000001e27 or 3.2000000000000001e95 < re < 1.4999999999999999e191

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.25 \cdot \left(im \cdot \left(re \cdot \left(re \cdot im\right)\right)\right)} \]

    if -4.8500000000000001e27 < re < 3.2000000000000001e95

    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 91.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + e^{-im}\right)} \]
    3. Taylor expanded in im around 0 71.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    4. Step-by-step derivation
      1. unpow271.0%

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    5. Simplified71.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(2 + im \cdot im\right)} \]

    if 1.4999999999999999e191 < re

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{-im} + e^{im}\right) \]
      2. associate-*l*100.0%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{-im} + e^{im}\right)\right)} \]
      3. +-commutative100.0%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{im} + e^{-im}\right)}\right) \]
      4. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(e^{im} \cdot 0.5 + e^{-im} \cdot 0.5\right)} \]
      7. *-commutative100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{0.5 \cdot e^{im}} + e^{-im} \cdot 0.5\right) \]
      8. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 100.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
    5. Taylor expanded in re around 0 0.9%

      \[\leadsto \color{blue}{-0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) + \left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
    6. Step-by-step derivation
      1. +-commutative0.9%

        \[\leadsto \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right) + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right)} \]
      2. distribute-lft-out0.9%

        \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) \]
      3. associate-*r*0.9%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(-0.5 \cdot {re}^{2}\right) \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
      4. +-commutative0.9%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
      5. distribute-lft-out0.9%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)\right)} \]
      6. associate-*r*0.9%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(\left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} \]
      7. distribute-rgt-out12.5%

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp12.5%

        \[\leadsto \left(e^{im} + \color{blue}{e^{-im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \]
      9. *-commutative12.5%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left({re}^{2} \cdot -0.5\right)} \cdot 0.5\right) \]
      10. associate-*l*12.5%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{{re}^{2} \cdot \left(-0.5 \cdot 0.5\right)}\right) \]
      11. metadata-eval12.5%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + {re}^{2} \cdot \color{blue}{-0.25}\right) \]
      12. unpow212.5%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*12.5%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    7. Simplified12.5%

      \[\leadsto \color{blue}{\left(e^{im} + e^{-im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    8. Applied egg-rr35.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, re, -re\right)} \]
    9. Step-by-step derivation
      1. fma-neg35.7%

        \[\leadsto \color{blue}{re \cdot re - re} \]
    10. Simplified35.7%

      \[\leadsto \color{blue}{re \cdot re - re} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification55.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.85 \cdot 10^{+27}:\\ \;\;\;\;-0.25 \cdot \left(im \cdot \left(re \cdot \left(re \cdot im\right)\right)\right)\\ \mathbf{elif}\;re \leq 3.2 \cdot 10^{+95}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;re \leq 1.5 \cdot 10^{+191}:\\ \;\;\;\;-0.25 \cdot \left(im \cdot \left(re \cdot \left(re \cdot im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot re - re\\ \end{array} \]

Alternative 18: 46.4% accurate, 33.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.2 \lor \neg \left(im \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -0.2) (not (<= im 1.4))) (* 0.5 (* im im)) 1.0))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.2) || !(im <= 1.4)) {
		tmp = 0.5 * (im * im);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-0.2d0)) .or. (.not. (im <= 1.4d0))) then
        tmp = 0.5d0 * (im * im)
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -0.2) || !(im <= 1.4)) {
		tmp = 0.5 * (im * im);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -0.2) or not (im <= 1.4):
		tmp = 0.5 * (im * im)
	else:
		tmp = 1.0
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -0.2) || !(im <= 1.4))
		tmp = Float64(0.5 * Float64(im * im));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -0.2) || ~((im <= 1.4)))
		tmp = 0.5 * (im * im);
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -0.2], N[Not[LessEqual[im, 1.4]], $MachinePrecision]], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.2 \lor \neg \left(im \leq 1.4\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -0.20000000000000001 or 1.3999999999999999 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in im around 0 53.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    3. Step-by-step derivation
      1. unpow253.4%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    4. Simplified53.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
    5. Taylor expanded in im around inf 53.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. *-commutative53.2%

        \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
      2. associate-*r*53.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
      3. *-commutative53.2%

        \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
      4. unpow253.2%

        \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
      5. associate-*l*52.5%

        \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
    7. Simplified52.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
    8. Taylor expanded in re around 0 42.3%

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
    9. Step-by-step derivation
      1. unpow242.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    10. Simplified42.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]

    if -0.20000000000000001 < im < 1.3999999999999999

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Taylor expanded in re around 0 57.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + e^{-im}\right)} \]
    3. Taylor expanded in im around 0 56.8%

      \[\leadsto 0.5 \cdot \color{blue}{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -0.2 \lor \neg \left(im \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 19: 47.3% accurate, 33.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 8 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{+242}:\\ \;\;\;\;-512 - re \cdot re\\ \mathbf{else}:\\ \;\;\;\;re \cdot re - re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re 8e+157)
   (* 0.5 (+ 2.0 (* im im)))
   (if (<= re 1.1e+242) (- -512.0 (* re re)) (- (* re re) re))))
double code(double re, double im) {
	double tmp;
	if (re <= 8e+157) {
		tmp = 0.5 * (2.0 + (im * im));
	} else if (re <= 1.1e+242) {
		tmp = -512.0 - (re * re);
	} else {
		tmp = (re * re) - re;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= 8d+157) then
        tmp = 0.5d0 * (2.0d0 + (im * im))
    else if (re <= 1.1d+242) then
        tmp = (-512.0d0) - (re * re)
    else
        tmp = (re * re) - re
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= 8e+157) {
		tmp = 0.5 * (2.0 + (im * im));
	} else if (re <= 1.1e+242) {
		tmp = -512.0 - (re * re);
	} else {
		tmp = (re * re) - re;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= 8e+157:
		tmp = 0.5 * (2.0 + (im * im))
	elif re <= 1.1e+242:
		tmp = -512.0 - (re * re)
	else:
		tmp = (re * re) - re
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= 8e+157)
		tmp = Float64(0.5 * Float64(2.0 + Float64(im * im)));
	elseif (re <= 1.1e+242)
		tmp = Float64(-512.0 - Float64(re * re));
	else
		tmp = Float64(Float64(re * re) - re);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= 8e+157)
		tmp = 0.5 * (2.0 + (im * im));
	elseif (re <= 1.1e+242)
		tmp = -512.0 - (re * re);
	else
		tmp = (re * re) - re;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, 8e+157], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e+242], N[(-512.0 - N[(re * re), $MachinePrecision]), $MachinePrecision], N[(N[(re * re), $MachinePrecision] - re), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq 8 \cdot 10^{+157}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\

\mathbf{elif}\;re \leq 1.1 \cdot 10^{+242}:\\
\;\;\;\;-512 - re \cdot re\\

\mathbf{else}:\\
\;\;\;\;re \cdot re - re\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < 7.99999999999999987e157

    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 72.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + e^{-im}\right)} \]
    3. Taylor expanded in im around 0 55.6%

      \[\leadsto 0.5 \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    4. Step-by-step derivation
      1. unpow255.6%

        \[\leadsto 0.5 \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
    5. Simplified55.6%

      \[\leadsto 0.5 \cdot \color{blue}{\left(2 + im \cdot im\right)} \]

    if 7.99999999999999987e157 < re < 1.1e242

    1. Initial program 99.9%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{-im} + e^{im}\right) \]
      2. associate-*l*99.9%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{-im} + e^{im}\right)\right)} \]
      3. +-commutative99.9%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{im} + e^{-im}\right)}\right) \]
      4. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in99.9%

        \[\leadsto \cos re \cdot \color{blue}{\left(e^{im} \cdot 0.5 + e^{-im} \cdot 0.5\right)} \]
      7. *-commutative99.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{0.5 \cdot e^{im}} + e^{-im} \cdot 0.5\right) \]
      8. fma-def99.9%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 100.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
    5. Taylor expanded in re around 0 1.2%

      \[\leadsto \color{blue}{-0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) + \left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
    6. Step-by-step derivation
      1. +-commutative1.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right) + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right)} \]
      2. distribute-lft-out1.2%

        \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) \]
      3. associate-*r*1.2%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(-0.5 \cdot {re}^{2}\right) \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
      4. +-commutative1.2%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
      5. distribute-lft-out1.2%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)\right)} \]
      6. associate-*r*1.2%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(\left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} \]
      7. distribute-rgt-out31.2%

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp31.2%

        \[\leadsto \left(e^{im} + \color{blue}{e^{-im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \]
      9. *-commutative31.2%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left({re}^{2} \cdot -0.5\right)} \cdot 0.5\right) \]
      10. associate-*l*31.2%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{{re}^{2} \cdot \left(-0.5 \cdot 0.5\right)}\right) \]
      11. metadata-eval31.2%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + {re}^{2} \cdot \color{blue}{-0.25}\right) \]
      12. unpow231.2%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*31.2%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    7. Simplified31.2%

      \[\leadsto \color{blue}{\left(e^{im} + e^{-im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    8. Applied egg-rr31.2%

      \[\leadsto \color{blue}{-512 + \left(-re\right) \cdot re} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv31.2%

        \[\leadsto \color{blue}{-512 - re \cdot re} \]
    10. Simplified31.2%

      \[\leadsto \color{blue}{-512 - re \cdot re} \]

    if 1.1e242 < re

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{-im} + e^{im}\right) \]
      2. associate-*l*100.0%

        \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{-im} + e^{im}\right)\right)} \]
      3. +-commutative100.0%

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{im} + e^{-im}\right)}\right) \]
      4. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(e^{im} \cdot 0.5 + e^{-im} \cdot 0.5\right)} \]
      7. *-commutative100.0%

        \[\leadsto \cos re \cdot \left(\color{blue}{0.5 \cdot e^{im}} + e^{-im} \cdot 0.5\right) \]
      8. fma-def100.0%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Taylor expanded in re around inf 100.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
    5. Taylor expanded in re around 0 1.1%

      \[\leadsto \color{blue}{-0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) + \left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
    6. Step-by-step derivation
      1. +-commutative1.1%

        \[\leadsto \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right) + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right)} \]
      2. distribute-lft-out1.1%

        \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} + -0.5 \cdot \left({re}^{2} \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)\right) \]
      3. associate-*r*1.1%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(-0.5 \cdot {re}^{2}\right) \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 0.5 \cdot e^{im}\right)} \]
      4. +-commutative1.1%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
      5. distribute-lft-out1.1%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right)\right)} \]
      6. associate-*r*1.1%

        \[\leadsto 0.5 \cdot \left(e^{im} + \frac{1}{e^{im}}\right) + \color{blue}{\left(\left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \cdot \left(e^{im} + \frac{1}{e^{im}}\right)} \]
      7. distribute-rgt-out7.0%

        \[\leadsto \color{blue}{\left(e^{im} + \frac{1}{e^{im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right)} \]
      8. rec-exp7.0%

        \[\leadsto \left(e^{im} + \color{blue}{e^{-im}}\right) \cdot \left(0.5 + \left(-0.5 \cdot {re}^{2}\right) \cdot 0.5\right) \]
      9. *-commutative7.0%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left({re}^{2} \cdot -0.5\right)} \cdot 0.5\right) \]
      10. associate-*l*7.0%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{{re}^{2} \cdot \left(-0.5 \cdot 0.5\right)}\right) \]
      11. metadata-eval7.0%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + {re}^{2} \cdot \color{blue}{-0.25}\right) \]
      12. unpow27.0%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      13. associate-*l*7.0%

        \[\leadsto \left(e^{im} + e^{-im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    7. Simplified7.0%

      \[\leadsto \color{blue}{\left(e^{im} + e^{-im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    8. Applied egg-rr36.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, re, -re\right)} \]
    9. Step-by-step derivation
      1. fma-neg36.4%

        \[\leadsto \color{blue}{re \cdot re - re} \]
    10. Simplified36.4%

      \[\leadsto \color{blue}{re \cdot re - re} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 8 \cdot 10^{+157}:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;re \leq 1.1 \cdot 10^{+242}:\\ \;\;\;\;-512 - re \cdot re\\ \mathbf{else}:\\ \;\;\;\;re \cdot re - re\\ \end{array} \]

Alternative 20: 2.9% accurate, 308.0× speedup?

\[\begin{array}{l} \\ -512 \end{array} \]
(FPCore (re im) :precision binary64 -512.0)
double code(double re, double im) {
	return -512.0;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = -512.0d0
end function
public static double code(double re, double im) {
	return -512.0;
}
def code(re, im):
	return -512.0
function code(re, im)
	return -512.0
end
function tmp = code(re, im)
	tmp = -512.0;
end
code[re_, im_] := -512.0
\begin{array}{l}

\\
-512
\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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr3.1%

    \[\leadsto \color{blue}{-512} \]
  12. Final simplification3.1%

    \[\leadsto -512 \]

Alternative 21: 3.9% 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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr4.1%

    \[\leadsto \color{blue}{-1} \]
  12. Final simplification4.1%

    \[\leadsto -1 \]

Alternative 22: 6.9% accurate, 308.0× speedup?

\[\begin{array}{l} \\ 0.015625 \end{array} \]
(FPCore (re im) :precision binary64 0.015625)
double code(double re, double im) {
	return 0.015625;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.015625d0
end function
public static double code(double re, double im) {
	return 0.015625;
}
def code(re, im):
	return 0.015625
function code(re, im)
	return 0.015625
end
function tmp = code(re, im)
	tmp = 0.015625;
end
code[re_, im_] := 0.015625
\begin{array}{l}

\\
0.015625
\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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr7.5%

    \[\leadsto \color{blue}{0.015625} \]
  12. Final simplification7.5%

    \[\leadsto 0.015625 \]

Alternative 23: 7.6% accurate, 308.0× speedup?

\[\begin{array}{l} \\ 0.125 \end{array} \]
(FPCore (re im) :precision binary64 0.125)
double code(double re, double im) {
	return 0.125;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.125d0
end function
public static double code(double re, double im) {
	return 0.125;
}
def code(re, im):
	return 0.125
function code(re, im)
	return 0.125
end
function tmp = code(re, im)
	tmp = 0.125;
end
code[re_, im_] := 0.125
\begin{array}{l}

\\
0.125
\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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr8.1%

    \[\leadsto \color{blue}{0.125} \]
  12. Final simplification8.1%

    \[\leadsto 0.125 \]

Alternative 24: 7.9% accurate, 308.0× speedup?

\[\begin{array}{l} \\ 0.25 \end{array} \]
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
	return 0.25;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.25d0
end function
public static double code(double re, double im) {
	return 0.25;
}
def code(re, im):
	return 0.25
function code(re, im)
	return 0.25
end
function tmp = code(re, im)
	tmp = 0.25;
end
code[re_, im_] := 0.25
\begin{array}{l}

\\
0.25
\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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr8.5%

    \[\leadsto \color{blue}{0.25} \]
  12. Final simplification8.5%

    \[\leadsto 0.25 \]

Alternative 25: 9.0% accurate, 308.0× speedup?

\[\begin{array}{l} \\ 0.75 \end{array} \]
(FPCore (re im) :precision binary64 0.75)
double code(double re, double im) {
	return 0.75;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.75d0
end function
public static double code(double re, double im) {
	return 0.75;
}
def code(re, im):
	return 0.75
function code(re, im)
	return 0.75
end
function tmp = code(re, im)
	tmp = 0.75;
end
code[re_, im_] := 0.75
\begin{array}{l}

\\
0.75
\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 78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
  3. Step-by-step derivation
    1. unpow278.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right) \]
  4. Simplified78.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(2 + im \cdot im\right)} \]
  5. Taylor expanded in im around inf 26.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right)} \]
  6. Step-by-step derivation
    1. *-commutative26.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left({im}^{2} \cdot \cos re\right)} \]
    2. associate-*r*26.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
    3. *-commutative26.8%

      \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \cos re \]
    4. unpow226.8%

      \[\leadsto \left(\color{blue}{\left(im \cdot im\right)} \cdot 0.5\right) \cdot \cos re \]
    5. associate-*l*26.5%

      \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right)} \cdot \cos re \]
  7. Simplified26.5%

    \[\leadsto \color{blue}{\left(im \cdot \left(im \cdot 0.5\right)\right) \cdot \cos re} \]
  8. Taylor expanded in re around 0 21.5%

    \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} \]
  9. Step-by-step derivation
    1. unpow221.5%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
  10. Simplified21.5%

    \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
  11. Applied egg-rr9.7%

    \[\leadsto \color{blue}{0.75} \]
  12. Final simplification9.7%

    \[\leadsto 0.75 \]

Alternative 26: 28.1% 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 re around 0 66.4%

    \[\leadsto \color{blue}{0.5 \cdot \left(e^{im} + e^{-im}\right)} \]
  3. Taylor expanded in im around 0 31.9%

    \[\leadsto 0.5 \cdot \color{blue}{2} \]
  4. Final simplification31.9%

    \[\leadsto 1 \]

Reproduce

?
herbie shell --seed 2023182 
(FPCore (re im)
  :name "math.cos on complex, real part"
  :precision binary64
  (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))