math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 7.5s
Alternatives: 12
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 12 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: 87.2% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 2.00000020000000012

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if 2.00000020000000012 < (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

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

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

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

Alternative 3: 90.4% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;im \leq -0.00046 \lor \neg \left(im \leq 0.0006\right):\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -4.00000000000000003e155 < im < -4.6000000000000001e-4 or 5.99999999999999947e-4 < im

    1. Initial program 100.0%

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

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

    if -4.6000000000000001e-4 < im < 5.99999999999999947e-4

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4 \cdot 10^{+155}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -0.00046 \lor \neg \left(im \leq 0.0006\right):\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\ \end{array} \]

Alternative 4: 80.1% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq -2.8 \cdot 10^{+22}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.39999999999999996e141 or 1.8999999999999999e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -1.39999999999999996e141 < im < -2.8e22 or 19500 < im < 1.8999999999999999e154

    1. Initial program 100.0%

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

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

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(1 + -0.5 \cdot \left(re \cdot re\right)\right)}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    4. Taylor expanded in re around inf 24.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{re \cdot \left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u10.0%

        \[\leadsto re \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)\right)} \]
      2. expm1-udef10.0%

        \[\leadsto re \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)} - 1\right)} \]
      3. cosh-undef10.0%

        \[\leadsto re \cdot \left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \color{blue}{\left(2 \cdot \cosh im\right)}\right)\right)} - 1\right) \]
    8. Applied egg-rr10.0%

      \[\leadsto re \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(2 \cdot \cosh im\right)\right)\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def10.0%

        \[\leadsto re \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(2 \cdot \cosh im\right)\right)\right)\right)} \]
      2. expm1-log1p24.0%

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

        \[\leadsto re \cdot \left(re \cdot \color{blue}{\left(\left(-0.25 \cdot 2\right) \cdot \cosh im\right)}\right) \]
      4. metadata-eval24.0%

        \[\leadsto re \cdot \left(re \cdot \left(\color{blue}{-0.5} \cdot \cosh im\right)\right) \]
    10. Simplified24.0%

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

    if -2.8e22 < im < 19500

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} + \cos re \]
    7. Step-by-step derivation
      1. unpow295.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.4 \cdot 10^{+141}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -2.8 \cdot 10^{+22}:\\ \;\;\;\;re \cdot \left(re \cdot \left(-0.5 \cdot \cosh im\right)\right)\\ \mathbf{elif}\;im \leq 19500:\\ \;\;\;\;\cos re + im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;re \cdot \left(re \cdot \left(-0.5 \cdot \cosh im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \end{array} \]

Alternative 5: 77.5% accurate, 2.7× speedup?

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

    if -7.40000000000000006e140 < im < -2.8e22

    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}{\left(1 + -0.5 \cdot {re}^{2}\right)}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    3. Simplified73.1%

      \[\leadsto \left(0.5 \cdot \color{blue}{\left(1 + -0.5 \cdot \left(re \cdot re\right)\right)}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    4. Taylor expanded in re around inf 26.9%

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

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

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

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

        \[\leadsto \color{blue}{re \cdot \left(re \cdot \left(\left(e^{im} + e^{-im}\right) \cdot -0.25\right)\right)} \]
      5. *-commutative26.9%

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

      \[\leadsto \color{blue}{re \cdot \left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u11.5%

        \[\leadsto re \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)\right)} \]
      2. expm1-udef11.5%

        \[\leadsto re \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(e^{im} + e^{-im}\right)\right)\right)} - 1\right)} \]
      3. cosh-undef11.5%

        \[\leadsto re \cdot \left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \color{blue}{\left(2 \cdot \cosh im\right)}\right)\right)} - 1\right) \]
    8. Applied egg-rr11.5%

      \[\leadsto re \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(2 \cdot \cosh im\right)\right)\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def11.5%

        \[\leadsto re \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re \cdot \left(-0.25 \cdot \left(2 \cdot \cosh im\right)\right)\right)\right)} \]
      2. expm1-log1p26.9%

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

        \[\leadsto re \cdot \left(re \cdot \color{blue}{\left(\left(-0.25 \cdot 2\right) \cdot \cosh im\right)}\right) \]
      4. metadata-eval26.9%

        \[\leadsto re \cdot \left(re \cdot \left(\color{blue}{-0.5} \cdot \cosh im\right)\right) \]
    10. Simplified26.9%

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

    if -2.8e22 < im < 1.44999999999999996

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -7.4 \cdot 10^{+140}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -2.8 \cdot 10^{+22}:\\ \;\;\;\;re \cdot \left(re \cdot \left(-0.5 \cdot \cosh im\right)\right)\\ \mathbf{elif}\;im \leq 1.45:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\ \end{array} \]

Alternative 6: 75.8% accurate, 2.8× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -1.3999999999999999 < im < 1.44999999999999996

    1. Initial program 100.0%

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

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

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

Alternative 7: 76.2% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 71.6% accurate, 2.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.6000000000000001e-4

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.6000000000000001e-4 < im < 4.4999999999999999e-4

    1. Initial program 100.0%

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

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

    if 4.4999999999999999e-4 < 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 54.1%

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

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

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

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

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

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

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

Alternative 9: 46.8% accurate, 33.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.45 \lor \neg \left(im \leq 1.45\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 < -1.44999999999999996 or 1.44999999999999996 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot {im}^{2}} + \cos re \]
    7. Step-by-step derivation
      1. unpow243.0%

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

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

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

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

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

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

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

    if -1.44999999999999996 < im < 1.44999999999999996

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos re} \]
    3. Taylor expanded in re around 0 50.1%

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

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

Alternative 10: 46.9% accurate, 44.0× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 11: 8.0% accurate, 308.0× speedup?

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

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

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

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

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

    \[\leadsto 0.25 \]

Alternative 12: 28.0% accurate, 308.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\cos re} \]
  3. Taylor expanded in re around 0 29.4%

    \[\leadsto \color{blue}{1} \]
  4. Final simplification29.4%

    \[\leadsto 1 \]

Reproduce

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