math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 9.2s
Alternatives: 15
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 2: 93.0% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;im \leq 2.1 \cdot 10^{+150}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if -7.19999999999999972e150 < im < -2.60000000000000009 or 1.94999999999999996 < im < 2.09999999999999998e150

    1. Initial program 100.0%

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

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

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

    if -2.60000000000000009 < im < 1.94999999999999996

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

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

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

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

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

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

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

    if 2.09999999999999998e150 < im

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified96.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 96.9%

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

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

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

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

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

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

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

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

Alternative 3: 93.2% accurate, 1.4× speedup?

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

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

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

\mathbf{elif}\;im \leq 2000000000:\\
\;\;\;\;\cos re + t_0\\

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

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


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

    1. Initial program 100.0%

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

    if -1.35000000000000003e154 < im < -2.60000000000000009 or 2e9 < im < 3.1000000000000001e154

    1. Initial program 100.0%

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

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

    if -2.60000000000000009 < im < 2e9

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

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

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

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

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

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

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

    if 3.1000000000000001e154 < 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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -2.6:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;\cos re + \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 3.1 \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: 93.2% accurate, 1.4× speedup?

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

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

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

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

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

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


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

    1. Initial program 100.0%

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

    if -1.35000000000000003e154 < im < -2.60000000000000009 or 2e9 < im < 2.2000000000000001e154

    1. Initial program 100.0%

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

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

    if -2.60000000000000009 < im < 2e9

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified98.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 inf 98.0%

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

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

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

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

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

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

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

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

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

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

    if 2.2000000000000001e154 < 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)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification91.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -2.6:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\ \mathbf{elif}\;im \leq 2.2 \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 5: 78.4% 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)\\ t_1 := \left(re \cdot re\right) \cdot \left(\left(im \cdot im\right) \cdot -0.25\right)\\ \mathbf{if}\;im \leq -1.9 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -1900000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+49}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+150}:\\ \;\;\;\;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 (* (* re re) (* (* im im) -0.25))))
   (if (<= im -1.9e+154)
     t_0
     (if (<= im -1900000000000.0)
       t_1
       (if (<= im 1.1e+49) (cos re) (if (<= im 1.9e+150) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = im * (0.5 * (cos(re) * im));
	double t_1 = (re * re) * ((im * im) * -0.25);
	double tmp;
	if (im <= -1.9e+154) {
		tmp = t_0;
	} else if (im <= -1900000000000.0) {
		tmp = t_1;
	} else if (im <= 1.1e+49) {
		tmp = cos(re);
	} else if (im <= 1.9e+150) {
		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 = (re * re) * ((im * im) * (-0.25d0))
    if (im <= (-1.9d+154)) then
        tmp = t_0
    else if (im <= (-1900000000000.0d0)) then
        tmp = t_1
    else if (im <= 1.1d+49) then
        tmp = cos(re)
    else if (im <= 1.9d+150) 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 = (re * re) * ((im * im) * -0.25);
	double tmp;
	if (im <= -1.9e+154) {
		tmp = t_0;
	} else if (im <= -1900000000000.0) {
		tmp = t_1;
	} else if (im <= 1.1e+49) {
		tmp = Math.cos(re);
	} else if (im <= 1.9e+150) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (0.5 * (math.cos(re) * im))
	t_1 = (re * re) * ((im * im) * -0.25)
	tmp = 0
	if im <= -1.9e+154:
		tmp = t_0
	elif im <= -1900000000000.0:
		tmp = t_1
	elif im <= 1.1e+49:
		tmp = math.cos(re)
	elif im <= 1.9e+150:
		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(Float64(re * re) * Float64(Float64(im * im) * -0.25))
	tmp = 0.0
	if (im <= -1.9e+154)
		tmp = t_0;
	elseif (im <= -1900000000000.0)
		tmp = t_1;
	elseif (im <= 1.1e+49)
		tmp = cos(re);
	elseif (im <= 1.9e+150)
		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 = (re * re) * ((im * im) * -0.25);
	tmp = 0.0;
	if (im <= -1.9e+154)
		tmp = t_0;
	elseif (im <= -1900000000000.0)
		tmp = t_1;
	elseif (im <= 1.1e+49)
		tmp = cos(re);
	elseif (im <= 1.9e+150)
		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[(N[(re * re), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.9e+154], t$95$0, If[LessEqual[im, -1900000000000.0], t$95$1, If[LessEqual[im, 1.1e+49], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.9e+150], 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 := \left(re \cdot re\right) \cdot \left(\left(im \cdot im\right) \cdot -0.25\right)\\
\mathbf{if}\;im \leq -1.9 \cdot 10^{+154}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 1.1 \cdot 10^{+49}:\\
\;\;\;\;\cos re\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.8999999999999999e154 or 1.89999999999999995e150 < 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. unpow298.4%

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

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

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

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

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

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

    if -1.8999999999999999e154 < im < -1.9e12 or 1.1e49 < im < 1.89999999999999995e150

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9e12 < im < 1.1e49

    1. Initial program 100.0%

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

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

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

Alternative 6: 78.3% accurate, 2.7× speedup?

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

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

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

\mathbf{elif}\;im \leq 10^{+51}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 2.1 \cdot 10^{+150}:\\
\;\;\;\;t_0\\

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


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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified88.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 88.0%

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

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

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

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

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

    if -5.9999999999999999e139 < im < -1.9e12 or 1e51 < im < 2.09999999999999998e150

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified5.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 5.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow227.5%

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

        \[\leadsto im \cdot \left(0.5 \cdot \mathsf{fma}\left(\color{blue}{\left(-0.5 \cdot re\right) \cdot re}, im, im\right)\right) \]
    9. Simplified27.5%

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

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

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

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

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

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

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

    if -1.9e12 < im < 1e51

    1. Initial program 100.0%

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

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

    if 2.09999999999999998e150 < im

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified96.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 96.9%

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

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

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

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

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

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

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

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

Alternative 7: 76.0% accurate, 2.8× speedup?

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

\\
\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\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 72.1%

    \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
  3. Simplified72.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 72.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 72.4% accurate, 2.9× speedup?

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

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

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

\mathbf{elif}\;im \leq 1.1 \cdot 10^{+49}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 1.65 \cdot 10^{+150}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.84999999999999997e154 or 1.6499999999999999e150 < 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. unpow298.4%

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

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

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

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

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

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

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

    if -1.84999999999999997e154 < im < -2.05e12 or 1.1e49 < im < 1.6499999999999999e150

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.05e12 < im < 1.1e49

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.85 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq -2050000000000:\\ \;\;\;\;\left(re \cdot re\right) \cdot \left(\left(im \cdot im\right) \cdot -0.25\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+49}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.65 \cdot 10^{+150}:\\ \;\;\;\;\left(re \cdot re\right) \cdot \left(\left(im \cdot im\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 9: 29.5% accurate, 20.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \left(0.5 \cdot im\right)\\ t_1 := im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right)\\ \mathbf{if}\;im \leq -1.7 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2.5:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{+29}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (* 0.5 im))) (t_1 (* im (* 0.5 (* re re)))))
   (if (<= im -1.7e+154)
     t_0
     (if (<= im -2.5)
       t_1
       (if (<= im 1.5e+29) 0.25 (if (<= im 1.7e+154) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = im * (0.5 * im);
	double t_1 = im * (0.5 * (re * re));
	double tmp;
	if (im <= -1.7e+154) {
		tmp = t_0;
	} else if (im <= -2.5) {
		tmp = t_1;
	} else if (im <= 1.5e+29) {
		tmp = 0.25;
	} else if (im <= 1.7e+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 * im)
    t_1 = im * (0.5d0 * (re * re))
    if (im <= (-1.7d+154)) then
        tmp = t_0
    else if (im <= (-2.5d0)) then
        tmp = t_1
    else if (im <= 1.5d+29) then
        tmp = 0.25d0
    else if (im <= 1.7d+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 * im);
	double t_1 = im * (0.5 * (re * re));
	double tmp;
	if (im <= -1.7e+154) {
		tmp = t_0;
	} else if (im <= -2.5) {
		tmp = t_1;
	} else if (im <= 1.5e+29) {
		tmp = 0.25;
	} else if (im <= 1.7e+154) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (0.5 * im)
	t_1 = im * (0.5 * (re * re))
	tmp = 0
	if im <= -1.7e+154:
		tmp = t_0
	elif im <= -2.5:
		tmp = t_1
	elif im <= 1.5e+29:
		tmp = 0.25
	elif im <= 1.7e+154:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(0.5 * im))
	t_1 = Float64(im * Float64(0.5 * Float64(re * re)))
	tmp = 0.0
	if (im <= -1.7e+154)
		tmp = t_0;
	elseif (im <= -2.5)
		tmp = t_1;
	elseif (im <= 1.5e+29)
		tmp = 0.25;
	elseif (im <= 1.7e+154)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (0.5 * im);
	t_1 = im * (0.5 * (re * re));
	tmp = 0.0;
	if (im <= -1.7e+154)
		tmp = t_0;
	elseif (im <= -2.5)
		tmp = t_1;
	elseif (im <= 1.5e+29)
		tmp = 0.25;
	elseif (im <= 1.7e+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 * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im * N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.7e+154], t$95$0, If[LessEqual[im, -2.5], t$95$1, If[LessEqual[im, 1.5e+29], 0.25, If[LessEqual[im, 1.7e+154], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;im \leq 1.5 \cdot 10^{+29}:\\
\;\;\;\;0.25\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.69999999999999987e154 or 1.69999999999999987e154 < 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)} \]
    7. Taylor expanded in re around 0 77.4%

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

    if -1.69999999999999987e154 < im < -2.5 or 1.5e29 < im < 1.69999999999999987e154

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified7.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 7.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow224.5%

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

        \[\leadsto im \cdot \left(0.5 \cdot \mathsf{fma}\left(\color{blue}{\left(-0.5 \cdot re\right) \cdot re}, im, im\right)\right) \]
    9. Simplified24.5%

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(\left(-0.5 \cdot re\right) \cdot re, im, im\right)}\right) \]
    10. Applied egg-rr18.7%

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

    if -2.5 < im < 1.5e29

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.7 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq -2.5:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right)\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{+29}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 10: 48.2% accurate, 23.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.6 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\

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

\mathbf{else}:\\
\;\;\;\;re \cdot re - re\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < 1.59999999999999991e59

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

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

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

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

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

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

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

    if 1.59999999999999991e59 < re < 2.7999999999999998e195

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow238.7%

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

        \[\leadsto im \cdot \left(0.5 \cdot \mathsf{fma}\left(\color{blue}{\left(-0.5 \cdot re\right) \cdot re}, im, im\right)\right) \]
    9. Simplified38.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.7999999999999998e195 < 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.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified76.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 28.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow20.9%

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

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

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(\left(-0.5 \cdot re\right) \cdot re, im, im\right)}\right) \]
    10. Applied egg-rr50.9%

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

        \[\leadsto \color{blue}{re \cdot re - re} \]
    12. Simplified50.9%

      \[\leadsto \color{blue}{re \cdot re - re} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification50.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1.6 \cdot 10^{+59}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\ \mathbf{elif}\;re \leq 2.8 \cdot 10^{+195}:\\ \;\;\;\;im \cdot \left(-0.25 \cdot \left(re \cdot \left(re \cdot im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot re - re\\ \end{array} \]

Alternative 11: 27.5% accurate, 27.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \left(0.5 \cdot im\right)\\ \mathbf{if}\;im \leq -2.7 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2.3 \cdot 10^{+28}:\\ \;\;\;\;re \cdot re - re\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;0.25\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (* 0.5 im))))
   (if (<= im -2.7e+151)
     t_0
     (if (<= im -2.3e+28)
       (- (* re re) re)
       (if (<= im 2000000000.0) 0.25 t_0)))))
double code(double re, double im) {
	double t_0 = im * (0.5 * im);
	double tmp;
	if (im <= -2.7e+151) {
		tmp = t_0;
	} else if (im <= -2.3e+28) {
		tmp = (re * re) - re;
	} else if (im <= 2000000000.0) {
		tmp = 0.25;
	} 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 * im)
    if (im <= (-2.7d+151)) then
        tmp = t_0
    else if (im <= (-2.3d+28)) then
        tmp = (re * re) - re
    else if (im <= 2000000000.0d0) then
        tmp = 0.25d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = im * (0.5 * im);
	double tmp;
	if (im <= -2.7e+151) {
		tmp = t_0;
	} else if (im <= -2.3e+28) {
		tmp = (re * re) - re;
	} else if (im <= 2000000000.0) {
		tmp = 0.25;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (0.5 * im)
	tmp = 0
	if im <= -2.7e+151:
		tmp = t_0
	elif im <= -2.3e+28:
		tmp = (re * re) - re
	elif im <= 2000000000.0:
		tmp = 0.25
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(0.5 * im))
	tmp = 0.0
	if (im <= -2.7e+151)
		tmp = t_0;
	elseif (im <= -2.3e+28)
		tmp = Float64(Float64(re * re) - re);
	elseif (im <= 2000000000.0)
		tmp = 0.25;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (0.5 * im);
	tmp = 0.0;
	if (im <= -2.7e+151)
		tmp = t_0;
	elseif (im <= -2.3e+28)
		tmp = (re * re) - re;
	elseif (im <= 2000000000.0)
		tmp = 0.25;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.7e+151], t$95$0, If[LessEqual[im, -2.3e+28], N[(N[(re * re), $MachinePrecision] - re), $MachinePrecision], If[LessEqual[im, 2000000000.0], 0.25, t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -2.3 \cdot 10^{+28}:\\
\;\;\;\;re \cdot re - re\\

\mathbf{elif}\;im \leq 2000000000:\\
\;\;\;\;0.25\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.7000000000000001e151 or 2e9 < 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 62.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified62.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 62.2%

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

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

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

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

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

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

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

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

    if -2.7000000000000001e151 < im < -2.29999999999999984e28

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

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow222.6%

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

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

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(\left(-0.5 \cdot re\right) \cdot re, im, im\right)}\right) \]
    10. Applied egg-rr17.4%

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

        \[\leadsto \color{blue}{re \cdot re - re} \]
    12. Simplified17.4%

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

    if -2.29999999999999984e28 < im < 2e9

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.7 \cdot 10^{+151}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq -2.3 \cdot 10^{+28}:\\ \;\;\;\;re \cdot re - re\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;0.25\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 12: 27.2% accurate, 27.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := im \cdot \left(0.5 \cdot im\right)\\ \mathbf{if}\;im \leq -1.45 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2.1 \cdot 10^{+14}:\\ \;\;\;\;im \cdot \left(re \cdot \left(-0.5\right)\right)\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;0.25\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* im (* 0.5 im))))
   (if (<= im -1.45e+154)
     t_0
     (if (<= im -2.1e+14)
       (* im (* re (- 0.5)))
       (if (<= im 2000000000.0) 0.25 t_0)))))
double code(double re, double im) {
	double t_0 = im * (0.5 * im);
	double tmp;
	if (im <= -1.45e+154) {
		tmp = t_0;
	} else if (im <= -2.1e+14) {
		tmp = im * (re * -0.5);
	} else if (im <= 2000000000.0) {
		tmp = 0.25;
	} 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 * im)
    if (im <= (-1.45d+154)) then
        tmp = t_0
    else if (im <= (-2.1d+14)) then
        tmp = im * (re * -0.5d0)
    else if (im <= 2000000000.0d0) then
        tmp = 0.25d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = im * (0.5 * im);
	double tmp;
	if (im <= -1.45e+154) {
		tmp = t_0;
	} else if (im <= -2.1e+14) {
		tmp = im * (re * -0.5);
	} else if (im <= 2000000000.0) {
		tmp = 0.25;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = im * (0.5 * im)
	tmp = 0
	if im <= -1.45e+154:
		tmp = t_0
	elif im <= -2.1e+14:
		tmp = im * (re * -0.5)
	elif im <= 2000000000.0:
		tmp = 0.25
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(im * Float64(0.5 * im))
	tmp = 0.0
	if (im <= -1.45e+154)
		tmp = t_0;
	elseif (im <= -2.1e+14)
		tmp = Float64(im * Float64(re * Float64(-0.5)));
	elseif (im <= 2000000000.0)
		tmp = 0.25;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = im * (0.5 * im);
	tmp = 0.0;
	if (im <= -1.45e+154)
		tmp = t_0;
	elseif (im <= -2.1e+14)
		tmp = im * (re * -0.5);
	elseif (im <= 2000000000.0)
		tmp = 0.25;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.45e+154], t$95$0, If[LessEqual[im, -2.1e+14], N[(im * N[(re * (-0.5)), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2000000000.0], 0.25, t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;im \leq 2000000000:\\
\;\;\;\;0.25\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.4499999999999999e154 or 2e9 < 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 61.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified61.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 61.8%

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

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

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

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

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

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

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

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

    if -1.4499999999999999e154 < im < -2.1e14

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified8.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 8.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(\left(-0.5 \cdot re\right) \cdot re, im, im\right)}\right) \]
    10. Applied egg-rr16.2%

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\left(-1 \cdot re\right)}\right) \]
    11. Step-by-step derivation
      1. neg-mul-116.2%

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\left(-re\right)}\right) \]
    12. Simplified16.2%

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

    if -2.1e14 < im < 2e9

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.45 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq -2.1 \cdot 10^{+14}:\\ \;\;\;\;im \cdot \left(re \cdot \left(-0.5\right)\right)\\ \mathbf{elif}\;im \leq 2000000000:\\ \;\;\;\;0.25\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 13: 26.6% accurate, 33.7× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

    if -2.60000000000000009 < im < 2e9

    1. Initial program 100.0%

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

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

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

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

Alternative 14: 48.2% accurate, 34.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.6 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 1.59999999999999991e59

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

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

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

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

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

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

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

    if 1.59999999999999991e59 < 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 66.9%

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot {im}^{2}\right) + \cos re} \]
    3. Simplified66.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 26.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(-0.5 \cdot {re}^{2}, im, im\right)}\right) \]
      3. unpow228.6%

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

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

      \[\leadsto im \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(\left(-0.5 \cdot re\right) \cdot re, im, im\right)}\right) \]
    10. Applied egg-rr26.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1.6 \cdot 10^{+59}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right)\\ \end{array} \]

Alternative 15: 8.2% accurate, 308.0× speedup?

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

\\
0.25
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto 0.25 \]

Reproduce

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