math.cos on complex, real part

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \cos re \cdot \mathsf{fma}\left(0.5, e^{im\_m}, \frac{0.5}{e^{im\_m}}\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (* (cos re) (fma 0.5 (exp im_m) (/ 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	return cos(re) * fma(0.5, exp(im_m), (0.5 / exp(im_m)));
}
im_m = abs(im)
function code(re, im_m)
	return Float64(cos(re) * fma(0.5, exp(im_m), Float64(0.5 / exp(im_m))))
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision] + N[(0.5 / N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im\_m}, \frac{0.5}{e^{im\_m}}\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 100.0% accurate, 1.0× speedup?

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

\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + e^{-im\_m}\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: 99.6% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 1.3:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im\_m}\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 1.3)
   (* (* (cos re) 0.5) (fma im_m im_m 2.0))
   (* (cos re) (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1.3) {
		tmp = (cos(re) * 0.5) * fma(im_m, im_m, 2.0);
	} else {
		tmp = cos(re) * (0.5 * exp(im_m));
	}
	return tmp;
}
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 1.3)
		tmp = Float64(Float64(cos(re) * 0.5) * fma(im_m, im_m, 2.0));
	else
		tmp = Float64(cos(re) * Float64(0.5 * exp(im_m)));
	end
	return tmp
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 1.3], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if 1.30000000000000004 < 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. Applied egg-rr97.5%

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

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

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

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

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

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

Alternative 4: 99.3% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 0.7:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot e^{im\_m}\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 0.7) (cos re) (* (cos re) (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 0.7) {
		tmp = cos(re);
	} else {
		tmp = cos(re) * (0.5 * exp(im_m));
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 0.7d0) then
        tmp = cos(re)
    else
        tmp = cos(re) * (0.5d0 * exp(im_m))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 0.7) {
		tmp = Math.cos(re);
	} else {
		tmp = Math.cos(re) * (0.5 * Math.exp(im_m));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 0.7:
		tmp = math.cos(re)
	else:
		tmp = math.cos(re) * (0.5 * math.exp(im_m))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 0.7)
		tmp = cos(re);
	else
		tmp = Float64(cos(re) * Float64(0.5 * exp(im_m)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 0.7)
		tmp = cos(re);
	else
		tmp = cos(re) * (0.5 * exp(im_m));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 0.7], N[Cos[re], $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if 0.69999999999999996 < 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. Applied egg-rr97.5%

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

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

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

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

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

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

Alternative 5: 87.0% accurate, 2.9× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 1.2:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot e^{im\_m}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 1.2) (cos re) (* 0.5 (exp im_m))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1.2) {
		tmp = cos(re);
	} else {
		tmp = 0.5 * exp(im_m);
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 1.2d0) then
        tmp = cos(re)
    else
        tmp = 0.5d0 * exp(im_m)
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1.2) {
		tmp = Math.cos(re);
	} else {
		tmp = 0.5 * Math.exp(im_m);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 1.2:
		tmp = math.cos(re)
	else:
		tmp = 0.5 * math.exp(im_m)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 1.2)
		tmp = cos(re);
	else
		tmp = Float64(0.5 * exp(im_m));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 1.2)
		tmp = cos(re);
	else
		tmp = 0.5 * exp(im_m);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 1.2], N[Cos[re], $MachinePrecision], N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

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

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


\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. Add Preprocessing
    3. Taylor expanded in im around 0 86.2%

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

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

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

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

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

      \[\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. Applied egg-rr97.5%

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

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

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

Alternative 6: 51.0% accurate, 3.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \cos re \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 (cos re))
im_m = fabs(im);
double code(double re, double im_m) {
	return cos(re);
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = cos(re)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return Math.cos(re);
}
im_m = math.fabs(im)
def code(re, im_m):
	return math.cos(re)
im_m = abs(im)
function code(re, im_m)
	return cos(re)
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = cos(re);
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[Cos[re], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\cos re} \]
  7. Final simplification55.4%

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

Alternative 7: 9.5% accurate, 61.6× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ 0.5 \cdot \left(im\_m + 1\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 (* 0.5 (+ im_m 1.0)))
im_m = fabs(im);
double code(double re, double im_m) {
	return 0.5 * (im_m + 1.0);
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = 0.5d0 * (im_m + 1.0d0)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return 0.5 * (im_m + 1.0);
}
im_m = math.fabs(im)
def code(re, im_m):
	return 0.5 * (im_m + 1.0)
im_m = abs(im)
function code(re, im_m)
	return Float64(0.5 * Float64(im_m + 1.0))
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = 0.5 * (im_m + 1.0);
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[(0.5 * N[(im$95$m + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

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

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

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

    \[\leadsto \color{blue}{0.5 \cdot \cos re + 0.5 \cdot \left(im \cdot \cos re\right)} \]
  7. Step-by-step derivation
    1. distribute-lft-out11.5%

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

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

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

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

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

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

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

Alternative 8: 4.4% accurate, 102.7× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ 0.5 \cdot im\_m \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 (* 0.5 im_m))
im_m = fabs(im);
double code(double re, double im_m) {
	return 0.5 * im_m;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = 0.5d0 * im_m
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return 0.5 * im_m;
}
im_m = math.fabs(im)
def code(re, im_m):
	return 0.5 * im_m
im_m = abs(im)
function code(re, im_m)
	return Float64(0.5 * im_m)
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = 0.5 * im_m;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[(0.5 * im$95$m), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
0.5 \cdot im\_m
\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. Applied egg-rr31.5%

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

    \[\leadsto \color{blue}{0.5 \cdot \cos re + 0.5 \cdot \left(im \cdot \cos re\right)} \]
  7. Step-by-step derivation
    1. distribute-lft-out11.5%

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

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

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

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

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

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

    \[\leadsto 0.5 \cdot \color{blue}{im} \]
  13. Final simplification3.3%

    \[\leadsto 0.5 \cdot im \]
  14. Add Preprocessing

Reproduce

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