math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 12.3s
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: 92.1% accurate, 1.4× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(2 + \left(im \cdot im + \left(t_1 + 0.00023919753086419754\right)\right)\right)\\


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

    1. Initial program 100.0%

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

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

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

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

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

    if 0.680000000000000049 < im < 1.99999999999999997e73

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

      \[\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. Step-by-step derivation
      1. associate-*r*5.3%

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

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

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

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

    if 1.99999999999999997e73 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(im \cdot im + \color{blue}{\left(0.08333333333333333 \cdot {im}^{4} + 0.002777777777777778 \cdot {im}^{6}\right)}\right)\right) \]
    7. Applied egg-rr98.2%

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

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

Alternative 3: 92.1% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

    if 0.680000000000000049 < im < 1.99999999999999997e73

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

      \[\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. Step-by-step derivation
      1. associate-*r*5.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.68 \lor \neg \left(im \leq 2 \cdot 10^{+73}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot im\right) + 0.08333333333333333 \cdot {im}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\ \end{array} \]

Alternative 4: 84.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;im \leq 4.5 \cdot 10^{+152}:\\
\;\;\;\;\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}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 0.660000000000000031

    1. Initial program 100.0%

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

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

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

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

    if 0.660000000000000031 < im < 4.5000000000000001e152

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

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

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

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

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

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

    if 4.5000000000000001e152 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.66:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 4.5 \cdot 10^{+152}:\\ \;\;\;\;\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 5: 84.9% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;im \leq 2.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}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 0.660000000000000031

    1. Initial program 100.0%

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

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

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

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

    if 0.660000000000000031 < im < 2.09999999999999994e154

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

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

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

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

    if 2.09999999999999994e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.66:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 2.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 6: 78.2% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 + im \cdot im\\ \mathbf{if}\;im \leq 3800000 \lor \neg \left(im \leq 2.15 \cdot 10^{+136}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, t_0, -0.25 \cdot \left(t_0 \cdot \left(re \cdot re\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (+ 2.0 (* im im))))
   (if (or (<= im 3800000.0) (not (<= im 2.15e+136)))
     (* (* 0.5 (cos re)) t_0)
     (fma 0.5 t_0 (* -0.25 (* t_0 (* re re)))))))
double code(double re, double im) {
	double t_0 = 2.0 + (im * im);
	double tmp;
	if ((im <= 3800000.0) || !(im <= 2.15e+136)) {
		tmp = (0.5 * cos(re)) * t_0;
	} else {
		tmp = fma(0.5, t_0, (-0.25 * (t_0 * (re * re))));
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(2.0 + Float64(im * im))
	tmp = 0.0
	if ((im <= 3800000.0) || !(im <= 2.15e+136))
		tmp = Float64(Float64(0.5 * cos(re)) * t_0);
	else
		tmp = fma(0.5, t_0, Float64(-0.25 * Float64(t_0 * Float64(re * re))));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[im, 3800000.0], N[Not[LessEqual[im, 2.15e+136]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(0.5 * t$95$0 + N[(-0.25 * N[(t$95$0 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 3800000 \lor \neg \left(im \leq 2.15 \cdot 10^{+136}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, t_0, -0.25 \cdot \left(t_0 \cdot \left(re \cdot re\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 3.8e6 or 2.1499999999999999e136 < 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 87.6%

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

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

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

    if 3.8e6 < im < 2.1499999999999999e136

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified36.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 3800000 \lor \neg \left(im \leq 2.15 \cdot 10^{+136}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(2 + im \cdot im\right) \cdot \left(re \cdot re\right)\right)\right)\\ \end{array} \]

Alternative 7: 78.0% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 5800000000 \lor \neg \left(im \leq 2.15 \cdot 10^{+136}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\

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


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

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

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

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

    if 5.8e9 < im < 2.1499999999999999e136

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified36.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 34.7%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified34.7%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around inf 34.7%

      \[\leadsto \color{blue}{-0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    12. Step-by-step derivation
      1. unpow234.7%

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

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

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

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

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

Alternative 8: 65.6% accurate, 2.8× speedup?

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

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

\mathbf{elif}\;im \leq 2.15 \cdot 10^{+136}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(-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}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 8.5e6

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

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

    if 8.5e6 < im < 2.1499999999999999e136

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified36.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 34.7%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified34.7%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around inf 34.7%

      \[\leadsto \color{blue}{-0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    12. Step-by-step derivation
      1. unpow234.7%

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

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

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

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

    if 2.1499999999999999e136 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 8500000:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 2.15 \cdot 10^{+136}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(-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 9: 62.3% accurate, 3.0× speedup?

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

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

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

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


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

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

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

    if 5e8 < im < 2.1499999999999999e136

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified36.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 34.7%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified34.7%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around inf 34.7%

      \[\leadsto \color{blue}{-0.25 \cdot \left({re}^{2} \cdot {im}^{2}\right)} \]
    12. Step-by-step derivation
      1. unpow234.7%

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

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

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

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

    if 2.1499999999999999e136 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

Alternative 10: 49.3% accurate, 27.8× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 7.2e5 < 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 78.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 31.2%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified31.2%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around inf 31.1%

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

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

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

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

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

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

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

        \[\leadsto re \cdot \left(\color{blue}{\left(re \cdot -0.25\right)} \cdot \left(im \cdot im\right)\right) \]
    13. Simplified31.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 720000:\\ \;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(\left(im \cdot im\right) \cdot \left(re \cdot -0.25\right)\right)\\ \end{array} \]

Alternative 11: 39.8% accurate, 33.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 8500000:\\
\;\;\;\;1\\

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

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{-2 \cdot \cos re}{-2 \cdot \cos re + \color{blue}{0}} \]
      2. +-rgt-identity35.7%

        \[\leadsto \frac{-2 \cdot \cos re}{\color{blue}{-2 \cdot \cos re}} \]
      3. *-inverses35.7%

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

      \[\leadsto \color{blue}{1} \]

    if 8.5e6 < im < 1.90000000000000007e136

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified36.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 34.7%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified34.7%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around 0 24.3%

      \[\leadsto \color{blue}{-0.5 \cdot {re}^{2}} \]
    12. Step-by-step derivation
      1. *-commutative24.3%

        \[\leadsto \color{blue}{{re}^{2} \cdot -0.5} \]
      2. unpow224.3%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot -0.5 \]
    13. Simplified24.3%

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

    if 1.90000000000000007e136 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 48.8% accurate, 34.0× speedup?

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

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

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


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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-in48.8%

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

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

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

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

    if 3.2999999999999997e160 < 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.4%

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right) + -0.25 \cdot \left(\left(2 + {im}^{2}\right) \cdot {re}^{2}\right)} \]
    6. Step-by-step derivation
      1. fma-def12.4%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified12.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in re around inf 35.3%

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

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

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

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

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

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

        \[\leadsto \left(-0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \mathsf{fma}\left(im, im, 2\right) \]
    10. Simplified35.3%

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im, im, 2\right)} \]
    11. Taylor expanded in im around 0 35.3%

      \[\leadsto \color{blue}{-0.5 \cdot {re}^{2}} \]
    12. Step-by-step derivation
      1. *-commutative35.3%

        \[\leadsto \color{blue}{{re}^{2} \cdot -0.5} \]
      2. unpow235.3%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot -0.5 \]
    13. Simplified35.3%

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

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

Alternative 13: 48.8% accurate, 34.0× speedup?

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

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

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


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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-in48.8%

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

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

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

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

    if 3.2999999999999997e160 < 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.4%

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(2 + {im}^{2}\right) + -0.25 \cdot \left(\left(2 + {im}^{2}\right) \cdot {re}^{2}\right)} \]
    6. Step-by-step derivation
      1. fma-def12.4%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + \color{blue}{im \cdot im}\right)\right)\right) \]
    7. Simplified12.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, 2 + im \cdot im, -0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(2 + im \cdot im\right)\right)\right)} \]
    8. Taylor expanded in im around 0 35.3%

      \[\leadsto \color{blue}{1 + -0.5 \cdot {re}^{2}} \]
    9. Step-by-step derivation
      1. *-commutative35.3%

        \[\leadsto 1 + \color{blue}{{re}^{2} \cdot -0.5} \]
      2. unpow235.3%

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

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

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

Alternative 14: 38.7% accurate, 43.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0145:\\
\;\;\;\;1\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{-2 \cdot \cos re}{-2 \cdot \cos re + \left(-2 \cdot \cos re - -2 \cdot \cos re\right)}} \]
    3. Step-by-step derivation
      1. +-inverses36.5%

        \[\leadsto \frac{-2 \cdot \cos re}{-2 \cdot \cos re + \color{blue}{0}} \]
      2. +-rgt-identity36.5%

        \[\leadsto \frac{-2 \cdot \cos re}{\color{blue}{-2 \cdot \cos re}} \]
      3. *-inverses36.5%

        \[\leadsto \color{blue}{1} \]
    4. Simplified36.5%

      \[\leadsto \color{blue}{1} \]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 29.7% accurate, 308.0× speedup?

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

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

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

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

      \[\leadsto \frac{-2 \cdot \cos re}{-2 \cdot \cos re + \color{blue}{0}} \]
    2. +-rgt-identity27.3%

      \[\leadsto \frac{-2 \cdot \cos re}{\color{blue}{-2 \cdot \cos re}} \]
    3. *-inverses27.3%

      \[\leadsto \color{blue}{1} \]
  4. Simplified27.3%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification27.3%

    \[\leadsto 1 \]

Reproduce

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