math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 8.4s
Alternatives: 14
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 14 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, 0.8× speedup?

\[\begin{array}{l} \\ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
	return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im)
	return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im))))
end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{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. Step-by-step derivation
    1. *-commutative100.0%

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

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

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

      \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
    5. distribute-lft-in100.0%

      \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. distribute-rgt-in100.0%

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

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

      \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
    9. exp-neg100.0%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    10. associate-*l/100.0%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
    11. metadata-eval100.0%

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
  4. Final simplification100.0%

    \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \]

Alternative 2: 100.0% accurate, 1.0× speedup?

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

\\
\left(\cos re \cdot 0.5\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(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right) \]

Alternative 3: 92.7% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;im \leq 8 \cdot 10^{+151}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.4000000000000001e159 or 8.00000000000000014e151 < 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.6%

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

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

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

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

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

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

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

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

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

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

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

    if -1.4000000000000001e159 < im < -0.0570000000000000021 or 0.0145000000000000007 < im < 8.00000000000000014e151

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

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

    if -0.0570000000000000021 < im < 0.0145000000000000007

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.4 \cdot 10^{+159}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \mathbf{elif}\;im \leq -0.057:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{elif}\;im \leq 0.0145:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 8 \cdot 10^{+151}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 4: 95.9% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;im \leq 1.15 \cdot 10^{+73}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -5.1000000000000003e82 or 1.15e73 < 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 99.1%

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

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

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

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

      \[\leadsto \color{blue}{0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)} \]
    6. Step-by-step derivation
      1. *-commutative99.1%

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

        \[\leadsto \color{blue}{\left({im}^{4} \cdot \cos re\right)} \cdot 0.041666666666666664 \]
      3. associate-*l*99.1%

        \[\leadsto \color{blue}{{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)} \]
    7. Simplified99.1%

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

    if -5.1000000000000003e82 < im < -0.087999999999999995 or 0.0145000000000000007 < im < 1.15e73

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

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

    if -0.087999999999999995 < im < 0.0145000000000000007

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.1 \cdot 10^{+82}:\\ \;\;\;\;{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)\\ \mathbf{elif}\;im \leq -0.088:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{elif}\;im \leq 0.0145:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+73}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)\\ \end{array} \]

Alternative 5: 97.1% accurate, 1.5× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -5.1000000000000003e82 < im < -8.9999999999999999e-10

    1. Initial program 99.9%

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

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

    if -8.9999999999999999e-10 < im

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.1 \cdot 10^{+82}:\\ \;\;\;\;{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)\\ \mathbf{elif}\;im \leq -9 \cdot 10^{-10}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \end{array} \]

Alternative 6: 83.9% accurate, 2.7× speedup?

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

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

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

\mathbf{elif}\;im \leq 8 \cdot 10^{+151}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

    if -1.3999999999999999 < im < 1.75

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

    if 1.75 < im < 8.00000000000000014e151

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

      \[\leadsto \color{blue}{0.5 + 0.5 \cdot e^{im}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.9%

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

Alternative 7: 84.2% accurate, 2.8× speedup?

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

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

\mathbf{elif}\;im \leq 8 \cdot 10^{+151}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\

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


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

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

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

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

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

    if 3.5 < im < 8.00000000000000014e151

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

      \[\leadsto \color{blue}{0.5 + 0.5 \cdot e^{im}} \]

    if 8.00000000000000014e151 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 3.5:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 8 \cdot 10^{+151}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(\cos re \cdot \left(0.5 \cdot im\right)\right)\\ \end{array} \]

Alternative 8: 77.4% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.2 \cdot 10^{+47}:\\
\;\;\;\;im \cdot \left(0.5 \cdot im\right)\\

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

\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)} \]
    11. Taylor expanded in re around 0 55.4%

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

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

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

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

    if -1.20000000000000009e47 < im < 2

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

    if 2 < im

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

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

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

Alternative 9: 69.8% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;im \leq 5.8 \cdot 10^{+86}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 2.3 \cdot 10^{+139}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - t_2 \cdot t_2}{t_0 - t_2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.0000000000000002e47 or 2.3e139 < 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 76.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \]
    10. Simplified53.7%

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)} \]
    11. Taylor expanded in re around 0 59.3%

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

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

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

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

    if -4.0000000000000002e47 < im < 5.79999999999999981e86

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)} \]
      5. distribute-lft-in100.0%

        \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot \left(e^{im} + e^{-im}\right)\right)} \]
      6. distribute-rgt-in100.0%

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

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

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{-im} \cdot 0.5\right)} \]
      9. exp-neg100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      10. associate-*l/100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1 \cdot 0.5}{e^{im}}}\right) \]
      11. metadata-eval100.0%

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right) \]
    3. Simplified100.0%

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

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

    if 5.79999999999999981e86 < im < 2.3e139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)} \]
    11. Step-by-step derivation
      1. distribute-lft-in11.1%

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

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

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

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

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \color{blue}{\left(im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)\right)} \cdot \left(\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      6. *-commutative56.3%

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

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right)\right)}\right)\right) \cdot \left(\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      8. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \color{blue}{\left(im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)\right)}}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      9. *-commutative56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \color{blue}{\left(\left(re \cdot re\right) \cdot -0.25\right)}\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      10. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right)\right)}\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      11. *-commutative56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{\color{blue}{0.5 \cdot \left(im \cdot im\right)} - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      12. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{0.5 \cdot \left(im \cdot im\right) - \color{blue}{im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}} \]
    12. Applied egg-rr56.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4 \cdot 10^{+47}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \mathbf{elif}\;im \leq 5.8 \cdot 10^{+86}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 2.3 \cdot 10^{+139}:\\ \;\;\;\;\frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{0.5 \cdot \left(im \cdot im\right) - im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 10: 47.9% accurate, 6.0× speedup?

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

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

\mathbf{elif}\;im \leq 2.3 \cdot 10^{+139}:\\
\;\;\;\;\frac{t_1 \cdot t_1 - t_0 \cdot t_0}{t_1 - t_0}\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 5.79999999999999981e86 < im < 2.3e139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)} \]
    11. Step-by-step derivation
      1. distribute-lft-in11.1%

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

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

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

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

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \color{blue}{\left(im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)\right)} \cdot \left(\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      6. *-commutative56.3%

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

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right)\right)}\right)\right) \cdot \left(\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      8. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \color{blue}{\left(im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)\right)}}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      9. *-commutative56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \color{blue}{\left(\left(re \cdot re\right) \cdot -0.25\right)}\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      10. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right)\right)}\right)\right)}{\left(im \cdot im\right) \cdot 0.5 - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      11. *-commutative56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{\color{blue}{0.5 \cdot \left(im \cdot im\right)} - \left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)} \]
      12. associate-*l*56.3%

        \[\leadsto \frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{0.5 \cdot \left(im \cdot im\right) - \color{blue}{im \cdot \left(im \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\right)}} \]
    12. Applied egg-rr56.3%

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

    if 2.3e139 < 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 92.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)} \]
    11. Taylor expanded in re around 0 68.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 5.8 \cdot 10^{+86}:\\ \;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\ \mathbf{elif}\;im \leq 2.3 \cdot 10^{+139}:\\ \;\;\;\;\frac{\left(0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) - \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right) \cdot \left(im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)\right)}{0.5 \cdot \left(im \cdot im\right) - im \cdot \left(im \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(0.5 \cdot im\right)\\ \end{array} \]

Alternative 11: 46.0% accurate, 33.7× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \color{blue}{\left(re \cdot re\right)}\right) \]
    10. Simplified38.6%

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

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

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

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

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

    if -0.0420000000000000026 < 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 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\cos re - 1.9380669946781485 \cdot 10^{-10} \cdot \cos re}{\cos re - 1.9380669946781485 \cdot 10^{-10} \cdot \cos re}} \]
    6. Step-by-step derivation
      1. *-inverses51.5%

        \[\leadsto \color{blue}{1} \]
    7. Simplified51.5%

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

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

Alternative 12: 46.2% 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 75.1%

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

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

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

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

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

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

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

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

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

Alternative 13: 4.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 75.1%

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

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

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

    \[\leadsto \color{blue}{-2 + \cos re} \]
  6. Step-by-step derivation
    1. +-commutative3.6%

      \[\leadsto \color{blue}{\cos re + -2} \]
  7. Simplified3.6%

    \[\leadsto \color{blue}{\cos re + -2} \]
  8. Taylor expanded in re around 0 4.2%

    \[\leadsto \color{blue}{-1} \]
  9. Final simplification4.2%

    \[\leadsto -1 \]

Alternative 14: 28.2% accurate, 308.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\cos re - 1.9380669946781485 \cdot 10^{-10} \cdot \cos re}{\cos re - 1.9380669946781485 \cdot 10^{-10} \cdot \cos re}} \]
  6. Step-by-step derivation
    1. *-inverses26.7%

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

    \[\leadsto \color{blue}{1} \]
  8. Final simplification26.7%

    \[\leadsto 1 \]

Reproduce

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