math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 8.3s
Alternatives: 14
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 14 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: 92.8% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;im \leq -11.5:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -3.1000000000000001e154 or 2.1499999999999999e154 < 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) + \cos re} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

    if -3.1000000000000001e154 < im < -11.5 or 0.030499999999999999 < im < 2.1499999999999999e154

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

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

    if -11.5 < im < 0.030499999999999999

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{im \cdot \left(im \cdot \cos re\right)}, \cos re\right) \]
    7. Step-by-step derivation
      1. fma-udef99.4%

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

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

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

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

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

        \[\leadsto \color{blue}{im \cdot \left(\left(im \cdot 0.5\right) \cdot \cos re\right)} + \cos re \]
    8. Applied egg-rr99.4%

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

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

Alternative 3: 92.8% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;im \leq -11.5:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.05999999999999988e154 or 1.9500000000000001e154 < 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) + \cos re} \]
    3. Simplified100.0%

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

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

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

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

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

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

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

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

    if -2.05999999999999988e154 < im < -11.5 or 0.0071000000000000004 < im < 1.9500000000000001e154

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

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

    if -11.5 < im < 0.0071000000000000004

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 78.5% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ t_1 := 0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{if}\;im \leq -2.9 \cdot 10^{+150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -600:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 2.3:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 5.4 \cdot 10^{+135}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (* 0.5 (* (cos re) im)))) (t_1 (+ 0.25 (* 0.25 (* re re)))))
   (if (<= im -2.9e+150)
     t_0
     (if (<= im -600.0)
       t_1
       (if (<= im 2.3)
         (cos re)
         (if (<= im 5.4e+135)
           (* (* im im) (+ 0.5 (* (* re re) -0.25)))
           (if (<= im 2.6e+138) t_1 t_0)))))))
double code(double re, double im) {
	double t_0 = im * (0.5 * (cos(re) * im));
	double t_1 = 0.25 + (0.25 * (re * re));
	double tmp;
	if (im <= -2.9e+150) {
		tmp = t_0;
	} else if (im <= -600.0) {
		tmp = t_1;
	} else if (im <= 2.3) {
		tmp = cos(re);
	} else if (im <= 5.4e+135) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else if (im <= 2.6e+138) {
		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 = im * (0.5d0 * (cos(re) * im))
    t_1 = 0.25d0 + (0.25d0 * (re * re))
    if (im <= (-2.9d+150)) then
        tmp = t_0
    else if (im <= (-600.0d0)) then
        tmp = t_1
    else if (im <= 2.3d0) then
        tmp = cos(re)
    else if (im <= 5.4d+135) then
        tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    else if (im <= 2.6d+138) 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 = im * (0.5 * (Math.cos(re) * im));
	double t_1 = 0.25 + (0.25 * (re * re));
	double tmp;
	if (im <= -2.9e+150) {
		tmp = t_0;
	} else if (im <= -600.0) {
		tmp = t_1;
	} else if (im <= 2.3) {
		tmp = Math.cos(re);
	} else if (im <= 5.4e+135) {
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	} else if (im <= 2.6e+138) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (0.5 * (math.cos(re) * im))
	t_1 = 0.25 + (0.25 * (re * re))
	tmp = 0
	if im <= -2.9e+150:
		tmp = t_0
	elif im <= -600.0:
		tmp = t_1
	elif im <= 2.3:
		tmp = math.cos(re)
	elif im <= 5.4e+135:
		tmp = (im * im) * (0.5 + ((re * re) * -0.25))
	elif im <= 2.6e+138:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(0.5 * Float64(cos(re) * im)))
	t_1 = Float64(0.25 + Float64(0.25 * Float64(re * re)))
	tmp = 0.0
	if (im <= -2.9e+150)
		tmp = t_0;
	elseif (im <= -600.0)
		tmp = t_1;
	elseif (im <= 2.3)
		tmp = cos(re);
	elseif (im <= 5.4e+135)
		tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	elseif (im <= 2.6e+138)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (0.5 * (cos(re) * im));
	t_1 = 0.25 + (0.25 * (re * re));
	tmp = 0.0;
	if (im <= -2.9e+150)
		tmp = t_0;
	elseif (im <= -600.0)
		tmp = t_1;
	elseif (im <= 2.3)
		tmp = cos(re);
	elseif (im <= 5.4e+135)
		tmp = (im * im) * (0.5 + ((re * re) * -0.25));
	elseif (im <= 2.6e+138)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.9e+150], t$95$0, If[LessEqual[im, -600.0], t$95$1, If[LessEqual[im, 2.3], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5.4e+135], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.6e+138], t$95$1, t$95$0]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -600:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;im \leq 2.6 \cdot 10^{+138}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -2.90000000000000011e150 or 2.6000000000000001e138 < 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 92.5%

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

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

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

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

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

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

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

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

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

    if -2.90000000000000011e150 < im < -600 or 5.3999999999999997e135 < im < 2.6000000000000001e138

    1. Initial program 100.0%

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

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

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

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

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

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

    if -600 < im < 2.2999999999999998

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

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

    if 2.2999999999999998 < im < 5.3999999999999997e135

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25 + 0.5\right) \]
    9. Simplified27.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.9 \cdot 10^{+150}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -600:\\ \;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{elif}\;im \leq 2.3:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 5.4 \cdot 10^{+135}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+138}:\\ \;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \end{array} \]

Alternative 5: 76.7% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq -255:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -3.99999999999999992e150 or 3.2e5 < 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 73.9%

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

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

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

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

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

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

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

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

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

    if -3.99999999999999992e150 < im < -255

    1. Initial program 100.0%

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

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

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

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

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

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

    if -255 < im < 3.2e5

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{im \cdot im}, \cos re\right) \]
    7. Step-by-step derivation
      1. fma-udef96.8%

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

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

        \[\leadsto \color{blue}{im \cdot \left(im \cdot 0.5\right)} + \cos re \]
    8. Applied egg-rr96.8%

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

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

Alternative 6: 77.6% accurate, 2.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -6.59999999999999962e150 or 2.1e7 < 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 73.9%

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

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

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

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

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

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

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

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

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

    if -6.59999999999999962e150 < im < -600

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -600 < im < 2.1e7

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{im \cdot im}, \cos re\right) \]
    7. Step-by-step derivation
      1. fma-udef96.8%

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

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

        \[\leadsto \color{blue}{im \cdot \left(im \cdot 0.5\right)} + \cos re \]
    8. Applied egg-rr96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.6 \cdot 10^{+150}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -600:\\ \;\;\;\;{re}^{4} \cdot \left(im \cdot \left(im \cdot 0.020833333333333332\right)\right)\\ \mathbf{elif}\;im \leq 21000000:\\ \;\;\;\;\cos re + im \cdot \left(0.5 \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \end{array} \]

Alternative 7: 75.8% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(im \cdot im\right)}\right) \cdot \cos re + \cos re \]
    4. distribute-lft1-in75.1%

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

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

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

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

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

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

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

Alternative 8: 73.7% accurate, 2.9× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.7999999999999999e23 < im < 2.5

    1. Initial program 100.0%

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

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

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

Alternative 9: 51.8% accurate, 17.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{if}\;im \leq -6.8 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 320000:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{im}{2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
   (if (<= im -6.8e+23)
     t_0
     (if (<= im 320000.0)
       (+ 1.0 (* 0.5 (* im im)))
       (if (<= im 1e+161) t_0 (* im (/ im 2.0)))))))
double code(double re, double im) {
	double t_0 = (im * im) * (0.5 + ((re * re) * -0.25));
	double tmp;
	if (im <= -6.8e+23) {
		tmp = t_0;
	} else if (im <= 320000.0) {
		tmp = 1.0 + (0.5 * (im * im));
	} else if (im <= 1e+161) {
		tmp = t_0;
	} else {
		tmp = im * (im / 2.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
    if (im <= (-6.8d+23)) then
        tmp = t_0
    else if (im <= 320000.0d0) then
        tmp = 1.0d0 + (0.5d0 * (im * im))
    else if (im <= 1d+161) then
        tmp = t_0
    else
        tmp = im * (im / 2.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (im * im) * (0.5 + ((re * re) * -0.25));
	double tmp;
	if (im <= -6.8e+23) {
		tmp = t_0;
	} else if (im <= 320000.0) {
		tmp = 1.0 + (0.5 * (im * im));
	} else if (im <= 1e+161) {
		tmp = t_0;
	} else {
		tmp = im * (im / 2.0);
	}
	return tmp;
}
def code(re, im):
	t_0 = (im * im) * (0.5 + ((re * re) * -0.25))
	tmp = 0
	if im <= -6.8e+23:
		tmp = t_0
	elif im <= 320000.0:
		tmp = 1.0 + (0.5 * (im * im))
	elif im <= 1e+161:
		tmp = t_0
	else:
		tmp = im * (im / 2.0)
	return tmp
function code(re, im)
	t_0 = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25)))
	tmp = 0.0
	if (im <= -6.8e+23)
		tmp = t_0;
	elseif (im <= 320000.0)
		tmp = Float64(1.0 + Float64(0.5 * Float64(im * im)));
	elseif (im <= 1e+161)
		tmp = t_0;
	else
		tmp = Float64(im * Float64(im / 2.0));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (im * im) * (0.5 + ((re * re) * -0.25));
	tmp = 0.0;
	if (im <= -6.8e+23)
		tmp = t_0;
	elseif (im <= 320000.0)
		tmp = 1.0 + (0.5 * (im * im));
	elseif (im <= 1e+161)
		tmp = t_0;
	else
		tmp = im * (im / 2.0);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -6.8e+23], t$95$0, If[LessEqual[im, 320000.0], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e+161], t$95$0, N[(im * N[(im / 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 320000:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\

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

\mathbf{else}:\\
\;\;\;\;im \cdot \frac{im}{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -6.79999999999999983e23 or 3.2e5 < im < 1e161

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.79999999999999983e23 < im < 3.2e5

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

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

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

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

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

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

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

    if 1e161 < 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) + \cos re} \]
    3. Simplified100.0%

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

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{2}\right) \cdot 0.5} \]
      2. associate-*r*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) \]
    6. Simplified100.0%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
      2. rem-log-exp85.7%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\log \left(e^{im}\right)}\right) \]
      3. log-pow85.7%

        \[\leadsto 0.5 \cdot \color{blue}{\log \left({\left(e^{im}\right)}^{im}\right)} \]
      4. log-pow85.7%

        \[\leadsto \color{blue}{\log \left({\left({\left(e^{im}\right)}^{im}\right)}^{0.5}\right)} \]
      5. unpow1/285.7%

        \[\leadsto \log \color{blue}{\left(\sqrt{{\left(e^{im}\right)}^{im}}\right)} \]
      6. sqr-pow85.7%

        \[\leadsto \log \left(\sqrt{\color{blue}{{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}}}\right) \]
      7. rem-sqrt-square85.7%

        \[\leadsto \log \color{blue}{\left(\left|{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right|\right)} \]
      8. sqr-pow85.7%

        \[\leadsto \log \left(\left|\color{blue}{{\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}}\right|\right) \]
      9. fabs-sqr85.7%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}\right)} \]
      10. sqr-pow85.7%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right)} \]
      11. log-pow85.7%

        \[\leadsto \color{blue}{\frac{im}{2} \cdot \log \left(e^{im}\right)} \]
      12. rem-log-exp85.7%

        \[\leadsto \frac{im}{2} \cdot \color{blue}{im} \]
    9. Simplified85.7%

      \[\leadsto \color{blue}{\frac{im}{2} \cdot im} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification53.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.8 \cdot 10^{+23}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq 320000:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 10^{+161}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{im}{2}\\ \end{array} \]

Alternative 10: 28.9% accurate, 20.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \frac{im}{2}\\ t_1 := 0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{if}\;im \leq -6.6 \cdot 10^{+150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -410:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 1.3 \cdot 10^{+15}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (/ im 2.0))) (t_1 (+ 0.25 (* 0.25 (* re re)))))
   (if (<= im -6.6e+150)
     t_0
     (if (<= im -410.0)
       t_1
       (if (<= im 1.3e+15) 0.25 (if (<= im 1.8e+154) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = im * (im / 2.0);
	double t_1 = 0.25 + (0.25 * (re * re));
	double tmp;
	if (im <= -6.6e+150) {
		tmp = t_0;
	} else if (im <= -410.0) {
		tmp = t_1;
	} else if (im <= 1.3e+15) {
		tmp = 0.25;
	} else if (im <= 1.8e+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 = im * (im / 2.0d0)
    t_1 = 0.25d0 + (0.25d0 * (re * re))
    if (im <= (-6.6d+150)) then
        tmp = t_0
    else if (im <= (-410.0d0)) then
        tmp = t_1
    else if (im <= 1.3d+15) then
        tmp = 0.25d0
    else if (im <= 1.8d+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 = im * (im / 2.0);
	double t_1 = 0.25 + (0.25 * (re * re));
	double tmp;
	if (im <= -6.6e+150) {
		tmp = t_0;
	} else if (im <= -410.0) {
		tmp = t_1;
	} else if (im <= 1.3e+15) {
		tmp = 0.25;
	} else if (im <= 1.8e+154) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (im / 2.0)
	t_1 = 0.25 + (0.25 * (re * re))
	tmp = 0
	if im <= -6.6e+150:
		tmp = t_0
	elif im <= -410.0:
		tmp = t_1
	elif im <= 1.3e+15:
		tmp = 0.25
	elif im <= 1.8e+154:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(im / 2.0))
	t_1 = Float64(0.25 + Float64(0.25 * Float64(re * re)))
	tmp = 0.0
	if (im <= -6.6e+150)
		tmp = t_0;
	elseif (im <= -410.0)
		tmp = t_1;
	elseif (im <= 1.3e+15)
		tmp = 0.25;
	elseif (im <= 1.8e+154)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (im / 2.0);
	t_1 = 0.25 + (0.25 * (re * re));
	tmp = 0.0;
	if (im <= -6.6e+150)
		tmp = t_0;
	elseif (im <= -410.0)
		tmp = t_1;
	elseif (im <= 1.3e+15)
		tmp = 0.25;
	elseif (im <= 1.8e+154)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(im / 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -6.6e+150], t$95$0, If[LessEqual[im, -410.0], t$95$1, If[LessEqual[im, 1.3e+15], 0.25, If[LessEqual[im, 1.8e+154], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := im \cdot \frac{im}{2}\\
t_1 := 0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\mathbf{if}\;im \leq -6.6 \cdot 10^{+150}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -410:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 1.3 \cdot 10^{+15}:\\
\;\;\;\;0.25\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -6.59999999999999962e150 or 1.8e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
      2. rem-log-exp65.5%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\log \left(e^{im}\right)}\right) \]
      3. log-pow65.5%

        \[\leadsto 0.5 \cdot \color{blue}{\log \left({\left(e^{im}\right)}^{im}\right)} \]
      4. log-pow65.5%

        \[\leadsto \color{blue}{\log \left({\left({\left(e^{im}\right)}^{im}\right)}^{0.5}\right)} \]
      5. unpow1/265.5%

        \[\leadsto \log \color{blue}{\left(\sqrt{{\left(e^{im}\right)}^{im}}\right)} \]
      6. sqr-pow65.5%

        \[\leadsto \log \left(\sqrt{\color{blue}{{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}}}\right) \]
      7. rem-sqrt-square65.5%

        \[\leadsto \log \color{blue}{\left(\left|{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right|\right)} \]
      8. sqr-pow65.5%

        \[\leadsto \log \left(\left|\color{blue}{{\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}}\right|\right) \]
      9. fabs-sqr65.5%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}\right)} \]
      10. sqr-pow65.5%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right)} \]
      11. log-pow65.5%

        \[\leadsto \color{blue}{\frac{im}{2} \cdot \log \left(e^{im}\right)} \]
      12. rem-log-exp63.8%

        \[\leadsto \frac{im}{2} \cdot \color{blue}{im} \]
    9. Simplified63.8%

      \[\leadsto \color{blue}{\frac{im}{2} \cdot im} \]

    if -6.59999999999999962e150 < im < -410 or 1.3e15 < im < 1.8e154

    1. Initial program 100.0%

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

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

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

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

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

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

    if -410 < im < 1.3e15

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.25} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -6.6 \cdot 10^{+150}:\\ \;\;\;\;im \cdot \frac{im}{2}\\ \mathbf{elif}\;im \leq -410:\\ \;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{elif}\;im \leq 1.3 \cdot 10^{+15}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+154}:\\ \;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \frac{im}{2}\\ \end{array} \]

Alternative 11: 49.7% accurate, 23.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.5 \cdot 10^{+167} \lor \neg \left(re \leq 1.56\right):\\
\;\;\;\;im \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot -0.25\right)\right)\\

\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 < -4.4999999999999999e167 or 1.5600000000000001 < re

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(im \cdot im\right)} \cdot \left(re \cdot \left(re \cdot -0.25\right)\right) \]
      7. associate-*l*29.7%

        \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)} \]
      8. associate-*r*29.7%

        \[\leadsto im \cdot \left(im \cdot \color{blue}{\left(\left(re \cdot re\right) \cdot -0.25\right)}\right) \]
      9. unpow229.7%

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

        \[\leadsto im \cdot \color{blue}{\left(\left(im \cdot {re}^{2}\right) \cdot -0.25\right)} \]
      11. *-commutative29.7%

        \[\leadsto im \cdot \left(\color{blue}{\left({re}^{2} \cdot im\right)} \cdot -0.25\right) \]
      12. associate-*l*29.7%

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

        \[\leadsto im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot \left(im \cdot -0.25\right)\right) \]
    12. Simplified29.7%

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

    if -4.4999999999999999e167 < re < 1.5600000000000001

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -4.5 \cdot 10^{+167} \lor \neg \left(re \leq 1.56\right):\\ \;\;\;\;im \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 12: 26.3% accurate, 33.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -11.5 \lor \neg \left(im \leq 0.7\right):\\
\;\;\;\;im \cdot \frac{im}{2}\\

\mathbf{else}:\\
\;\;\;\;0.25\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -11.5 or 0.69999999999999996 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
      2. rem-log-exp73.6%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\log \left(e^{im}\right)}\right) \]
      3. log-pow73.5%

        \[\leadsto 0.5 \cdot \color{blue}{\log \left({\left(e^{im}\right)}^{im}\right)} \]
      4. log-pow73.5%

        \[\leadsto \color{blue}{\log \left({\left({\left(e^{im}\right)}^{im}\right)}^{0.5}\right)} \]
      5. unpow1/273.5%

        \[\leadsto \log \color{blue}{\left(\sqrt{{\left(e^{im}\right)}^{im}}\right)} \]
      6. sqr-pow73.5%

        \[\leadsto \log \left(\sqrt{\color{blue}{{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}}}\right) \]
      7. rem-sqrt-square73.5%

        \[\leadsto \log \color{blue}{\left(\left|{\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right|\right)} \]
      8. sqr-pow73.5%

        \[\leadsto \log \left(\left|\color{blue}{{\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}}\right|\right) \]
      9. fabs-sqr73.5%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)} \cdot {\left(e^{im}\right)}^{\left(\frac{\frac{im}{2}}{2}\right)}\right)} \]
      10. sqr-pow73.5%

        \[\leadsto \log \color{blue}{\left({\left(e^{im}\right)}^{\left(\frac{im}{2}\right)}\right)} \]
      11. log-pow73.6%

        \[\leadsto \color{blue}{\frac{im}{2} \cdot \log \left(e^{im}\right)} \]
      12. rem-log-exp32.0%

        \[\leadsto \frac{im}{2} \cdot \color{blue}{im} \]
    9. Simplified32.0%

      \[\leadsto \color{blue}{\frac{im}{2} \cdot im} \]

    if -11.5 < im < 0.69999999999999996

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -11.5 \lor \neg \left(im \leq 0.7\right):\\ \;\;\;\;im \cdot \frac{im}{2}\\ \mathbf{else}:\\ \;\;\;\;0.25\\ \end{array} \]

Alternative 13: 47.0% accurate, 44.0× speedup?

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

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

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

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

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

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

      \[\leadsto 1 + \color{blue}{{im}^{2} \cdot 0.5} \]
    2. unpow245.9%

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

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

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

Alternative 14: 8.0% 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-rr8.5%

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

    \[\leadsto \color{blue}{0.25} \]
  4. Final simplification8.7%

    \[\leadsto 0.25 \]

Reproduce

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