math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 8.5s
Alternatives: 19
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 19 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 2: 95.3% accurate, 1.4× speedup?

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

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

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

\mathbf{elif}\;im \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -6.4999999999999999e97 or 1.1999999999999999e77 < im

    1. Initial program 100.0%

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

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

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

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

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

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

    if -6.4999999999999999e97 < im < -9.60000000000000024e-4 or 1.45000000000000012e-29 < im < 1.1999999999999999e77

    1. Initial program 100.0%

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

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

    if -9.60000000000000024e-4 < im < 1.45000000000000012e-29

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

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

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

Alternative 3: 95.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(e^{-im} + e^{im}\right)\\ t_1 := 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -6.5 \cdot 10^{+97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.065:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.45 \cdot 10^{-29}:\\ \;\;\;\;\cos re \cdot \mathsf{fma}\left(im, 0.5 \cdot im, 1\right)\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (+ (exp (- im)) (exp im))))
        (t_1 (* 0.041666666666666664 (* (cos re) (pow im 4.0)))))
   (if (<= im -6.5e+97)
     t_1
     (if (<= im -0.065)
       t_0
       (if (<= im 1.45e-29)
         (* (cos re) (fma im (* 0.5 im) 1.0))
         (if (<= im 1.15e+77) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = 0.5 * (exp(-im) + exp(im));
	double t_1 = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
	double tmp;
	if (im <= -6.5e+97) {
		tmp = t_1;
	} else if (im <= -0.065) {
		tmp = t_0;
	} else if (im <= 1.45e-29) {
		tmp = cos(re) * fma(im, (0.5 * im), 1.0);
	} else if (im <= 1.15e+77) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im)))
	t_1 = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0)))
	tmp = 0.0
	if (im <= -6.5e+97)
		tmp = t_1;
	elseif (im <= -0.065)
		tmp = t_0;
	elseif (im <= 1.45e-29)
		tmp = Float64(cos(re) * fma(im, Float64(0.5 * im), 1.0));
	elseif (im <= 1.15e+77)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -6.5e+97], t$95$1, If[LessEqual[im, -0.065], t$95$0, If[LessEqual[im, 1.45e-29], N[(N[Cos[re], $MachinePrecision] * N[(im * N[(0.5 * im), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.15e+77], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;im \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;\cos re \cdot \mathsf{fma}\left(im, 0.5 \cdot im, 1\right)\\

\mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -6.4999999999999999e97 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

    if -6.4999999999999999e97 < im < -0.065000000000000002 or 1.45000000000000012e-29 < 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 re around 0 89.2%

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

    if -0.065000000000000002 < im < 1.45000000000000012e-29

    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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative99.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.5 \cdot 10^{+97}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq -0.065:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{elif}\;im \leq 1.45 \cdot 10^{-29}:\\ \;\;\;\;\cos re \cdot \mathsf{fma}\left(im, 0.5 \cdot im, 1\right)\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\ \end{array} \]

Alternative 4: 87.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -2.2 \lor \neg \left(im \leq 2.2\right):\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\

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


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

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

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

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

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

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

    if -2.2000000000000002 < im < 2.2000000000000002

    1. Initial program 100.0%

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

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

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

Alternative 5: 84.4% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq -6.2 \cdot 10^{+19}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.4000000000000001e152 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative98.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos re \cdot 0.5, im \cdot im, \cos re\right)} \]
    7. Taylor expanded in im around inf 98.9%

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

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

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

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

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

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

    if -1.4000000000000001e152 < im < -6.2e19 or 3.8e9 < im < 1.8999999999999999e154

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

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

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

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

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

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

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

    if -6.2e19 < im < 3.8e9

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.4 \cdot 10^{+152}:\\ \;\;\;\;\cos re \cdot \left(im \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -6.2 \cdot 10^{+19}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 3800000000:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(im \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 6: 78.3% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := 0.041666666666666664 \cdot {im}^{4}\\
t_1 := \left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\mathbf{if}\;im \leq -1 \cdot 10^{+216}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -4.8 \cdot 10^{+18}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 10^{+188}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 10^{+219}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1e216 or 1e188 < im < 9.99999999999999965e218

    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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1e216 < im < -4.8e18 or 3.2e10 < im < 1e188

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

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

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

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

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

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

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

    if -4.8e18 < im < 3.2e10

    1. Initial program 100.0%

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

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

    if 9.99999999999999965e218 < 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    12. Simplified95.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1 \cdot 10^{+216}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq -4.8 \cdot 10^{+18}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 32000000000:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 10^{+188}:\\ \;\;\;\;0.041666666666666664 \cdot {im}^{4}\\ \mathbf{elif}\;im \leq 10^{+219}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 7: 71.1% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(im \cdot im\right)\\ t_1 := 0.25 + \left(re \cdot re\right) \cdot 0.25\\ t_2 := \left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{if}\;im \leq -1.95 \cdot 10^{+167}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq -1.45 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 580:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+188}:\\ \;\;\;\;1 + t_0\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+219}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (* im im)))
        (t_1 (+ 0.25 (* (* re re) 0.25)))
        (t_2 (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
   (if (<= im -1.95e+167)
     t_2
     (if (<= im -1.45e+20)
       t_1
       (if (<= im 580.0)
         (cos re)
         (if (<= im 6.6e+134)
           t_1
           (if (<= im 5e+188) (+ 1.0 t_0) (if (<= im 1.8e+219) t_2 t_0))))))))
double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = 0.25 + ((re * re) * 0.25);
	double t_2 = (im * im) * (0.5 + ((re * re) * -0.25));
	double tmp;
	if (im <= -1.95e+167) {
		tmp = t_2;
	} else if (im <= -1.45e+20) {
		tmp = t_1;
	} else if (im <= 580.0) {
		tmp = cos(re);
	} else if (im <= 6.6e+134) {
		tmp = t_1;
	} else if (im <= 5e+188) {
		tmp = 1.0 + t_0;
	} else if (im <= 1.8e+219) {
		tmp = t_2;
	} 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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = 0.5d0 * (im * im)
    t_1 = 0.25d0 + ((re * re) * 0.25d0)
    t_2 = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    if (im <= (-1.95d+167)) then
        tmp = t_2
    else if (im <= (-1.45d+20)) then
        tmp = t_1
    else if (im <= 580.0d0) then
        tmp = cos(re)
    else if (im <= 6.6d+134) then
        tmp = t_1
    else if (im <= 5d+188) then
        tmp = 1.0d0 + t_0
    else if (im <= 1.8d+219) then
        tmp = t_2
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = 0.25 + ((re * re) * 0.25);
	double t_2 = (im * im) * (0.5 + ((re * re) * -0.25));
	double tmp;
	if (im <= -1.95e+167) {
		tmp = t_2;
	} else if (im <= -1.45e+20) {
		tmp = t_1;
	} else if (im <= 580.0) {
		tmp = Math.cos(re);
	} else if (im <= 6.6e+134) {
		tmp = t_1;
	} else if (im <= 5e+188) {
		tmp = 1.0 + t_0;
	} else if (im <= 1.8e+219) {
		tmp = t_2;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (im * im)
	t_1 = 0.25 + ((re * re) * 0.25)
	t_2 = (im * im) * (0.5 + ((re * re) * -0.25))
	tmp = 0
	if im <= -1.95e+167:
		tmp = t_2
	elif im <= -1.45e+20:
		tmp = t_1
	elif im <= 580.0:
		tmp = math.cos(re)
	elif im <= 6.6e+134:
		tmp = t_1
	elif im <= 5e+188:
		tmp = 1.0 + t_0
	elif im <= 1.8e+219:
		tmp = t_2
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(im * im))
	t_1 = Float64(0.25 + Float64(Float64(re * re) * 0.25))
	t_2 = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)))
	tmp = 0.0
	if (im <= -1.95e+167)
		tmp = t_2;
	elseif (im <= -1.45e+20)
		tmp = t_1;
	elseif (im <= 580.0)
		tmp = cos(re);
	elseif (im <= 6.6e+134)
		tmp = t_1;
	elseif (im <= 5e+188)
		tmp = Float64(1.0 + t_0);
	elseif (im <= 1.8e+219)
		tmp = t_2;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * (im * im);
	t_1 = 0.25 + ((re * re) * 0.25);
	t_2 = (im * im) * (0.5 + ((re * re) * -0.25));
	tmp = 0.0;
	if (im <= -1.95e+167)
		tmp = t_2;
	elseif (im <= -1.45e+20)
		tmp = t_1;
	elseif (im <= 580.0)
		tmp = cos(re);
	elseif (im <= 6.6e+134)
		tmp = t_1;
	elseif (im <= 5e+188)
		tmp = 1.0 + t_0;
	elseif (im <= 1.8e+219)
		tmp = t_2;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.95e+167], t$95$2, If[LessEqual[im, -1.45e+20], t$95$1, If[LessEqual[im, 580.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 6.6e+134], t$95$1, If[LessEqual[im, 5e+188], N[(1.0 + t$95$0), $MachinePrecision], If[LessEqual[im, 1.8e+219], t$95$2, t$95$0]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -1.45 \cdot 10^{+20}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 6.6 \cdot 10^{+134}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+188}:\\
\;\;\;\;1 + t_0\\

\mathbf{elif}\;im \leq 1.8 \cdot 10^{+219}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if im < -1.9499999999999999e167 or 5.0000000000000001e188 < im < 1.80000000000000003e219

    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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9499999999999999e167 < im < -1.45e20 or 580 < im < 6.6e134

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.25 + 0.25 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. *-commutative25.9%

        \[\leadsto 0.25 + \color{blue}{{re}^{2} \cdot 0.25} \]
      2. unpow225.9%

        \[\leadsto 0.25 + \color{blue}{\left(re \cdot re\right)} \cdot 0.25 \]
    5. Simplified25.9%

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

    if -1.45e20 < im < 580

    1. Initial program 100.0%

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

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

    if 6.6e134 < im < 5.0000000000000001e188

    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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative75.0%

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

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

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

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

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

    if 1.80000000000000003e219 < 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    12. Simplified95.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.95 \cdot 10^{+167}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq -1.45 \cdot 10^{+20}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{elif}\;im \leq 580:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+134}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+188}:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+219}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 8: 49.6% accurate, 20.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(im \cdot im\right)\\ t_1 := 0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{if}\;im \leq -9.5 \cdot 10^{+153}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -4.1 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 310:\\ \;\;\;\;1\\ \mathbf{elif}\;im \leq 6.5 \cdot 10^{+135}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (* im im))) (t_1 (+ 0.25 (* (* re re) 0.25))))
   (if (<= im -9.5e+153)
     t_0
     (if (<= im -4.1e+18)
       t_1
       (if (<= im 310.0) 1.0 (if (<= im 6.5e+135) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = 0.25 + ((re * re) * 0.25);
	double tmp;
	if (im <= -9.5e+153) {
		tmp = t_0;
	} else if (im <= -4.1e+18) {
		tmp = t_1;
	} else if (im <= 310.0) {
		tmp = 1.0;
	} else if (im <= 6.5e+135) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * (im * im)
    t_1 = 0.25d0 + ((re * re) * 0.25d0)
    if (im <= (-9.5d+153)) then
        tmp = t_0
    else if (im <= (-4.1d+18)) then
        tmp = t_1
    else if (im <= 310.0d0) then
        tmp = 1.0d0
    else if (im <= 6.5d+135) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = 0.25 + ((re * re) * 0.25);
	double tmp;
	if (im <= -9.5e+153) {
		tmp = t_0;
	} else if (im <= -4.1e+18) {
		tmp = t_1;
	} else if (im <= 310.0) {
		tmp = 1.0;
	} else if (im <= 6.5e+135) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (im * im)
	t_1 = 0.25 + ((re * re) * 0.25)
	tmp = 0
	if im <= -9.5e+153:
		tmp = t_0
	elif im <= -4.1e+18:
		tmp = t_1
	elif im <= 310.0:
		tmp = 1.0
	elif im <= 6.5e+135:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(im * im))
	t_1 = Float64(0.25 + Float64(Float64(re * re) * 0.25))
	tmp = 0.0
	if (im <= -9.5e+153)
		tmp = t_0;
	elseif (im <= -4.1e+18)
		tmp = t_1;
	elseif (im <= 310.0)
		tmp = 1.0;
	elseif (im <= 6.5e+135)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * (im * im);
	t_1 = 0.25 + ((re * re) * 0.25);
	tmp = 0.0;
	if (im <= -9.5e+153)
		tmp = t_0;
	elseif (im <= -4.1e+18)
		tmp = t_1;
	elseif (im <= 310.0)
		tmp = 1.0;
	elseif (im <= 6.5e+135)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -9.5e+153], t$95$0, If[LessEqual[im, -4.1e+18], t$95$1, If[LessEqual[im, 310.0], 1.0, If[LessEqual[im, 6.5e+135], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(im \cdot im\right)\\
t_1 := 0.25 + \left(re \cdot re\right) \cdot 0.25\\
\mathbf{if}\;im \leq -9.5 \cdot 10^{+153}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -4.1 \cdot 10^{+18}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 310:\\
\;\;\;\;1\\

\mathbf{elif}\;im \leq 6.5 \cdot 10^{+135}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -9.4999999999999995e153 or 6.5000000000000003e135 < 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative94.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos re \cdot 0.5}, im \cdot im, \cos re\right) \]
    6. Simplified94.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos re \cdot 0.5, im \cdot im, \cos re\right)} \]
    7. Taylor expanded in im around inf 94.4%

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    12. Simplified69.7%

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

    if -9.4999999999999995e153 < im < -4.1e18 or 310 < im < 6.5000000000000003e135

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.25 + 0.25 \cdot {re}^{2}} \]
    4. Step-by-step derivation
      1. *-commutative24.4%

        \[\leadsto 0.25 + \color{blue}{{re}^{2} \cdot 0.25} \]
      2. unpow224.4%

        \[\leadsto 0.25 + \color{blue}{\left(re \cdot re\right)} \cdot 0.25 \]
    5. Simplified24.4%

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

    if -4.1e18 < im < 310

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
    7. Applied egg-rr53.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -9.5 \cdot 10^{+153}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq -4.1 \cdot 10^{+18}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{elif}\;im \leq 310:\\ \;\;\;\;1\\ \mathbf{elif}\;im \leq 6.5 \cdot 10^{+135}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 9: 49.5% accurate, 23.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(im \cdot im\right)\\ t_1 := re \cdot re - re\\ \mathbf{if}\;im \leq -1.9 \cdot 10^{+153}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1.4 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 360:\\ \;\;\;\;1\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (* im im))) (t_1 (- (* re re) re)))
   (if (<= im -1.9e+153)
     t_0
     (if (<= im -1.4e+19)
       t_1
       (if (<= im 360.0) 1.0 (if (<= im 1.05e+136) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = (re * re) - re;
	double tmp;
	if (im <= -1.9e+153) {
		tmp = t_0;
	} else if (im <= -1.4e+19) {
		tmp = t_1;
	} else if (im <= 360.0) {
		tmp = 1.0;
	} else if (im <= 1.05e+136) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * (im * im)
    t_1 = (re * re) - re
    if (im <= (-1.9d+153)) then
        tmp = t_0
    else if (im <= (-1.4d+19)) then
        tmp = t_1
    else if (im <= 360.0d0) then
        tmp = 1.0d0
    else if (im <= 1.05d+136) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double t_1 = (re * re) - re;
	double tmp;
	if (im <= -1.9e+153) {
		tmp = t_0;
	} else if (im <= -1.4e+19) {
		tmp = t_1;
	} else if (im <= 360.0) {
		tmp = 1.0;
	} else if (im <= 1.05e+136) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (im * im)
	t_1 = (re * re) - re
	tmp = 0
	if im <= -1.9e+153:
		tmp = t_0
	elif im <= -1.4e+19:
		tmp = t_1
	elif im <= 360.0:
		tmp = 1.0
	elif im <= 1.05e+136:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(im * im))
	t_1 = Float64(Float64(re * re) - re)
	tmp = 0.0
	if (im <= -1.9e+153)
		tmp = t_0;
	elseif (im <= -1.4e+19)
		tmp = t_1;
	elseif (im <= 360.0)
		tmp = 1.0;
	elseif (im <= 1.05e+136)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * (im * im);
	t_1 = (re * re) - re;
	tmp = 0.0;
	if (im <= -1.9e+153)
		tmp = t_0;
	elseif (im <= -1.4e+19)
		tmp = t_1;
	elseif (im <= 360.0)
		tmp = 1.0;
	elseif (im <= 1.05e+136)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(re * re), $MachinePrecision] - re), $MachinePrecision]}, If[LessEqual[im, -1.9e+153], t$95$0, If[LessEqual[im, -1.4e+19], t$95$1, If[LessEqual[im, 360.0], 1.0, If[LessEqual[im, 1.05e+136], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -1.4 \cdot 10^{+19}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 360:\\
\;\;\;\;1\\

\mathbf{elif}\;im \leq 1.05 \cdot 10^{+136}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.89999999999999983e153 or 1.05e136 < 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 \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \left(\cos re + 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\right)} \]
    3. Simplified100.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative94.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos re \cdot 0.5}, im \cdot im, \cos re\right) \]
    6. Simplified94.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos re \cdot 0.5, im \cdot im, \cos re\right)} \]
    7. Taylor expanded in im around inf 94.4%

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    12. Simplified69.7%

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

    if -1.89999999999999983e153 < im < -1.4e19 or 360 < im < 1.05e136

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, re, -re\right)} \]
    5. Step-by-step derivation
      1. fma-neg23.7%

        \[\leadsto \color{blue}{re \cdot re - re} \]
    6. Simplified23.7%

      \[\leadsto \color{blue}{re \cdot re - re} \]

    if -1.4e19 < im < 360

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
    7. Applied egg-rr53.4%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification51.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.9 \cdot 10^{+153}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq -1.4 \cdot 10^{+19}:\\ \;\;\;\;re \cdot re - re\\ \mathbf{elif}\;im \leq 360:\\ \;\;\;\;1\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{+136}:\\ \;\;\;\;re \cdot re - re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 10: 49.0% accurate, 27.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -6 \cdot 10^{+145} \lor \neg \left(re \leq 3.3 \cdot 10^{+174}\right):\\
\;\;\;\;re \cdot re - re\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -6.0000000000000005e145 or 3.3000000000000001e174 < re

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, re, -re\right)} \]
    5. Step-by-step derivation
      1. fma-neg38.1%

        \[\leadsto \color{blue}{re \cdot re - re} \]
    6. Simplified38.1%

      \[\leadsto \color{blue}{re \cdot re - re} \]

    if -6.0000000000000005e145 < re < 3.3000000000000001e174

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative76.1%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos re \cdot 0.5}, im \cdot im, \cos re\right) \]
    6. Simplified76.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -6 \cdot 10^{+145} \lor \neg \left(re \leq 3.3 \cdot 10^{+174}\right):\\ \;\;\;\;re \cdot re - re\\ \mathbf{else}:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 11: 47.4% accurate, 33.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.00041 \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.00041) (not (<= im 1.4))) (* 0.5 (* im im)) 1.0))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.00041) || !(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.00041d0)) .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.00041) || !(im <= 1.4)) {
		tmp = 0.5 * (im * im);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -0.00041) 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.00041) || !(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.00041) || ~((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.00041], 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.00041 \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 < -4.0999999999999999e-4 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 81.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(0.5 \cdot \cos re, im \cdot im, \cos re\right)} \]
      4. *-commutative56.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\cos re \cdot 0.5}, im \cdot im, \cos re\right) \]
    6. Simplified56.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos re \cdot 0.5, im \cdot im, \cos re\right)} \]
    7. Taylor expanded in im around inf 55.8%

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

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

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

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

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

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

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

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

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

    if -4.0999999999999999e-4 < im < 1.3999999999999999

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
    7. Applied egg-rr54.8%

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

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

Alternative 12: 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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr3.3%

    \[\leadsto \color{blue}{-1} \]
  8. Final simplification3.3%

    \[\leadsto -1 \]

Alternative 13: 7.4% accurate, 308.0× speedup?

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

\\
0.041666666666666664
\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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr7.1%

    \[\leadsto \color{blue}{0.041666666666666664} \]
  8. Final simplification7.1%

    \[\leadsto 0.041666666666666664 \]

Alternative 14: 7.5% accurate, 308.0× speedup?

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

\\
0.0625
\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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr7.3%

    \[\leadsto \color{blue}{0.0625} \]
  8. Final simplification7.3%

    \[\leadsto 0.0625 \]

Alternative 15: 7.8% 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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr7.5%

    \[\leadsto \color{blue}{0.125} \]
  8. Final simplification7.5%

    \[\leadsto 0.125 \]

Alternative 16: 8.2% 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. Applied egg-rr7.7%

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

    \[\leadsto \color{blue}{0.25} \]
  4. Final simplification7.8%

    \[\leadsto 0.25 \]

Alternative 17: 8.8% accurate, 308.0× speedup?

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

\\
0.5
\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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr8.3%

    \[\leadsto \color{blue}{0.5} \]
  8. Final simplification8.3%

    \[\leadsto 0.5 \]

Alternative 18: 9.2% 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 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr8.7%

    \[\leadsto \color{blue}{0.75} \]
  8. Final simplification8.7%

    \[\leadsto 0.75 \]

Alternative 19: 29.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 im around 0 89.8%

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

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

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

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

    \[\leadsto \color{blue}{0.041666666666666664 \cdot \left({im}^{4} \cdot \cos re\right)} \]
  7. Applied egg-rr25.6%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification25.6%

    \[\leadsto 1 \]

Reproduce

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