math.cos on complex, real part

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 2: 93.3% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

    if 0.996 < (cos.f64 re)

    1. Initial program 100.0%

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

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

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

Alternative 3: 93.2% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(\color{blue}{\left({im}^{2} \cdot {im}^{2}\right)} \cdot 0.08333333333333333 + im \cdot im\right)\right) \]
      5. pow-prod-down89.6%

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr89.0%

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

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

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

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

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

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

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

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

    if 0.996 < (cos.f64 re)

    1. Initial program 100.0%

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

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

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

Alternative 4: 81.9% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)\right)\\


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

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

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

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

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

    if 0.999998999999999971 < (cos.f64 re)

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    3. Taylor expanded in im around 0 85.2%

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

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

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

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

Alternative 5: 87.7% accurate, 2.6× speedup?

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

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

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

    \[\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. unpow287.2%

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(\color{blue}{\left(im \cdot im\right) \cdot \left(\left(im \cdot im\right) \cdot 0.08333333333333333\right)} + im \cdot im\right)\right) \]
    8. fma-def86.9%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
  6. Applied egg-rr86.9%

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

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

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

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

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

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

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

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\left(im \cdot \left(im \cdot 0.08333333333333333\right) + 1\right) \cdot \left(im \cdot im\right)}\right) \]
  9. Final simplification86.9%

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

Alternative 6: 77.7% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -1.45:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;2 \cdot \left(re \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
   (if (<= im -1.45)
     t_0
     (if (<= im 700.0)
       (cos re)
       (if (<= im 1.35e+154) (* 2.0 (* re (* re (fma im im 2.0)))) t_0)))))
double code(double re, double im) {
	double t_0 = cos(re) * (0.5 * (im * im));
	double tmp;
	if (im <= -1.45) {
		tmp = t_0;
	} else if (im <= 700.0) {
		tmp = cos(re);
	} else if (im <= 1.35e+154) {
		tmp = 2.0 * (re * (re * fma(im, im, 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im)))
	tmp = 0.0
	if (im <= -1.45)
		tmp = t_0;
	elseif (im <= 700.0)
		tmp = cos(re);
	elseif (im <= 1.35e+154)
		tmp = Float64(2.0 * Float64(re * Float64(re * fma(im, im, 2.0))));
	else
		tmp = t_0;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.45], t$95$0, If[LessEqual[im, 700.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(2.0 * N[(re * N[(re * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{if}\;im \leq -1.45:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;2 \cdot \left(re \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\right)\\

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


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

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

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

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

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

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

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

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

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

    if -1.44999999999999996 < im < 700

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr99.5%

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

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

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

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

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

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

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

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

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

    if 700 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \left(-2 + -2 \cdot \color{blue}{\left(1 + \left(re \cdot re\right) \cdot -2\right)}\right)\right) \cdot \left(2 + im \cdot im\right) \]
    11. Taylor expanded in re around inf 36.1%

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

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

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

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

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

        \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)}\right) \]
      6. associate-*l*36.1%

        \[\leadsto 2 \cdot \color{blue}{\left(re \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\right)} \]
    13. Simplified36.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.45:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;2 \cdot \left(re \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 7: 77.7% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{if}\;im \leq -1.45:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 3.05 \cdot 10^{+153}:\\
\;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.44999999999999996 or 3.0499999999999999e153 < 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 67.0%

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

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

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

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

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

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

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

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

    if -1.44999999999999996 < im < 720

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr99.5%

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

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

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

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

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

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

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

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

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

    if 720 < im < 3.0499999999999999e153

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \left(-2 + -2 \cdot \color{blue}{\left(1 + \left(re \cdot re\right) \cdot -2\right)}\right)\right) \cdot \left(2 + im \cdot im\right) \]
    11. Taylor expanded in re around inf 36.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.45:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 720:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 3.05 \cdot 10^{+153}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 8: 76.2% accurate, 2.8× speedup?

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

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

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

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

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

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

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

Alternative 9: 73.3% accurate, 2.9× speedup?

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

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

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

\mathbf{elif}\;im \leq 1.2 \cdot 10^{+83}:\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -9.9999999999999998e23 or 1.19999999999999996e83 < 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 65.3%

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

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

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

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

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

    if -9.9999999999999998e23 < im < 1100

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(\color{blue}{\left(im \cdot im\right) \cdot \left(\left(im \cdot im\right) \cdot 0.08333333333333333\right)} + im \cdot im\right)\right) \]
      8. fma-def95.5%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr95.5%

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

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

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

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

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

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

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

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

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

    if 1100 < im < 1.19999999999999996e83

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \left(-2 + -2 \cdot \color{blue}{\left(1 + \left(re \cdot re\right) \cdot -2\right)}\right)\right) \cdot \left(2 + im \cdot im\right) \]
    11. Taylor expanded in re around inf 37.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1 \cdot 10^{+24}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\right)\\ \mathbf{elif}\;im \leq 1100:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+83}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\right)\\ \end{array} \]

Alternative 10: 49.1% accurate, 16.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 + im \cdot im\\ \mathbf{if}\;im \leq 520:\\ \;\;\;\;0.5 \cdot t_0\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+83}:\\ \;\;\;\;t_0 \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(0.5 \cdot \left(1 + -0.5 \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 (<= im 520.0)
     (* 0.5 t_0)
     (if (<= im 5e+83)
       (* t_0 (* 0.5 (* re (* re 4.0))))
       (* t_0 (* 0.5 (+ 1.0 (* -0.5 (* re re)))))))))
double code(double re, double im) {
	double t_0 = 2.0 + (im * im);
	double tmp;
	if (im <= 520.0) {
		tmp = 0.5 * t_0;
	} else if (im <= 5e+83) {
		tmp = t_0 * (0.5 * (re * (re * 4.0)));
	} else {
		tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 2.0d0 + (im * im)
    if (im <= 520.0d0) then
        tmp = 0.5d0 * t_0
    else if (im <= 5d+83) then
        tmp = t_0 * (0.5d0 * (re * (re * 4.0d0)))
    else
        tmp = t_0 * (0.5d0 * (1.0d0 + ((-0.5d0) * (re * re))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 2.0 + (im * im);
	double tmp;
	if (im <= 520.0) {
		tmp = 0.5 * t_0;
	} else if (im <= 5e+83) {
		tmp = t_0 * (0.5 * (re * (re * 4.0)));
	} else {
		tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = 2.0 + (im * im)
	tmp = 0
	if im <= 520.0:
		tmp = 0.5 * t_0
	elif im <= 5e+83:
		tmp = t_0 * (0.5 * (re * (re * 4.0)))
	else:
		tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))))
	return tmp
function code(re, im)
	t_0 = Float64(2.0 + Float64(im * im))
	tmp = 0.0
	if (im <= 520.0)
		tmp = Float64(0.5 * t_0);
	elseif (im <= 5e+83)
		tmp = Float64(t_0 * Float64(0.5 * Float64(re * Float64(re * 4.0))));
	else
		tmp = Float64(t_0 * Float64(0.5 * Float64(1.0 + Float64(-0.5 * Float64(re * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 2.0 + (im * im);
	tmp = 0.0;
	if (im <= 520.0)
		tmp = 0.5 * t_0;
	elseif (im <= 5e+83)
		tmp = t_0 * (0.5 * (re * (re * 4.0)));
	else
		tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 520.0], N[(0.5 * t$95$0), $MachinePrecision], If[LessEqual[im, 5e+83], N[(t$95$0 * N[(0.5 * N[(re * N[(re * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(0.5 * N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 520:\\
\;\;\;\;0.5 \cdot t_0\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+83}:\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\

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


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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    3. Taylor expanded in im around 0 48.3%

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

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

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

    if 520 < im < 5.00000000000000029e83

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \left(-2 + -2 \cdot \color{blue}{\left(1 + \left(re \cdot re\right) \cdot -2\right)}\right)\right) \cdot \left(2 + im \cdot im\right) \]
    11. Taylor expanded in re around inf 37.5%

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

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

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

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

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

    if 5.00000000000000029e83 < 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 77.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 520:\\ \;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+83}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\right)\\ \end{array} \]

Alternative 11: 48.2% accurate, 27.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -3.4499999999999999e25

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(1 + -0.5 \cdot \left(re \cdot re\right)\right)}\right) \cdot \left(2 + im \cdot im\right) \]
    8. Taylor expanded in im around inf 26.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(0.5 \cdot \mathsf{fma}\left(-0.5, re \cdot re, 1\right)\right)\right)} \]
      8. fma-udef26.2%

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

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

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

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

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

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

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

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

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

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

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

    if -3.4499999999999999e25 < re

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    3. Taylor expanded in im around 0 54.2%

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

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

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

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

Alternative 12: 46.7% accurate, 33.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(1 + -0.5 \cdot \left(re \cdot re\right)\right)}\right) \cdot \left(2 + im \cdot im\right) \]
    8. Taylor expanded in im around inf 48.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{{im}^{2} \cdot 0.5} \]
      2. unpow239.4%

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

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

    if -2e12 < im < 1.3999999999999999

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    3. Taylor expanded in im around 0 49.9%

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

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

Alternative 13: 3.9% accurate, 308.0× speedup?

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

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

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

    \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
  3. Applied egg-rr4.2%

    \[\leadsto \left(0.5 \cdot 1\right) \cdot \color{blue}{-2} \]
  4. Final simplification4.2%

    \[\leadsto -1 \]

Alternative 14: 8.0% accurate, 308.0× speedup?

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

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

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

    \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
  3. Applied egg-rr8.2%

    \[\leadsto \left(0.5 \cdot 1\right) \cdot \color{blue}{0.5} \]
  4. Final simplification8.2%

    \[\leadsto 0.25 \]

Alternative 15: 9.1% accurate, 308.0× speedup?

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

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

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

    \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
  3. Applied egg-rr9.2%

    \[\leadsto \left(0.5 \cdot 1\right) \cdot \color{blue}{1.5} \]
  4. Final simplification9.2%

    \[\leadsto 0.75 \]

Alternative 16: 28.2% accurate, 308.0× speedup?

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

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

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

    \[\leadsto \left(0.5 \cdot \color{blue}{1}\right) \cdot \left(e^{-im} + e^{im}\right) \]
  3. Taylor expanded in im around 0 27.7%

    \[\leadsto \left(0.5 \cdot 1\right) \cdot \color{blue}{2} \]
  4. Final simplification27.7%

    \[\leadsto 1 \]

Reproduce

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