math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 9.1s
Alternatives: 19
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 19 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. cos-neg100.0%

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

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

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

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

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

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

Alternative 2: 94.2% accurate, 1.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;\cos re \leq 0.99999995:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{im\_m} + e^{-im\_m}\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= (cos re) 0.99999995)
   (*
    (* (cos re) 0.5)
    (+
     (+
      1.0
      (*
       im_m
       (+
        (*
         im_m
         (+
          0.5
          (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
        -1.0)))
     (+
      1.0
      (*
       im_m
       (+
        1.0
        (*
         im_m
         (+
          0.5
          (* im_m (+ (* im_m 0.041666666666666664) 0.16666666666666666)))))))))
   (* 0.5 (+ (exp im_m) (exp (- im_m))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (cos(re) <= 0.99999995) {
		tmp = (cos(re) * 0.5) * ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	} else {
		tmp = 0.5 * (exp(im_m) + 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 (cos(re) <= 0.99999995d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0))))))))
    else
        tmp = 0.5d0 * (exp(im_m) + 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 (Math.cos(re) <= 0.99999995) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	} else {
		tmp = 0.5 * (Math.exp(im_m) + Math.exp(-im_m));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if math.cos(re) <= 0.99999995:
		tmp = (math.cos(re) * 0.5) * ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))))
	else:
		tmp = 0.5 * (math.exp(im_m) + math.exp(-im_m))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (cos(re) <= 0.99999995)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))));
	else
		tmp = Float64(0.5 * Float64(exp(im_m) + exp(Float64(-im_m))));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (cos(re) <= 0.99999995)
		tmp = (cos(re) * 0.5) * ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	else
		tmp = 0.5 * (exp(im_m) + exp(-im_m));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.99999995], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[im$95$m], $MachinePrecision] + N[Exp[(-im$95$m)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.99999995:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\

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


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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 86.5%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative86.5%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified86.5%

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

    if 0.999999949999999971 < (cos.f64 re)

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

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

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

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

Alternative 3: 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 4: 99.6% accurate, 1.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + \left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right)\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (*
  (* (cos re) 0.5)
  (+
   (exp im_m)
   (+
    1.0
    (*
     im_m
     (+
      (*
       im_m
       (+ 0.5 (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
      -1.0))))))
im_m = fabs(im);
double code(double re, double im_m) {
	return (cos(re) * 0.5) * (exp(im_m) + (1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -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 = (cos(re) * 0.5d0) * (exp(im_m) + (1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))))
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) + (1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))));
}
im_m = math.fabs(im)
def code(re, im_m):
	return (math.cos(re) * 0.5) * (math.exp(im_m) + (1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))))
im_m = abs(im)
function code(re, im_m)
	return Float64(Float64(cos(re) * 0.5) * Float64(exp(im_m) + Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)))))
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = (cos(re) * 0.5) * (exp(im_m) + (1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))));
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[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + \left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\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. Add Preprocessing
  3. Taylor expanded in im around 0 91.2%

    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
  4. Final simplification91.2%

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

Alternative 5: 90.2% accurate, 1.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ \mathbf{if}\;im\_m \leq 400:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{elif}\;im\_m \leq 1.95 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{im\_m} + e^{-im\_m}\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0))))
   (if (<= im_m 400.0)
     (*
      (* (cos re) 0.5)
      (+
       (+ 1.0 t_0)
       (+
        1.0
        (*
         im_m
         (+
          1.0
          (*
           im_m
           (+
            0.5
            (*
             im_m
             (+ (* im_m 0.041666666666666664) 0.16666666666666666)))))))))
     (if (<= im_m 1.95e+77)
       (* (+ (exp im_m) (exp (- im_m))) -0.5)
       (* 0.5 (* (cos re) (+ t_0 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 400.0) {
		tmp = (cos(re) * 0.5) * ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	} else if (im_m <= 1.95e+77) {
		tmp = (exp(im_m) + exp(-im_m)) * -0.5;
	} else {
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    if (im_m <= 400.0d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 + t_0) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0))))))))
    else if (im_m <= 1.95d+77) then
        tmp = (exp(im_m) + exp(-im_m)) * (-0.5d0)
    else
        tmp = 0.5d0 * (cos(re) * (t_0 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 400.0) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	} else if (im_m <= 1.95e+77) {
		tmp = (Math.exp(im_m) + Math.exp(-im_m)) * -0.5;
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_0 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	tmp = 0
	if im_m <= 400.0:
		tmp = (math.cos(re) * 0.5) * ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))))
	elif im_m <= 1.95e+77:
		tmp = (math.exp(im_m) + math.exp(-im_m)) * -0.5
	else:
		tmp = 0.5 * (math.cos(re) * (t_0 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	tmp = 0.0
	if (im_m <= 400.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 + t_0) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))));
	elseif (im_m <= 1.95e+77)
		tmp = Float64(Float64(exp(im_m) + exp(Float64(-im_m))) * -0.5);
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_0 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	tmp = 0.0;
	if (im_m <= 400.0)
		tmp = (cos(re) * 0.5) * ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))));
	elseif (im_m <= 1.95e+77)
		tmp = (exp(im_m) + exp(-im_m)) * -0.5;
	else
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 400.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 + t$95$0), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 1.95e+77], N[(N[(N[Exp[im$95$m], $MachinePrecision] + N[Exp[(-im$95$m)], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$0 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
\mathbf{if}\;im\_m \leq 400:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\


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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 89.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative89.1%

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

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

    if 400 < im < 1.9499999999999999e77

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr100.0%

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

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

    if 1.9499999999999999e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 400:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 1.95 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{im} + e^{-im}\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.5% accurate, 1.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + \left(1 + im\_m \cdot \left(0.5 \cdot im\_m + -1\right)\right)\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (* (* (cos re) 0.5) (+ (exp im_m) (+ 1.0 (* im_m (+ (* 0.5 im_m) -1.0))))))
im_m = fabs(im);
double code(double re, double im_m) {
	return (cos(re) * 0.5) * (exp(im_m) + (1.0 + (im_m * ((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 = (cos(re) * 0.5d0) * (exp(im_m) + (1.0d0 + (im_m * ((0.5d0 * im_m) + (-1.0d0)))))
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) + (1.0 + (im_m * ((0.5 * im_m) + -1.0))));
}
im_m = math.fabs(im)
def code(re, im_m):
	return (math.cos(re) * 0.5) * (math.exp(im_m) + (1.0 + (im_m * ((0.5 * im_m) + -1.0))))
im_m = abs(im)
function code(re, im_m)
	return Float64(Float64(cos(re) * 0.5) * Float64(exp(im_m) + Float64(1.0 + Float64(im_m * Float64(Float64(0.5 * im_m) + -1.0)))))
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = (cos(re) * 0.5) * (exp(im_m) + (1.0 + (im_m * ((0.5 * im_m) + -1.0))));
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[(1.0 + N[(im$95$m * N[(N[(0.5 * im$95$m), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + \left(1 + im\_m \cdot \left(0.5 \cdot im\_m + -1\right)\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. Add Preprocessing
  3. Taylor expanded in im around 0 85.4%

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

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

Alternative 7: 99.3% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + \left(1 - im\_m\right)\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (* (* (cos re) 0.5) (+ (exp im_m) (- 1.0 im_m))))
im_m = fabs(im);
double code(double re, double im_m) {
	return (cos(re) * 0.5) * (exp(im_m) + (1.0 - 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) + (1.0d0 - 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) + (1.0 - im_m));
}
im_m = math.fabs(im)
def code(re, im_m):
	return (math.cos(re) * 0.5) * (math.exp(im_m) + (1.0 - im_m))
im_m = abs(im)
function code(re, im_m)
	return Float64(Float64(cos(re) * 0.5) * Float64(exp(im_m) + Float64(1.0 - im_m)))
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = (cos(re) * 0.5) * (exp(im_m) + (1.0 - 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[(1.0 - 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} + \left(1 - im\_m\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. Add Preprocessing
  3. Taylor expanded in im around 0 70.1%

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

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

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

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

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

Alternative 8: 90.1% accurate, 2.1× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ t_1 := \left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{if}\;im\_m \leq 550:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot t\_1\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;t\_1 \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0)))
        (t_1
         (+
          (+ 1.0 t_0)
          (+
           1.0
           (*
            im_m
            (+
             1.0
             (*
              im_m
              (+
               0.5
               (*
                im_m
                (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))))
   (if (<= im_m 550.0)
     (* (* (cos re) 0.5) t_1)
     (if (<= im_m 2.55e+77)
       (* t_1 (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_0 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double t_1 = (1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))));
	double tmp;
	if (im_m <= 550.0) {
		tmp = (cos(re) * 0.5) * t_1;
	} else if (im_m <= 2.55e+77) {
		tmp = t_1 * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    t_1 = (1.0d0 + t_0) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))
    if (im_m <= 550.0d0) then
        tmp = (cos(re) * 0.5d0) * t_1
    else if (im_m <= 2.55d+77) then
        tmp = t_1 * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_0 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double t_1 = (1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))));
	double tmp;
	if (im_m <= 550.0) {
		tmp = (Math.cos(re) * 0.5) * t_1;
	} else if (im_m <= 2.55e+77) {
		tmp = t_1 * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_0 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	t_1 = (1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))
	tmp = 0
	if im_m <= 550.0:
		tmp = (math.cos(re) * 0.5) * t_1
	elif im_m <= 2.55e+77:
		tmp = t_1 * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_0 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	t_1 = Float64(Float64(1.0 + t_0) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666))))))))
	tmp = 0.0
	if (im_m <= 550.0)
		tmp = Float64(Float64(cos(re) * 0.5) * t_1);
	elseif (im_m <= 2.55e+77)
		tmp = Float64(t_1 * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_0 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	t_1 = (1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))));
	tmp = 0.0;
	if (im_m <= 550.0)
		tmp = (cos(re) * 0.5) * t_1;
	elseif (im_m <= 2.55e+77)
		tmp = t_1 * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 + t$95$0), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 550.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(t$95$1 * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$0 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
t_1 := \left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\\
\mathbf{if}\;im\_m \leq 550:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot t\_1\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;t\_1 \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\


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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 89.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative89.1%

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

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

    if 550 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 550:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 90.0% accurate, 2.2× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ t_1 := 1 + t\_0\\ \mathbf{if}\;im\_m \leq 580:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(t\_1 + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(t\_1 + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0)))
        (t_1 (+ 1.0 t_0)))
   (if (<= im_m 580.0)
     (*
      (* (cos re) 0.5)
      (+
       t_1
       (+ 1.0 (* im_m (+ 1.0 (* im_m (+ 0.5 (* im_m 0.16666666666666666))))))))
     (if (<= im_m 2.55e+77)
       (*
        (+
         t_1
         (+
          1.0
          (*
           im_m
           (+
            1.0
            (*
             im_m
             (+
              0.5
              (*
               im_m
               (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
        (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_0 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double t_1 = 1.0 + t_0;
	double tmp;
	if (im_m <= 580.0) {
		tmp = (cos(re) * 0.5) * (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	} else if (im_m <= 2.55e+77) {
		tmp = (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    t_1 = 1.0d0 + t_0
    if (im_m <= 580.0d0) then
        tmp = (cos(re) * 0.5d0) * (t_1 + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * 0.16666666666666666d0)))))))
    else if (im_m <= 2.55d+77) then
        tmp = (t_1 + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_0 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double t_1 = 1.0 + t_0;
	double tmp;
	if (im_m <= 580.0) {
		tmp = (Math.cos(re) * 0.5) * (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	} else if (im_m <= 2.55e+77) {
		tmp = (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_0 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	t_1 = 1.0 + t_0
	tmp = 0
	if im_m <= 580.0:
		tmp = (math.cos(re) * 0.5) * (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))))
	elif im_m <= 2.55e+77:
		tmp = (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_0 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	t_1 = Float64(1.0 + t_0)
	tmp = 0.0
	if (im_m <= 580.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(t_1 + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.16666666666666666))))))));
	elseif (im_m <= 2.55e+77)
		tmp = Float64(Float64(t_1 + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_0 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	t_1 = 1.0 + t_0;
	tmp = 0.0;
	if (im_m <= 580.0)
		tmp = (cos(re) * 0.5) * (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	elseif (im_m <= 2.55e+77)
		tmp = (t_1 + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + t$95$0), $MachinePrecision]}, If[LessEqual[im$95$m, 580.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(t$95$1 + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(N[(t$95$1 + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$0 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
t_1 := 1 + t\_0\\
\mathbf{if}\;im\_m \leq 580:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(t\_1 + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.16666666666666666\right)\right)\right)\right)\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;\left(t\_1 + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\


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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 64.6%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + 0.16666666666666666 \cdot im\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative64.6%

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

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

    if 580 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot \left(2.5 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 580:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 89.9% accurate, 2.3× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := 1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\\ t_1 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ \mathbf{if}\;im\_m \leq 650:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im\_m \cdot \left(0.5 \cdot im\_m + -1\right)\right) + t\_0\right)\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + t\_1\right) + t\_0\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_1 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (+
          1.0
          (*
           im_m
           (+
            1.0
            (*
             im_m
             (+
              0.5
              (*
               im_m
               (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
        (t_1
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0))))
   (if (<= im_m 650.0)
     (* (* (cos re) 0.5) (+ (+ 1.0 (* im_m (+ (* 0.5 im_m) -1.0))) t_0))
     (if (<= im_m 2.55e+77)
       (* (+ (+ 1.0 t_1) t_0) (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_1 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	double t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 650.0) {
		tmp = (cos(re) * 0.5) * ((1.0 + (im_m * ((0.5 * im_m) + -1.0))) + t_0);
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_1 + 2.5));
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0))))))
    t_1 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    if (im_m <= 650.0d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 + (im_m * ((0.5d0 * im_m) + (-1.0d0)))) + t_0)
    else if (im_m <= 2.55d+77) then
        tmp = ((1.0d0 + t_1) + t_0) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_1 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	double t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 650.0) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 + (im_m * ((0.5 * im_m) + -1.0))) + t_0);
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_1 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))
	t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	tmp = 0
	if im_m <= 650.0:
		tmp = (math.cos(re) * 0.5) * ((1.0 + (im_m * ((0.5 * im_m) + -1.0))) + t_0)
	elif im_m <= 2.55e+77:
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_1 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))
	t_1 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	tmp = 0.0
	if (im_m <= 650.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 + Float64(im_m * Float64(Float64(0.5 * im_m) + -1.0))) + t_0));
	elseif (im_m <= 2.55e+77)
		tmp = Float64(Float64(Float64(1.0 + t_1) + t_0) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_1 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	tmp = 0.0;
	if (im_m <= 650.0)
		tmp = (cos(re) * 0.5) * ((1.0 + (im_m * ((0.5 * im_m) + -1.0))) + t_0);
	elseif (im_m <= 2.55e+77)
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_1 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 650.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 + N[(im$95$m * N[(N[(0.5 * im$95$m), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(N[(N[(1.0 + t$95$1), $MachinePrecision] + t$95$0), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$1 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := 1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\\
t_1 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
\mathbf{if}\;im\_m \leq 650:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im\_m \cdot \left(0.5 \cdot im\_m + -1\right)\right) + t\_0\right)\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;\left(\left(1 + t\_1\right) + t\_0\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_1 + 2.5\right)\right)\\


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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 89.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative89.1%

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in im around 0 88.8%

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

    if 650 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 650:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 + im \cdot \left(0.5 \cdot im + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 89.7% accurate, 2.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := 1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\\ t_1 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ \mathbf{if}\;im\_m \leq 490:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + t\_0\right)\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + t\_1\right) + t\_0\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_1 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (+
          1.0
          (*
           im_m
           (+
            1.0
            (*
             im_m
             (+
              0.5
              (*
               im_m
               (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
        (t_1
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0))))
   (if (<= im_m 490.0)
     (* (* (cos re) 0.5) (+ (- 1.0 im_m) t_0))
     (if (<= im_m 2.55e+77)
       (* (+ (+ 1.0 t_1) t_0) (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_1 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	double t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 490.0) {
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + t_0);
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_1 + 2.5));
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0))))))
    t_1 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    if (im_m <= 490.0d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 - im_m) + t_0)
    else if (im_m <= 2.55d+77) then
        tmp = ((1.0d0 + t_1) + t_0) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_1 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	double t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 490.0) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 - im_m) + t_0);
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_1 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))))
	t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	tmp = 0
	if im_m <= 490.0:
		tmp = (math.cos(re) * 0.5) * ((1.0 - im_m) + t_0)
	elif im_m <= 2.55e+77:
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_1 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))
	t_1 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	tmp = 0.0
	if (im_m <= 490.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 - im_m) + t_0));
	elseif (im_m <= 2.55e+77)
		tmp = Float64(Float64(Float64(1.0 + t_1) + t_0) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_1 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = 1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666))))));
	t_1 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	tmp = 0.0;
	if (im_m <= 490.0)
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + t_0);
	elseif (im_m <= 2.55e+77)
		tmp = ((1.0 + t_1) + t_0) * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_1 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 490.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 - im$95$m), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(N[(N[(1.0 + t$95$1), $MachinePrecision] + t$95$0), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$1 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := 1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\\
t_1 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
\mathbf{if}\;im\_m \leq 490:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + t\_0\right)\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;\left(\left(1 + t\_1\right) + t\_0\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_1 + 2.5\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. Add Preprocessing
    3. Taylor expanded in im around 0 62.7%

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    8. Simplified88.6%

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

    if 490 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 490:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 89.7% accurate, 2.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ \mathbf{if}\;im\_m \leq 650:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0))))
   (if (<= im_m 650.0)
     (*
      (* (cos re) 0.5)
      (+
       (- 1.0 im_m)
       (+ 1.0 (* im_m (+ 1.0 (* im_m (+ 0.5 (* im_m 0.16666666666666666))))))))
     (if (<= im_m 2.55e+77)
       (*
        (+
         (+ 1.0 t_0)
         (+
          1.0
          (*
           im_m
           (+
            1.0
            (*
             im_m
             (+
              0.5
              (*
               im_m
               (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
        (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_0 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 650.0) {
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    if (im_m <= 650.0d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 - im_m) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * 0.16666666666666666d0)))))))
    else if (im_m <= 2.55d+77) then
        tmp = ((1.0d0 + t_0) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_0 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 650.0) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_0 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	tmp = 0
	if im_m <= 650.0:
		tmp = (math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))))
	elif im_m <= 2.55e+77:
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_0 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	tmp = 0.0
	if (im_m <= 650.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 - im_m) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.16666666666666666))))))));
	elseif (im_m <= 2.55e+77)
		tmp = Float64(Float64(Float64(1.0 + t_0) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_0 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	tmp = 0.0;
	if (im_m <= 650.0)
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * 0.16666666666666666)))))));
	elseif (im_m <= 2.55e+77)
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 650.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 - im$95$m), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(N[(N[(1.0 + t$95$0), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$0 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
\mathbf{if}\;im\_m \leq 650:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.16666666666666666\right)\right)\right)\right)\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;\left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\


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

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

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

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

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

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

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + \color{blue}{im \cdot 0.16666666666666666}\right)\right)\right)\right) \]
    8. Simplified60.6%

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

    if 650 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot \left(2.5 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification65.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 650:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 89.7% accurate, 2.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\ \mathbf{if}\;im\_m \leq 460:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + 0.5 \cdot im\_m\right)\right)\right)\\ \mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0
         (*
          im_m
          (+
           (*
            im_m
            (+
             0.5
             (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
           -1.0))))
   (if (<= im_m 460.0)
     (*
      (* (cos re) 0.5)
      (+ (- 1.0 im_m) (+ 1.0 (* im_m (+ 1.0 (* 0.5 im_m))))))
     (if (<= im_m 2.55e+77)
       (*
        (+
         (+ 1.0 t_0)
         (+
          1.0
          (*
           im_m
           (+
            1.0
            (*
             im_m
             (+
              0.5
              (*
               im_m
               (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
        (+ 0.5 (* (* re re) -0.25)))
       (* 0.5 (* (cos re) (+ t_0 2.5)))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 460.0) {
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0))
    if (im_m <= 460.0d0) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 - im_m) + (1.0d0 + (im_m * (1.0d0 + (0.5d0 * im_m)))))
    else if (im_m <= 2.55d+77) then
        tmp = ((1.0d0 + t_0) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = 0.5d0 * (cos(re) * (t_0 + 2.5d0))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	double tmp;
	if (im_m <= 460.0) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	} else if (im_m <= 2.55e+77) {
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = 0.5 * (Math.cos(re) * (t_0 + 2.5));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0)
	tmp = 0
	if im_m <= 460.0:
		tmp = (math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))))
	elif im_m <= 2.55e+77:
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = 0.5 * (math.cos(re) * (t_0 + 2.5))
	return tmp
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))
	tmp = 0.0
	if (im_m <= 460.0)
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 - im_m) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(0.5 * im_m))))));
	elseif (im_m <= 2.55e+77)
		tmp = Float64(Float64(Float64(1.0 + t_0) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(t_0 + 2.5)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	t_0 = im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0);
	tmp = 0.0;
	if (im_m <= 460.0)
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	elseif (im_m <= 2.55e+77)
		tmp = ((1.0 + t_0) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	else
		tmp = 0.5 * (cos(re) * (t_0 + 2.5));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im$95$m, 460.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 - im$95$m), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(0.5 * im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im$95$m, 2.55e+77], N[(N[(N[(1.0 + t$95$0), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(t$95$0 + 2.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
t_0 := im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\\
\mathbf{if}\;im\_m \leq 460:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + 0.5 \cdot im\_m\right)\right)\right)\\

\mathbf{elif}\;im\_m \leq 2.55 \cdot 10^{+77}:\\
\;\;\;\;\left(\left(1 + t\_0\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(t\_0 + 2.5\right)\right)\\


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

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

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

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

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

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

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

    if 460 < im < 2.54999999999999985e77

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 5.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified5.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 32.4%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr32.4%

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

    if 2.54999999999999985e77 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{0.5 \cdot \left(\cos re \cdot \left(2.5 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 460:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\right) + \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{+77}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right) + 2.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 86.2% accurate, 2.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 360 \lor \neg \left(im\_m \leq 7.5 \cdot 10^{+152}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + 0.5 \cdot im\_m\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (or (<= im_m 360.0) (not (<= im_m 7.5e+152)))
   (* (* (cos re) 0.5) (+ (- 1.0 im_m) (+ 1.0 (* im_m (+ 1.0 (* 0.5 im_m))))))
   (*
    (+
     (+
      1.0
      (*
       im_m
       (+
        (*
         im_m
         (+
          0.5
          (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
        -1.0)))
     (+
      1.0
      (*
       im_m
       (+
        1.0
        (*
         im_m
         (+
          0.5
          (* im_m (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
    (+ 0.5 (* (* re re) -0.25)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if ((im_m <= 360.0) || !(im_m <= 7.5e+152)) {
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	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 <= 360.0d0) .or. (.not. (im_m <= 7.5d+152))) then
        tmp = (cos(re) * 0.5d0) * ((1.0d0 - im_m) + (1.0d0 + (im_m * (1.0d0 + (0.5d0 * im_m)))))
    else
        tmp = ((1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    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 <= 360.0) || !(im_m <= 7.5e+152)) {
		tmp = (Math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if (im_m <= 360.0) or not (im_m <= 7.5e+152):
		tmp = (math.cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))))
	else:
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if ((im_m <= 360.0) || !(im_m <= 7.5e+152))
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(1.0 - im_m) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(0.5 * im_m))))));
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if ((im_m <= 360.0) || ~((im_m <= 7.5e+152)))
		tmp = (cos(re) * 0.5) * ((1.0 - im_m) + (1.0 + (im_m * (1.0 + (0.5 * im_m)))));
	else
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[Or[LessEqual[im$95$m, 360.0], N[Not[LessEqual[im$95$m, 7.5e+152]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(1.0 - im$95$m), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(0.5 * im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 360 \lor \neg \left(im\_m \leq 7.5 \cdot 10^{+152}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\_m\right) + \left(1 + im\_m \cdot \left(1 + 0.5 \cdot im\_m\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 360 or 7.50000000000000046e152 < im

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

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

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

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

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

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

    if 360 < im < 7.50000000000000046e152

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 56.8%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative56.8%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified56.8%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 60.2%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr60.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 360 \lor \neg \left(im \leq 7.5 \cdot 10^{+152}\right):\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(\left(1 - im\right) + \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 86.2% accurate, 2.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 520:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im\_m \leq 7.5 \cdot 10^{+152}:\\ \;\;\;\;\left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(im\_m \cdot \left(0.5 \cdot im\_m + -1\right) + 2.5\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 520.0)
   (cos re)
   (if (<= im_m 7.5e+152)
     (*
      (+
       (+
        1.0
        (*
         im_m
         (+
          (*
           im_m
           (+
            0.5
            (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
          -1.0)))
       (+
        1.0
        (*
         im_m
         (+
          1.0
          (*
           im_m
           (+
            0.5
            (*
             im_m
             (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
      (+ 0.5 (* (* re re) -0.25)))
     (* (* (cos re) 0.5) (+ (* im_m (+ (* 0.5 im_m) -1.0)) 2.5)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 520.0) {
		tmp = cos(re);
	} else if (im_m <= 7.5e+152) {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = (cos(re) * 0.5) * ((im_m * ((0.5 * im_m) + -1.0)) + 2.5);
	}
	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 <= 520.0d0) then
        tmp = cos(re)
    else if (im_m <= 7.5d+152) then
        tmp = ((1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    else
        tmp = (cos(re) * 0.5d0) * ((im_m * ((0.5d0 * im_m) + (-1.0d0))) + 2.5d0)
    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 <= 520.0) {
		tmp = Math.cos(re);
	} else if (im_m <= 7.5e+152) {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	} else {
		tmp = (Math.cos(re) * 0.5) * ((im_m * ((0.5 * im_m) + -1.0)) + 2.5);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 520.0:
		tmp = math.cos(re)
	elif im_m <= 7.5e+152:
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	else:
		tmp = (math.cos(re) * 0.5) * ((im_m * ((0.5 * im_m) + -1.0)) + 2.5)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 520.0)
		tmp = cos(re);
	elseif (im_m <= 7.5e+152)
		tmp = Float64(Float64(Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	else
		tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(im_m * Float64(Float64(0.5 * im_m) + -1.0)) + 2.5));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 520.0)
		tmp = cos(re);
	elseif (im_m <= 7.5e+152)
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	else
		tmp = (cos(re) * 0.5) * ((im_m * ((0.5 * im_m) + -1.0)) + 2.5);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 520.0], N[Cos[re], $MachinePrecision], If[LessEqual[im$95$m, 7.5e+152], N[(N[(N[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(im$95$m * N[(N[(0.5 * im$95$m), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + 2.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|

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

\mathbf{elif}\;im\_m \leq 7.5 \cdot 10^{+152}:\\
\;\;\;\;\left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\

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


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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      12. 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) \]
      13. 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-rr61.8%

      \[\leadsto \color{blue}{\frac{\cos re \cdot -0.5}{-0.5}} \]
    6. Step-by-step derivation
      1. associate-/l*61.8%

        \[\leadsto \color{blue}{\cos re \cdot \frac{-0.5}{-0.5}} \]
      2. metadata-eval61.8%

        \[\leadsto \cos re \cdot \color{blue}{1} \]
      3. *-rgt-identity61.8%

        \[\leadsto \color{blue}{\cos re} \]
    7. Simplified61.8%

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

    if 520 < im < 7.50000000000000046e152

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 56.8%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative56.8%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified56.8%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 60.2%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr60.2%

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

    if 7.50000000000000046e152 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Applied egg-rr100.0%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{1.5}\right) \]
    5. Taylor expanded in im around 0 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 520:\\ \;\;\;\;\cos re\\ \mathbf{elif}\;im \leq 7.5 \cdot 10^{+152}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(im \cdot \left(0.5 \cdot im + -1\right) + 2.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 80.0% accurate, 2.9× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 600:\\ \;\;\;\;\cos re\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 600.0)
   (cos re)
   (*
    (+
     (+
      1.0
      (*
       im_m
       (+
        (*
         im_m
         (+
          0.5
          (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
        -1.0)))
     (+
      1.0
      (*
       im_m
       (+
        1.0
        (*
         im_m
         (+
          0.5
          (* im_m (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
    (+ 0.5 (* (* re re) -0.25)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 600.0) {
		tmp = cos(re);
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	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 <= 600.0d0) then
        tmp = cos(re)
    else
        tmp = ((1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    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 <= 600.0) {
		tmp = Math.cos(re);
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 600.0:
		tmp = math.cos(re)
	else:
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 600.0)
		tmp = cos(re);
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 600.0)
		tmp = cos(re);
	else
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 600.0], N[Cos[re], $MachinePrecision], N[(N[(N[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

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

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


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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
      12. 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) \]
      13. 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-rr61.8%

      \[\leadsto \color{blue}{\frac{\cos re \cdot -0.5}{-0.5}} \]
    6. Step-by-step derivation
      1. associate-/l*61.8%

        \[\leadsto \color{blue}{\cos re \cdot \frac{-0.5}{-0.5}} \]
      2. metadata-eval61.8%

        \[\leadsto \cos re \cdot \color{blue}{1} \]
      3. *-rgt-identity61.8%

        \[\leadsto \color{blue}{\cos re} \]
    7. Simplified61.8%

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

    if 600 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 81.4%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + \color{blue}{im \cdot 0.041666666666666664}\right)\right)\right)\right)\right) \]
    6. Simplified81.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 73.0%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr73.0%

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

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

Alternative 17: 57.0% accurate, 6.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 8.2 \cdot 10^{-38}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 + im\_m \cdot \left(im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im\_m \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot \left(im\_m \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 8.2e-38)
   1.0
   (*
    (+
     (+
      1.0
      (*
       im_m
       (+
        (*
         im_m
         (+
          0.5
          (* im_m (- (* im_m 0.041666666666666664) 0.16666666666666666))))
        -1.0)))
     (+
      1.0
      (*
       im_m
       (+
        1.0
        (*
         im_m
         (+
          0.5
          (* im_m (+ (* im_m 0.041666666666666664) 0.16666666666666666))))))))
    (+ 0.5 (* (* re re) -0.25)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 8.2e-38) {
		tmp = 1.0;
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	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 <= 8.2d-38) then
        tmp = 1.0d0
    else
        tmp = ((1.0d0 + (im_m * ((im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) - 0.16666666666666666d0)))) + (-1.0d0)))) + (1.0d0 + (im_m * (1.0d0 + (im_m * (0.5d0 + (im_m * ((im_m * 0.041666666666666664d0) + 0.16666666666666666d0)))))))) * (0.5d0 + ((re * re) * (-0.25d0)))
    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 <= 8.2e-38) {
		tmp = 1.0;
	} else {
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 8.2e-38:
		tmp = 1.0
	else:
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 8.2e-38)
		tmp = 1.0;
	else
		tmp = Float64(Float64(Float64(1.0 + Float64(im_m * Float64(Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + Float64(1.0 + Float64(im_m * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * Float64(Float64(im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * Float64(0.5 + Float64(Float64(re * re) * -0.25)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 8.2e-38)
		tmp = 1.0;
	else
		tmp = ((1.0 + (im_m * ((im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) - 0.16666666666666666)))) + -1.0))) + (1.0 + (im_m * (1.0 + (im_m * (0.5 + (im_m * ((im_m * 0.041666666666666664) + 0.16666666666666666)))))))) * (0.5 + ((re * re) * -0.25));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 8.2e-38], 1.0, N[(N[(N[(1.0 + N[(im$95$m * N[(N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] - 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(im$95$m * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * N[(N[(im$95$m * 0.041666666666666664), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 8.2 \cdot 10^{-38}:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 8.1999999999999996e-38

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\cos re \cdot -0.5}{\cos re \cdot -0.5 + \left(\cos re \cdot -0.5 - \cos re \cdot -0.5\right)}} \]
    6. Step-by-step derivation
      1. +-inverses33.0%

        \[\leadsto \frac{\cos re \cdot -0.5}{\cos re \cdot -0.5 + \color{blue}{0}} \]
      2. +-rgt-identity33.0%

        \[\leadsto \frac{\cos re \cdot -0.5}{\color{blue}{\cos re \cdot -0.5}} \]
      3. *-inverses33.0%

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

      \[\leadsto \color{blue}{1} \]

    if 8.1999999999999996e-38 < im

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\color{blue}{\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right)} + e^{im}\right) \]
    4. Taylor expanded in im around 0 82.6%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot im\right)\right)\right)\right)}\right) \]
    5. Step-by-step derivation
      1. *-commutative82.6%

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \color{blue}{\left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)}\right) \]
    7. Taylor expanded in re around 0 70.1%

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

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

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

        \[\leadsto \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \cdot \left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(0.041666666666666664 \cdot im - 0.16666666666666666\right)\right) - 1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.16666666666666666 + im \cdot 0.041666666666666664\right)\right)\right)\right)\right) \]
    11. Applied egg-rr70.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 8.2 \cdot 10^{-38}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\left(\left(1 + im \cdot \left(im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 - 0.16666666666666666\right)\right) + -1\right)\right) + \left(1 + im \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(im \cdot 0.041666666666666664 + 0.16666666666666666\right)\right)\right)\right)\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 29.3% accurate, 308.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ 1 \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 1.0)
im_m = fabs(im);
double code(double re, double im_m) {
	return 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 = 1.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return 1.0;
}
im_m = math.fabs(im)
def code(re, im_m):
	return 1.0
im_m = abs(im)
function code(re, im_m)
	return 1.0
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = 1.0;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := 1.0
\begin{array}{l}
im_m = \left|im\right|

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

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    12. 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) \]
    13. 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-rr27.6%

    \[\leadsto \color{blue}{\frac{\cos re \cdot -0.5}{\cos re \cdot -0.5 + \left(\cos re \cdot -0.5 - \cos re \cdot -0.5\right)}} \]
  6. Step-by-step derivation
    1. +-inverses27.6%

      \[\leadsto \frac{\cos re \cdot -0.5}{\cos re \cdot -0.5 + \color{blue}{0}} \]
    2. +-rgt-identity27.6%

      \[\leadsto \frac{\cos re \cdot -0.5}{\color{blue}{\cos re \cdot -0.5}} \]
    3. *-inverses27.6%

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

    \[\leadsto \color{blue}{1} \]
  8. Add Preprocessing

Alternative 19: 2.4% accurate, 308.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ 0 \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 0.0)
im_m = fabs(im);
double code(double re, double im_m) {
	return 0.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.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return 0.0;
}
im_m = math.fabs(im)
def code(re, im_m):
	return 0.0
im_m = abs(im)
function code(re, im_m)
	return 0.0
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = 0.0;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := 0.0
\begin{array}{l}
im_m = \left|im\right|

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{1}{e^{im}}} \cdot 0.5\right) \]
    12. 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) \]
    13. 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-rr2.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos re \cdot -0.5, -1, \cos re \cdot -0.5\right)} \]
  6. Step-by-step derivation
    1. fma-undefine2.3%

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

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

      \[\leadsto \cos re \cdot \color{blue}{0.5} + \cos re \cdot -0.5 \]
    4. *-commutative2.3%

      \[\leadsto \color{blue}{0.5 \cdot \cos re} + \cos re \cdot -0.5 \]
    5. +-commutative2.3%

      \[\leadsto \color{blue}{\cos re \cdot -0.5 + 0.5 \cdot \cos re} \]
    6. metadata-eval2.3%

      \[\leadsto \cos re \cdot -0.5 + \color{blue}{\left(--0.5\right)} \cdot \cos re \]
    7. distribute-lft-neg-in2.3%

      \[\leadsto \cos re \cdot -0.5 + \color{blue}{\left(--0.5 \cdot \cos re\right)} \]
    8. *-commutative2.3%

      \[\leadsto \cos re \cdot -0.5 + \left(-\color{blue}{\cos re \cdot -0.5}\right) \]
    9. sub-neg2.3%

      \[\leadsto \color{blue}{\cos re \cdot -0.5 - \cos re \cdot -0.5} \]
    10. +-inverses2.3%

      \[\leadsto \color{blue}{0} \]
  7. Simplified2.3%

    \[\leadsto \color{blue}{0} \]
  8. Add Preprocessing

Reproduce

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