math.cos on complex, real part

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos re \cdot \left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (cos re) (+ (* 0.5 (exp im)) (* 0.5 (/ 1.0 (exp im))))))
double code(double re, double im) {
	return cos(re) * ((0.5 * exp(im)) + (0.5 * (1.0 / 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)) + (0.5d0 * (1.0d0 / exp(im))))
end function
public static double code(double re, double im) {
	return Math.cos(re) * ((0.5 * Math.exp(im)) + (0.5 * (1.0 / Math.exp(im))));
}
def code(re, im):
	return math.cos(re) * ((0.5 * math.exp(im)) + (0.5 * (1.0 / math.exp(im))))
function code(re, im)
	return Float64(cos(re) * Float64(Float64(0.5 * exp(im)) + Float64(0.5 * Float64(1.0 / exp(im)))))
end
function tmp = code(re, im)
	tmp = cos(re) * ((0.5 * exp(im)) + (0.5 * (1.0 / exp(im))));
end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos re \cdot \left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{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. Taylor expanded in im around inf 100.0%

    \[\leadsto \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\right)} \]
  6. Final simplification100.0%

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

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. 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 3: 73.2% accurate, 1.4× speedup?

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

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

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

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


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

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

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

    if 1.55000000000000007e-5 < im < 1.40000000000000009e102

    1. Initial program 99.9%

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

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

    if 1.40000000000000009e102 < 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 100.0%

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

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

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

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

      \[\leadsto \color{blue}{{\cos re}^{-1}} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right) \]
    10. Step-by-step derivation
      1. unpow-15.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.55 \cdot 10^{-5}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos re} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 74.5% accurate, 1.5× speedup?

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

\\
\cos re \cdot \left(0.5 + 0.5 \cdot 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. Taylor expanded in im around 0 73.9%

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

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)} \]
  7. Final simplification73.9%

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

Alternative 5: 73.1% accurate, 2.4× speedup?

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

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

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

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


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

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

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

    if 1.50000000000000004e-5 < im < 1.40000000000000009e102

    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-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 inf 100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
    7. Taylor expanded in im around 0 79.0%

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

    if 1.40000000000000009e102 < 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 100.0%

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

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

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

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

      \[\leadsto \color{blue}{{\cos re}^{-1}} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right) \]
    10. Step-by-step derivation
      1. unpow-15.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.5 \cdot 10^{-5}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot e^{im} + 0.5 \cdot \left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot -0.16666666666666666\right) + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos re} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 73.2% accurate, 2.4× speedup?

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

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

\mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\

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


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

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

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

    if 1.19999999999999996 < im < 1.40000000000000009e102

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

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

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

    if 1.40000000000000009e102 < 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 100.0%

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

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

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

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

      \[\leadsto \color{blue}{{\cos re}^{-1}} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right) \]
    10. Step-by-step derivation
      1. unpow-15.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\cos re} \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 73.1% accurate, 2.5× speedup?

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

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

\mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\

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


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

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

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

    if 1.19999999999999996 < im < 1.40000000000000009e102

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

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

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

    if 1.40000000000000009e102 < 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 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+102}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 72.1% accurate, 2.5× speedup?

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

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

\mathbf{elif}\;im \leq 1.2 \cdot 10^{+154}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\

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


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

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

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

    if 1.19999999999999996 < im < 1.20000000000000007e154

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

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

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

    if 1.20000000000000007e154 < 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 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+154}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot 0.25\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 68.9% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 1.2) (cos re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
	double tmp;
	if (im <= 1.2) {
		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.2d0) 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.2) {
		tmp = Math.cos(re);
	} else {
		tmp = 0.5 + (0.5 * Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 1.2:
		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.2)
		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.2)
		tmp = cos(re);
	else
		tmp = 0.5 + (0.5 * exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 1.2], 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:\\
\;\;\;\;\cos re\\

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


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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.5 + 0.5 \cdot e^{im}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 62.8% accurate, 2.9× speedup?

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

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

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


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

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

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

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

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

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

        \[\leadsto \cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + \color{blue}{im \cdot 0.08333333333333333}\right)\right)\right) \]
    8. Simplified65.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 43.8% accurate, 23.7× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1 + im \cdot \left(0.5 + im \cdot \left(0.25 + 0.08333333333333333 \cdot im\right)\right)} \]
  10. Final simplification44.9%

    \[\leadsto 1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right) \]
  11. Add Preprocessing

Alternative 12: 27.7% accurate, 61.6× speedup?

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

\\
1 + 0.5 \cdot im
\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 73.9%

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

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

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

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

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

    \[\leadsto \color{blue}{1 + 0.5 \cdot im} \]
  11. Final simplification28.7%

    \[\leadsto 1 + 0.5 \cdot im \]
  12. Add Preprocessing

Alternative 13: 3.5% accurate, 308.0× speedup?

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

\\
-2
\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 inf 100.0%

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

    \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
  7. Applied egg-rr3.4%

    \[\leadsto \color{blue}{-2} \]
  8. Final simplification3.4%

    \[\leadsto -2 \]
  9. Add Preprocessing

Alternative 14: 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. 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 inf 100.0%

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

    \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
  7. Applied egg-rr3.9%

    \[\leadsto \color{blue}{-1} \]
  8. Final simplification3.9%

    \[\leadsto -1 \]
  9. Add Preprocessing

Alternative 15: 7.9% accurate, 308.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
  7. Applied egg-rr7.9%

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

    \[\leadsto 0.25 \]
  9. Add Preprocessing

Alternative 16: 8.5% accurate, 308.0× speedup?

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

\\
0.5
\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 inf 100.0%

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

    \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
  7. Applied egg-rr8.4%

    \[\leadsto \color{blue}{0.5} \]
  8. Final simplification8.4%

    \[\leadsto 0.5 \]
  9. Add Preprocessing

Alternative 17: 27.8% 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 inf 100.0%

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

    \[\leadsto \color{blue}{0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}} \]
  7. Taylor expanded in im around 0 28.9%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification28.9%

    \[\leadsto 1 \]
  9. Add Preprocessing

Reproduce

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