math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 6.5s
Alternatives: 13
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 13 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: 83.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 0.0134 \lor \neg \left(im \leq 1.5 \cdot 10^{+154}\right):\\ \;\;\;\;\mathsf{fma}\left(0.5, \cos re \cdot \left(im \cdot im\right), \cos re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im 0.0134) (not (<= im 1.5e+154)))
   (fma 0.5 (* (cos re) (* im im)) (cos re))
   (* (+ (exp (- im)) (exp im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
	double tmp;
	if ((im <= 0.0134) || !(im <= 1.5e+154)) {
		tmp = fma(0.5, (cos(re) * (im * im)), cos(re));
	} else {
		tmp = (exp(-im) + exp(im)) * (0.5 + (-0.25 * (re * re)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if ((im <= 0.0134) || !(im <= 1.5e+154))
		tmp = fma(0.5, Float64(cos(re) * Float64(im * im)), cos(re));
	else
		tmp = Float64(Float64(exp(Float64(-im)) + exp(im)) * Float64(0.5 + Float64(-0.25 * Float64(re * re))));
	end
	return tmp
end
code[re_, im_] := If[Or[LessEqual[im, 0.0134], N[Not[LessEqual[im, 1.5e+154]], $MachinePrecision]], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] + N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0134 \lor \neg \left(im \leq 1.5 \cdot 10^{+154}\right):\\
\;\;\;\;\mathsf{fma}\left(0.5, \cos re \cdot \left(im \cdot im\right), \cos re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 0.0134000000000000005 or 1.50000000000000013e154 < 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 83.5%

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

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

    if 0.0134000000000000005 < im < 1.50000000000000013e154

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

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

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

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

Alternative 3: 77.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} + e^{im}\\ \mathbf{if}\;im \leq 0.0065:\\ \;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+122} \lor \neg \left(im \leq 2 \cdot 10^{+198}\right):\\ \;\;\;\;t_0 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\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 (<= im 0.0065)
     (+ (cos re) (* 0.5 (* im im)))
     (if (or (<= im 6.6e+122) (not (<= im 2e+198)))
       (* t_0 (+ 0.5 (* -0.25 (* re re))))
       (* 0.5 t_0)))))
double code(double re, double im) {
	double t_0 = exp(-im) + exp(im);
	double tmp;
	if (im <= 0.0065) {
		tmp = cos(re) + (0.5 * (im * im));
	} else if ((im <= 6.6e+122) || !(im <= 2e+198)) {
		tmp = t_0 * (0.5 + (-0.25 * (re * re)));
	} 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 (im <= 0.0065d0) then
        tmp = cos(re) + (0.5d0 * (im * im))
    else if ((im <= 6.6d+122) .or. (.not. (im <= 2d+198))) then
        tmp = t_0 * (0.5d0 + ((-0.25d0) * (re * re)))
    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 (im <= 0.0065) {
		tmp = Math.cos(re) + (0.5 * (im * im));
	} else if ((im <= 6.6e+122) || !(im <= 2e+198)) {
		tmp = t_0 * (0.5 + (-0.25 * (re * re)));
	} else {
		tmp = 0.5 * t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) + math.exp(im)
	tmp = 0
	if im <= 0.0065:
		tmp = math.cos(re) + (0.5 * (im * im))
	elif (im <= 6.6e+122) or not (im <= 2e+198):
		tmp = t_0 * (0.5 + (-0.25 * (re * re)))
	else:
		tmp = 0.5 * t_0
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) + exp(im))
	tmp = 0.0
	if (im <= 0.0065)
		tmp = Float64(cos(re) + Float64(0.5 * Float64(im * im)));
	elseif ((im <= 6.6e+122) || !(im <= 2e+198))
		tmp = Float64(t_0 * Float64(0.5 + Float64(-0.25 * Float64(re * re))));
	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 (im <= 0.0065)
		tmp = cos(re) + (0.5 * (im * im));
	elseif ((im <= 6.6e+122) || ~((im <= 2e+198)))
		tmp = t_0 * (0.5 + (-0.25 * (re * re)));
	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[im, 0.0065], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 6.6e+122], N[Not[LessEqual[im, 2e+198]], $MachinePrecision]], N[(t$95$0 * N[(0.5 + N[(-0.25 * N[(re * re), $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}\;im \leq 0.0065:\\
\;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;im \leq 6.6 \cdot 10^{+122} \lor \neg \left(im \leq 2 \cdot 10^{+198}\right):\\
\;\;\;\;t_0 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\

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


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

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

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

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

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

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

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

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

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

    if 0.0064999999999999997 < im < 6.5999999999999998e122 or 2.00000000000000004e198 < 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 2.2%

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

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

    if 6.5999999999999998e122 < im < 2.00000000000000004e198

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.0065:\\ \;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+122} \lor \neg \left(im \leq 2 \cdot 10^{+198}\right):\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \]

Alternative 4: 77.8% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

    if 0.0018500000000000001 < 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 68.8%

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

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

Alternative 5: 77.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq 380:\\ \;\;\;\;\cos re + t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (* im im))))
   (if (<= im 380.0) (+ (cos re) t_0) (log1p (expm1 t_0)))))
double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double tmp;
	if (im <= 380.0) {
		tmp = cos(re) + t_0;
	} else {
		tmp = log1p(expm1(t_0));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = 0.5 * (im * im);
	double tmp;
	if (im <= 380.0) {
		tmp = Math.cos(re) + t_0;
	} else {
		tmp = Math.log1p(Math.expm1(t_0));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * (im * im)
	tmp = 0
	if im <= 380.0:
		tmp = math.cos(re) + t_0
	else:
		tmp = math.log1p(math.expm1(t_0))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 * Float64(im * im))
	tmp = 0.0
	if (im <= 380.0)
		tmp = Float64(cos(re) + t_0);
	else
		tmp = log1p(expm1(t_0));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 380.0], N[(N[Cos[re], $MachinePrecision] + t$95$0), $MachinePrecision], N[Log[1 + N[(Exp[t$95$0] - 1), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    9. Simplified37.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
    10. Step-by-step derivation
      1. log1p-expm1-u69.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)} \]
    11. Applied egg-rr69.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 380:\\ \;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)\\ \end{array} \]

Alternative 6: 74.9% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 10^{+51}:\\ \;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{0.125 \cdot {im}^{6}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1e+51)
   (+ (cos re) (* 0.5 (* im im)))
   (cbrt (* 0.125 (pow im 6.0)))))
double code(double re, double im) {
	double tmp;
	if (im <= 1e+51) {
		tmp = cos(re) + (0.5 * (im * im));
	} else {
		tmp = cbrt((0.125 * pow(im, 6.0)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= 1e+51) {
		tmp = Math.cos(re) + (0.5 * (im * im));
	} else {
		tmp = Math.cbrt((0.125 * Math.pow(im, 6.0)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 1e+51)
		tmp = Float64(cos(re) + Float64(0.5 * Float64(im * im)));
	else
		tmp = cbrt(Float64(0.125 * (im ^ 6.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 1e+51], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(0.125 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{0.125 \cdot {im}^{6}}\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    if 1e51 < 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.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot im\right)} \]
    10. Step-by-step derivation
      1. add-cbrt-cube65.3%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)}} \]
      2. pow1/365.3%

        \[\leadsto \color{blue}{{\left(\left(\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\right)}^{0.3333333333333333}} \]
      3. pow365.3%

        \[\leadsto {\color{blue}{\left({\left(0.5 \cdot \left(im \cdot im\right)\right)}^{3}\right)}}^{0.3333333333333333} \]
      4. unpow-prod-down65.3%

        \[\leadsto {\color{blue}{\left({0.5}^{3} \cdot {\left(im \cdot im\right)}^{3}\right)}}^{0.3333333333333333} \]
      5. metadata-eval65.3%

        \[\leadsto {\left(\color{blue}{0.125} \cdot {\left(im \cdot im\right)}^{3}\right)}^{0.3333333333333333} \]
      6. pow-prod-down65.3%

        \[\leadsto {\left(0.125 \cdot \color{blue}{\left({im}^{3} \cdot {im}^{3}\right)}\right)}^{0.3333333333333333} \]
      7. pow-prod-up65.3%

        \[\leadsto {\left(0.125 \cdot \color{blue}{{im}^{\left(3 + 3\right)}}\right)}^{0.3333333333333333} \]
      8. metadata-eval65.3%

        \[\leadsto {\left(0.125 \cdot {im}^{\color{blue}{6}}\right)}^{0.3333333333333333} \]
    11. Applied egg-rr65.3%

      \[\leadsto \color{blue}{{\left(0.125 \cdot {im}^{6}\right)}^{0.3333333333333333}} \]
    12. Step-by-step derivation
      1. unpow1/365.3%

        \[\leadsto \color{blue}{\sqrt[3]{0.125 \cdot {im}^{6}}} \]
    13. Simplified65.3%

      \[\leadsto \color{blue}{\sqrt[3]{0.125 \cdot {im}^{6}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 10^{+51}:\\ \;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{0.125 \cdot {im}^{6}}\\ \end{array} \]

Alternative 7: 69.1% accurate, 2.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 60.5% accurate, 3.0× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

    if 680 < im < 2.6e131

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.6e131 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 48.0% accurate, 27.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.22 \cdot 10^{+14} \lor \neg \left(im \leq 1.95 \cdot 10^{+152}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 1.22e14 or 1.95000000000000006e152 < 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 82.4%

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

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

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

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

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

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

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

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

    if 1.22e14 < im < 1.95000000000000006e152

    1. Initial program 100.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.22 \cdot 10^{+14} \lor \neg \left(im \leq 1.95 \cdot 10^{+152}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\ \mathbf{else}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \end{array} \]

Alternative 10: 47.7% accurate, 27.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 86 \lor \neg \left(im \leq 4.2 \cdot 10^{+130}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 86 or 4.19999999999999981e130 < 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 81.8%

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

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

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

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

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

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

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

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

    if 86 < im < 4.19999999999999981e130

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 18.2% accurate, 27.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.22 \cdot 10^{+14}:\\
\;\;\;\;0.25\\

\mathbf{elif}\;im \leq 1.5 \cdot 10^{+152}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\

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


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

    1. Initial program 100.0%

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

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

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

    if 1.22e14 < im < 1.49999999999999995e152

    1. Initial program 100.0%

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

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

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

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

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

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

    if 1.49999999999999995e152 < 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 97.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.22 \cdot 10^{+14}:\\ \;\;\;\;0.25\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{+152}:\\ \;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 12: 17.0% accurate, 43.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 155:\\
\;\;\;\;0.25\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    9. Simplified37.3%

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

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

Alternative 13: 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-rr7.8%

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

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

    \[\leadsto 0.25 \]

Reproduce

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