math.cos on complex, real part

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 100.0% accurate, 1.0× speedup?

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

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

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
  2. Final simplification100.0%

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

Alternative 3: 75.2% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 87.7% accurate, 1.4× speedup?

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

\\
\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \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. Taylor expanded in im around 0 94.4%

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

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

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

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

    \[\leadsto \left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right) \]

Alternative 5: 81.8% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    if 3.7000000000000002 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 3.7:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)\\ \end{array} \]

Alternative 6: 81.1% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

    if 490 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr72.1%

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

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

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

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

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

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)} \]
    10. Taylor expanded in re around 0 72.1%

      \[\leadsto {im}^{4} \cdot \color{blue}{\left(0.041666666666666664 + -0.020833333333333332 \cdot {re}^{2}\right)} \]
    11. Step-by-step derivation
      1. *-commutative72.1%

        \[\leadsto {im}^{4} \cdot \left(0.041666666666666664 + \color{blue}{{re}^{2} \cdot -0.020833333333333332}\right) \]
      2. unpow272.1%

        \[\leadsto {im}^{4} \cdot \left(0.041666666666666664 + \color{blue}{\left(re \cdot re\right)} \cdot -0.020833333333333332\right) \]
    12. Simplified72.1%

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

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 490:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 7: 67.8% accurate, 2.8× speedup?

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

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

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 1.1e37 < im < 1.35000000000000003e154

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)} \]
      2. metadata-eval54.5%

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow254.5%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative54.5%

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

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef54.5%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative54.5%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified54.5%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around inf 54.5%

      \[\leadsto 1 + \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]

    if 1.35000000000000003e154 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.1 \cdot 10^{+37}:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 8: 68.7% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 200:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 200

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)} \]
      2. metadata-eval69.8%

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow269.8%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative69.8%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      5. *-commutative69.8%

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef69.8%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative69.8%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified69.8%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around inf 69.2%

      \[\leadsto 1 + \color{blue}{0.041666666666666664 \cdot {im}^{4}} \]

    if 200 < re

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 200:\\ \;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\ \end{array} \]

Alternative 9: 64.5% accurate, 2.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\


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

    1. Initial program 100.0%

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

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

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

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

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

    if 1.15000000000000001e37 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow270.0%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative70.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      5. *-commutative70.0%

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef70.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative70.0%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified70.0%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around inf 70.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.15 \cdot 10^{+37}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\ \end{array} \]

Alternative 10: 64.5% accurate, 2.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664\\


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

    1. Initial program 100.0%

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

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

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

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

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

    if 1.1e37 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(2 + \color{blue}{\mathsf{fma}\left(im \cdot im, \left(im \cdot im\right) \cdot 0.08333333333333333, im \cdot im\right)}\right) \]
    6. Applied egg-rr95.0%

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

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

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

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

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

      \[\leadsto \color{blue}{{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)} \]
    10. Taylor expanded in re around 0 70.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.1 \cdot 10^{+37}:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;{im}^{4} \cdot 0.041666666666666664\\ \end{array} \]

Alternative 11: 62.0% accurate, 3.0× speedup?

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

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 420 < im < 5.0000000000000001e172

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot im + -0.5 \cdot \left(\left(re \cdot re\right) \cdot \color{blue}{\left(im \cdot im\right)}\right)\right) \]
      4. associate-*r*26.3%

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

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

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

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

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

    if 5.0000000000000001e172 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow275.0%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative75.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      5. *-commutative75.0%

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef75.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative75.0%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified75.0%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around 0 75.0%

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

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    10. Simplified75.0%

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

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

Alternative 12: 49.1% accurate, 18.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 8.8e11 or 1.0000000000000001e172 < im

    1. Initial program 100.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)} \]
      2. metadata-eval59.5%

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow259.5%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative59.5%

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

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef59.5%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative59.5%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified59.5%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around 0 54.3%

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

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

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

    if 8.8e11 < im < 1.0000000000000001e172

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot im + -0.5 \cdot \left(\left(re \cdot re\right) \cdot \color{blue}{\left(im \cdot im\right)}\right)\right) \]
      4. associate-*r*27.7%

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

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

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

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

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

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

Alternative 13: 48.4% accurate, 23.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 4.5e12 or 1.5499999999999999e138 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right) \]
      3. unpow260.0%

        \[\leadsto 1 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + \color{blue}{im \cdot im}\right) \]
      4. +-commutative60.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)} \]
      5. *-commutative60.0%

        \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
      6. fma-udef60.0%

        \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
      7. *-commutative60.0%

        \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
    7. Simplified60.0%

      \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
    8. Taylor expanded in im around 0 54.1%

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

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

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

    if 4.5e12 < im < 1.5499999999999999e138

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right) \cdot -0.25} + 0.5\right) \]
      6. associate-*r*32.2%

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

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

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

        \[\leadsto im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right) + 0.5\right)}\right) \]
      10. associate-*r*32.2%

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

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

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

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

      \[\leadsto im \cdot \color{blue}{\left(-0.25 \cdot \left({re}^{2} \cdot im\right)\right)} \]
    12. Step-by-step derivation
      1. *-commutative29.5%

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

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

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

        \[\leadsto im \cdot \left(im \cdot \left(\color{blue}{\left(re \cdot re\right)} \cdot -0.25\right)\right) \]
    13. Simplified29.5%

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

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

Alternative 14: 47.0% accurate, 44.0× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot 2 + 0.5 \cdot \left(0.08333333333333333 \cdot {im}^{4} + {im}^{2}\right)} \]
    2. metadata-eval59.2%

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

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

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

      \[\leadsto 1 + 0.5 \cdot \left(im \cdot im + \color{blue}{{im}^{4} \cdot 0.08333333333333333}\right) \]
    6. fma-udef59.2%

      \[\leadsto 1 + 0.5 \cdot \color{blue}{\mathsf{fma}\left(im, im, {im}^{4} \cdot 0.08333333333333333\right)} \]
    7. *-commutative59.2%

      \[\leadsto 1 + 0.5 \cdot \mathsf{fma}\left(im, im, \color{blue}{0.08333333333333333 \cdot {im}^{4}}\right) \]
  7. Simplified59.2%

    \[\leadsto \color{blue}{1 + 0.5 \cdot \mathsf{fma}\left(im, im, 0.08333333333333333 \cdot {im}^{4}\right)} \]
  8. Taylor expanded in im around 0 51.3%

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

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

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

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

Alternative 15: 21.9% accurate, 61.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(im \cdot im\right) \cdot \left(\color{blue}{\left(re \cdot re\right) \cdot -0.25} + 0.5\right) \]
    6. associate-*r*21.3%

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

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

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

      \[\leadsto im \cdot \left(im \cdot \color{blue}{\left(re \cdot \left(re \cdot -0.25\right) + 0.5\right)}\right) \]
    10. associate-*r*21.4%

      \[\leadsto im \cdot \left(im \cdot \left(\color{blue}{\left(re \cdot re\right) \cdot -0.25} + 0.5\right)\right) \]
    11. *-commutative21.4%

      \[\leadsto im \cdot \left(im \cdot \left(\color{blue}{-0.25 \cdot \left(re \cdot re\right)} + 0.5\right)\right) \]
    12. fma-def21.4%

      \[\leadsto im \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(-0.25, re \cdot re, 0.5\right)}\right) \]
  10. Simplified21.4%

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

    \[\leadsto im \cdot \color{blue}{\left(0.5 \cdot im\right)} \]
  12. Final simplification22.8%

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

Reproduce

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