math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 5.7s
Alternatives: 13
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    13. 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) \]
    14. 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. Add Preprocessing
  5. Final simplification100.0%

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

Alternative 2: 95.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.9999:\\
\;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\

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


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 91.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 91.6%

      \[\leadsto \cos re \cdot \left(1 + \color{blue}{0.001388888888888889 \cdot {im}^{6}}\right) \]

    if 0.99990000000000001 < (cos.f64 re)

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in re around 0 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos re \leq 0.9999:\\ \;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.9999:\\
\;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\

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


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 91.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 91.6%

      \[\leadsto \cos re \cdot \left(1 + \color{blue}{0.001388888888888889 \cdot {im}^{6}}\right) \]

    if 0.99990000000000001 < (cos.f64 re)

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos re \leq 0.9999:\\ \;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 88.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.35:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1.35)
   (* (cos re) (* 0.5 (fma im im 2.0)))
   (* (cos re) (fma 0.5 (exp im) 0.0))))
double code(double re, double im) {
	double tmp;
	if (im <= 1.35) {
		tmp = cos(re) * (0.5 * fma(im, im, 2.0));
	} else {
		tmp = cos(re) * fma(0.5, exp(im), 0.0);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 1.35)
		tmp = Float64(cos(re) * Float64(0.5 * fma(im, im, 2.0)));
	else
		tmp = Float64(cos(re) * fma(0.5, exp(im), 0.0));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 1.35], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.35:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 92.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around 0 81.3%

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

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

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

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

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

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

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

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

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

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

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

    if 1.3500000000000001 < im

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \cos \left(-re\right) \cdot \color{blue}{\left(e^{im} \cdot 0.5 + e^{-im} \cdot 0.5\right)} \]
      6. cancel-sign-sub99.9%

        \[\leadsto \cos \left(-re\right) \cdot \color{blue}{\left(e^{im} \cdot 0.5 - \left(-e^{-im}\right) \cdot 0.5\right)} \]
      7. distribute-lft-neg-in99.9%

        \[\leadsto \cos \left(-re\right) \cdot \left(e^{im} \cdot 0.5 - \color{blue}{\left(-e^{-im} \cdot 0.5\right)}\right) \]
      8. cos-neg99.9%

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

        \[\leadsto \cos re \cdot \left(\color{blue}{0.5 \cdot e^{im}} - \left(-e^{-im} \cdot 0.5\right)\right) \]
      10. fma-neg99.9%

        \[\leadsto \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, -\left(-e^{-im} \cdot 0.5\right)\right)} \]
      11. remove-double-neg99.9%

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr98.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.35:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 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. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 6: 72.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 10^{+48}:\\ \;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1.3e+19)
   (cos re)
   (if (<= im 1e+48)
     (sqrt (* (pow im 12.0) 1.9290123456790124e-6))
     (* 0.001388888888888889 (* (cos re) (pow im 6.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 1.3e+19) {
		tmp = cos(re);
	} else if (im <= 1e+48) {
		tmp = sqrt((pow(im, 12.0) * 1.9290123456790124e-6));
	} else {
		tmp = 0.001388888888888889 * (cos(re) * pow(im, 6.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 1.3d+19) then
        tmp = cos(re)
    else if (im <= 1d+48) then
        tmp = sqrt(((im ** 12.0d0) * 1.9290123456790124d-6))
    else
        tmp = 0.001388888888888889d0 * (cos(re) * (im ** 6.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 1.3e+19) {
		tmp = Math.cos(re);
	} else if (im <= 1e+48) {
		tmp = Math.sqrt((Math.pow(im, 12.0) * 1.9290123456790124e-6));
	} else {
		tmp = 0.001388888888888889 * (Math.cos(re) * Math.pow(im, 6.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 1.3e+19:
		tmp = math.cos(re)
	elif im <= 1e+48:
		tmp = math.sqrt((math.pow(im, 12.0) * 1.9290123456790124e-6))
	else:
		tmp = 0.001388888888888889 * (math.cos(re) * math.pow(im, 6.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 1.3e+19)
		tmp = cos(re);
	elseif (im <= 1e+48)
		tmp = sqrt(Float64((im ^ 12.0) * 1.9290123456790124e-6));
	else
		tmp = Float64(0.001388888888888889 * Float64(cos(re) * (im ^ 6.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 1.3e+19)
		tmp = cos(re);
	elseif (im <= 1e+48)
		tmp = sqrt(((im ^ 12.0) * 1.9290123456790124e-6));
	else
		tmp = 0.001388888888888889 * (cos(re) * (im ^ 6.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 1.3e+19], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1e+48], N[Sqrt[N[(N[Power[im, 12.0], $MachinePrecision] * 1.9290123456790124e-6), $MachinePrecision]], $MachinePrecision], N[(0.001388888888888889 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\

\mathbf{elif}\;im \leq 10^{+48}:\\
\;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\

\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 63.6%

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

    if 1.3e19 < im < 1.00000000000000004e48

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 5.1%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 5.1%

      \[\leadsto \color{blue}{0.001388888888888889 \cdot \left({im}^{6} \cdot \cos re\right)} \]
    7. Taylor expanded in re around 0 5.1%

      \[\leadsto \color{blue}{0.001388888888888889 \cdot {im}^{6}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt5.1%

        \[\leadsto \color{blue}{\sqrt{0.001388888888888889 \cdot {im}^{6}} \cdot \sqrt{0.001388888888888889 \cdot {im}^{6}}} \]
      2. sqrt-unprod42.6%

        \[\leadsto \color{blue}{\sqrt{\left(0.001388888888888889 \cdot {im}^{6}\right) \cdot \left(0.001388888888888889 \cdot {im}^{6}\right)}} \]
      3. *-commutative42.6%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{6} \cdot 0.001388888888888889\right)} \cdot \left(0.001388888888888889 \cdot {im}^{6}\right)} \]
      4. *-commutative42.6%

        \[\leadsto \sqrt{\left({im}^{6} \cdot 0.001388888888888889\right) \cdot \color{blue}{\left({im}^{6} \cdot 0.001388888888888889\right)}} \]
      5. swap-sqr42.6%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{6} \cdot {im}^{6}\right) \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)}} \]
      6. pow-prod-up42.6%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(6 + 6\right)}} \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)} \]
      7. metadata-eval42.6%

        \[\leadsto \sqrt{{im}^{\color{blue}{12}} \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)} \]
      8. metadata-eval42.6%

        \[\leadsto \sqrt{{im}^{12} \cdot \color{blue}{1.9290123456790124 \cdot 10^{-6}}} \]
    9. Applied egg-rr42.6%

      \[\leadsto \color{blue}{\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}} \]

    if 1.00000000000000004e48 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 98.2%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 10^{+48}:\\ \;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 74.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\

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

\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 64.6%

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

    if 6.79999999999999948e-7 < im < 1.00000000000000004e48

    1. Initial program 99.5%

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

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

    if 1.00000000000000004e48 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 98.2%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 10^{+48}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 86.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 10^{+48}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 6.8e-7)
   (* (cos re) (* 0.5 (fma im im 2.0)))
   (if (<= im 1e+48)
     (* 0.5 (+ (exp im) (exp (- im))))
     (* 0.001388888888888889 (* (cos re) (pow im 6.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 6.8e-7) {
		tmp = cos(re) * (0.5 * fma(im, im, 2.0));
	} else if (im <= 1e+48) {
		tmp = 0.5 * (exp(im) + exp(-im));
	} else {
		tmp = 0.001388888888888889 * (cos(re) * pow(im, 6.0));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 6.8e-7)
		tmp = Float64(cos(re) * Float64(0.5 * fma(im, im, 2.0)));
	elseif (im <= 1e+48)
		tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im))));
	else
		tmp = Float64(0.001388888888888889 * Float64(cos(re) * (im ^ 6.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 6.8e-7], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e+48], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.001388888888888889 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 92.8%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around 0 81.5%

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

        \[\leadsto \cos re + \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \cos re} \]
      2. distribute-rgt1-in81.5%

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)}\right) \]
    8. Simplified81.5%

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

    if 6.79999999999999948e-7 < im < 1.00000000000000004e48

    1. Initial program 99.5%

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

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

    if 1.00000000000000004e48 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 98.2%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 10^{+48}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 68.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.5 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1.5e+19) (cos re) (sqrt (* (pow im 12.0) 1.9290123456790124e-6))))
double code(double re, double im) {
	double tmp;
	if (im <= 1.5e+19) {
		tmp = cos(re);
	} else {
		tmp = sqrt((pow(im, 12.0) * 1.9290123456790124e-6));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 1.5d+19) then
        tmp = cos(re)
    else
        tmp = sqrt(((im ** 12.0d0) * 1.9290123456790124d-6))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 1.5e+19) {
		tmp = Math.cos(re);
	} else {
		tmp = Math.sqrt((Math.pow(im, 12.0) * 1.9290123456790124e-6));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 1.5e+19:
		tmp = math.cos(re)
	else:
		tmp = math.sqrt((math.pow(im, 12.0) * 1.9290123456790124e-6))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 1.5e+19)
		tmp = cos(re);
	else
		tmp = sqrt(Float64((im ^ 12.0) * 1.9290123456790124e-6));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 1.5e+19)
		tmp = cos(re);
	else
		tmp = sqrt(((im ^ 12.0) * 1.9290123456790124e-6));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 1.5e+19], N[Cos[re], $MachinePrecision], N[Sqrt[N[(N[Power[im, 12.0], $MachinePrecision] * 1.9290123456790124e-6), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.5 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\

\mathbf{else}:\\
\;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 63.6%

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

    if 1.5e19 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 89.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 89.7%

      \[\leadsto \color{blue}{0.001388888888888889 \cdot \left({im}^{6} \cdot \cos re\right)} \]
    7. Taylor expanded in re around 0 71.4%

      \[\leadsto \color{blue}{0.001388888888888889 \cdot {im}^{6}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt71.4%

        \[\leadsto \color{blue}{\sqrt{0.001388888888888889 \cdot {im}^{6}} \cdot \sqrt{0.001388888888888889 \cdot {im}^{6}}} \]
      2. sqrt-unprod74.8%

        \[\leadsto \color{blue}{\sqrt{\left(0.001388888888888889 \cdot {im}^{6}\right) \cdot \left(0.001388888888888889 \cdot {im}^{6}\right)}} \]
      3. *-commutative74.8%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{6} \cdot 0.001388888888888889\right)} \cdot \left(0.001388888888888889 \cdot {im}^{6}\right)} \]
      4. *-commutative74.8%

        \[\leadsto \sqrt{\left({im}^{6} \cdot 0.001388888888888889\right) \cdot \color{blue}{\left({im}^{6} \cdot 0.001388888888888889\right)}} \]
      5. swap-sqr74.8%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{6} \cdot {im}^{6}\right) \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)}} \]
      6. pow-prod-up74.8%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(6 + 6\right)}} \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)} \]
      7. metadata-eval74.8%

        \[\leadsto \sqrt{{im}^{\color{blue}{12}} \cdot \left(0.001388888888888889 \cdot 0.001388888888888889\right)} \]
      8. metadata-eval74.8%

        \[\leadsto \sqrt{{im}^{12} \cdot \color{blue}{1.9290123456790124 \cdot 10^{-6}}} \]
    9. Applied egg-rr74.8%

      \[\leadsto \color{blue}{\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.5 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 66.5% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.1 \cdot 10^{+20}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;1 + 0.001388888888888889 \cdot {im}^{6}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.1e+20) (cos re) (+ 1.0 (* 0.001388888888888889 (pow im 6.0)))))
double code(double re, double im) {
	double tmp;
	if (im <= 2.1e+20) {
		tmp = cos(re);
	} else {
		tmp = 1.0 + (0.001388888888888889 * pow(im, 6.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 2.1d+20) then
        tmp = cos(re)
    else
        tmp = 1.0d0 + (0.001388888888888889d0 * (im ** 6.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 2.1e+20) {
		tmp = Math.cos(re);
	} else {
		tmp = 1.0 + (0.001388888888888889 * Math.pow(im, 6.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 2.1e+20:
		tmp = math.cos(re)
	else:
		tmp = 1.0 + (0.001388888888888889 * math.pow(im, 6.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 2.1e+20)
		tmp = cos(re);
	else
		tmp = Float64(1.0 + Float64(0.001388888888888889 * (im ^ 6.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 2.1e+20)
		tmp = cos(re);
	else
		tmp = 1.0 + (0.001388888888888889 * (im ^ 6.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 2.1e+20], N[Cos[re], $MachinePrecision], N[(1.0 + N[(0.001388888888888889 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.1 \cdot 10^{+20}:\\
\;\;\;\;\cos re\\

\mathbf{else}:\\
\;\;\;\;1 + 0.001388888888888889 \cdot {im}^{6}\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 63.6%

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

    if 2.1e20 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 89.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 89.7%

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

      \[\leadsto \color{blue}{1 + 0.001388888888888889 \cdot {im}^{6}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.1 \cdot 10^{+20}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;1 + 0.001388888888888889 \cdot {im}^{6}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 66.5% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot {im}^{6}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1.3e+19) (cos re) (* 0.001388888888888889 (pow im 6.0))))
double code(double re, double im) {
	double tmp;
	if (im <= 1.3e+19) {
		tmp = cos(re);
	} else {
		tmp = 0.001388888888888889 * pow(im, 6.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 1.3d+19) then
        tmp = cos(re)
    else
        tmp = 0.001388888888888889d0 * (im ** 6.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 1.3e+19) {
		tmp = Math.cos(re);
	} else {
		tmp = 0.001388888888888889 * Math.pow(im, 6.0);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 1.3e+19:
		tmp = math.cos(re)
	else:
		tmp = 0.001388888888888889 * math.pow(im, 6.0)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 1.3e+19)
		tmp = cos(re);
	else
		tmp = Float64(0.001388888888888889 * (im ^ 6.0));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 1.3e+19)
		tmp = cos(re);
	else
		tmp = 0.001388888888888889 * (im ^ 6.0);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 1.3e+19], N[Cos[re], $MachinePrecision], N[(0.001388888888888889 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\

\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot {im}^{6}\\


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

    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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 63.6%

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

    if 1.3e19 < 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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      13. 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) \]
      14. 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. Add Preprocessing
    5. Taylor expanded in im around 0 89.7%

      \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
    6. Taylor expanded in im around inf 89.7%

      \[\leadsto \color{blue}{0.001388888888888889 \cdot \left({im}^{6} \cdot \cos re\right)} \]
    7. Taylor expanded in re around 0 71.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.001388888888888889 \cdot {im}^{6}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 52.0% accurate, 3.0× speedup?

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

\\
\cos re
\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. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    13. 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) \]
    14. 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. Add Preprocessing
  5. Taylor expanded in im around 0 50.6%

    \[\leadsto \color{blue}{\cos re} \]
  6. Final simplification50.6%

    \[\leadsto \cos re \]
  7. Add Preprocessing

Alternative 13: 29.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. Step-by-step derivation
    1. cos-neg100.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    13. 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) \]
    14. 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. Add Preprocessing
  5. Taylor expanded in im around 0 91.1%

    \[\leadsto \cos re \cdot \color{blue}{\left(1 + {im}^{2} \cdot \left(0.5 + {im}^{2} \cdot \left(0.041666666666666664 + 0.001388888888888889 \cdot {im}^{2}\right)\right)\right)} \]
  6. Applied egg-rr26.4%

    \[\leadsto \color{blue}{\frac{\cos re - 0.043055555555555555 \cdot \cos re}{\cos re - 0.043055555555555555 \cdot \cos re}} \]
  7. Step-by-step derivation
    1. *-inverses26.4%

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

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

    \[\leadsto 1 \]
  10. Add Preprocessing

Reproduce

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