math.exp on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 19.3s
Alternatives: 18
Speedup: 1.0×

Specification

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

\\
e^{re} \cdot \cos im
\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 18 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} \\ e^{re} \cdot \cos im \end{array} \]
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
	return exp(re) * cos(im);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
	return Math.exp(re) * Math.cos(im);
}
def code(re, im):
	return math.exp(re) * math.cos(im)
function code(re, im)
	return Float64(exp(re) * cos(im))
end
function tmp = code(re, im)
	tmp = exp(re) * cos(im);
end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
e^{re} \cdot \cos im
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

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

\\
e^{re} \cdot \cos im
\end{array}
Derivation
  1. Initial program 100.0%

    \[e^{re} \cdot \cos im \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 93.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.9998:\\
\;\;\;\;e^{re}\\

\mathbf{elif}\;e^{re} \leq 2:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\

\mathbf{else}:\\
\;\;\;\;e^{re}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 re) < 0.99980000000000002 or 2 < (exp.f64 re)

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6483.4%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified83.4%

      \[\leadsto \color{blue}{e^{re}} \]

    if 0.99980000000000002 < (exp.f64 re) < 2

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re\right)}, \mathsf{cos.f64}\left(im\right)\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(re + 1\right), \mathsf{cos.f64}\left(\color{blue}{im}\right)\right) \]
      2. +-lowering-+.f6499.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(re, 1\right), \mathsf{cos.f64}\left(\color{blue}{im}\right)\right) \]
    5. Simplified99.8%

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

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

Alternative 3: 92.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{re} \leq 0.9998:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;e^{re} \leq 2:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;e^{re}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (exp re) 0.9998) (exp re) (if (<= (exp re) 2.0) (cos im) (exp re))))
double code(double re, double im) {
	double tmp;
	if (exp(re) <= 0.9998) {
		tmp = exp(re);
	} else if (exp(re) <= 2.0) {
		tmp = cos(im);
	} else {
		tmp = exp(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (exp(re) <= 0.9998d0) then
        tmp = exp(re)
    else if (exp(re) <= 2.0d0) then
        tmp = cos(im)
    else
        tmp = exp(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (Math.exp(re) <= 0.9998) {
		tmp = Math.exp(re);
	} else if (Math.exp(re) <= 2.0) {
		tmp = Math.cos(im);
	} else {
		tmp = Math.exp(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.exp(re) <= 0.9998:
		tmp = math.exp(re)
	elif math.exp(re) <= 2.0:
		tmp = math.cos(im)
	else:
		tmp = math.exp(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (exp(re) <= 0.9998)
		tmp = exp(re);
	elseif (exp(re) <= 2.0)
		tmp = cos(im);
	else
		tmp = exp(re);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (exp(re) <= 0.9998)
		tmp = exp(re);
	elseif (exp(re) <= 2.0)
		tmp = cos(im);
	else
		tmp = exp(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.9998], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 2.0], N[Cos[im], $MachinePrecision], N[Exp[re], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.9998:\\
\;\;\;\;e^{re}\\

\mathbf{elif}\;e^{re} \leq 2:\\
\;\;\;\;\cos im\\

\mathbf{else}:\\
\;\;\;\;e^{re}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 re) < 0.99980000000000002 or 2 < (exp.f64 re)

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6483.4%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified83.4%

      \[\leadsto \color{blue}{e^{re}} \]

    if 0.99980000000000002 < (exp.f64 re) < 2

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6499.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified99.1%

      \[\leadsto \color{blue}{\cos im} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 96.1% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
t_0 := \cos im \cdot \left(1 + re \cdot \left(1 + re \cdot 0.5\right)\right)\\
\mathbf{if}\;re \leq -0.00039:\\
\;\;\;\;e^{re}\\

\mathbf{elif}\;re \leq 57:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -3.89999999999999993e-4

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f64100.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{e^{re}} \]

    if -3.89999999999999993e-4 < re < 57 or 5e152 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + \frac{1}{2} \cdot re\right)\right)}, \mathsf{cos.f64}\left(im\right)\right) \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + \frac{1}{2} \cdot re\right)\right)\right), \mathsf{cos.f64}\left(\color{blue}{im}\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + \frac{1}{2} \cdot re\right)\right)\right), \mathsf{cos.f64}\left(im\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(\frac{1}{2} \cdot re\right)\right)\right)\right), \mathsf{cos.f64}\left(im\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \frac{1}{2}\right)\right)\right)\right), \mathsf{cos.f64}\left(im\right)\right) \]
      5. *-lowering-*.f6498.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \frac{1}{2}\right)\right)\right)\right), \mathsf{cos.f64}\left(im\right)\right) \]
    5. Simplified98.9%

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

    if 57 < re < 5e152

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6478.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified78.6%

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

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

Alternative 5: 92.6% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.000116:\\
\;\;\;\;e^{re}\\

\mathbf{elif}\;re \leq 57:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -1.16e-4

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f64100.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{e^{re}} \]

    if -1.16e-4 < re < 57

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re\right)}, \mathsf{cos.f64}\left(im\right)\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\left(re + 1\right), \mathsf{cos.f64}\left(\color{blue}{im}\right)\right) \]
      2. +-lowering-+.f6499.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(re, 1\right), \mathsf{cos.f64}\left(\color{blue}{im}\right)\right) \]
    5. Simplified99.1%

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

    if 57 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6472.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified72.6%

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

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

Alternative 6: 69.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.5 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;re \leq -550:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 240:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t\_0\right) \cdot \left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.5 (* im im))))
   (if (<= re -550.0)
     t_0
     (if (<= re 240.0)
       (cos im)
       (*
        (+ 1.0 t_0)
        (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))))))))
double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -550.0) {
		tmp = t_0;
	} else if (re <= 240.0) {
		tmp = cos(im);
	} else {
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-0.5d0) * (im * im)
    if (re <= (-550.0d0)) then
        tmp = t_0
    else if (re <= 240.0d0) then
        tmp = cos(im)
    else
        tmp = (1.0d0 + t_0) * (1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0))))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -550.0) {
		tmp = t_0;
	} else if (re <= 240.0) {
		tmp = Math.cos(im);
	} else {
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.5 * (im * im)
	tmp = 0
	if re <= -550.0:
		tmp = t_0
	elif re <= 240.0:
		tmp = math.cos(im)
	else:
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))))
	return tmp
function code(re, im)
	t_0 = Float64(-0.5 * Float64(im * im))
	tmp = 0.0
	if (re <= -550.0)
		tmp = t_0;
	elseif (re <= 240.0)
		tmp = cos(im);
	else
		tmp = Float64(Float64(1.0 + t_0) * Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.5 * (im * im);
	tmp = 0.0;
	if (re <= -550.0)
		tmp = t_0;
	elseif (re <= 240.0)
		tmp = cos(im);
	else
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -550.0], t$95$0, If[LessEqual[re, 240.0], N[Cos[im], $MachinePrecision], N[(N[(1.0 + t$95$0), $MachinePrecision] * N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.5 \cdot \left(im \cdot im\right)\\
\mathbf{if}\;re \leq -550:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq 240:\\
\;\;\;\;\cos im\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -550 < re < 240

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f6497.9%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified97.9%

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

    if 240 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6472.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified72.6%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6460.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified60.5%

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

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

Alternative 7: 48.3% accurate, 4.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\\ \mathbf{if}\;re \leq -175:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 2 \cdot 10^{+88}:\\ \;\;\;\;1 + \frac{re \cdot \left(1 + t\_0 \cdot \left(re \cdot \left(-0.5 + re \cdot -0.16666666666666666\right)\right)\right)}{1 - t\_0}\\ \mathbf{else}:\\ \;\;\;\;\left(re \cdot \left(re \cdot re\right)\right) \cdot \left(0.16666666666666666 + \left(im \cdot im\right) \cdot -0.08333333333333333\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* re (+ 0.5 (* re 0.16666666666666666)))))
   (if (<= re -175.0)
     (* -0.5 (* im im))
     (if (<= re 2e+88)
       (+
        1.0
        (/
         (* re (+ 1.0 (* t_0 (* re (+ -0.5 (* re -0.16666666666666666))))))
         (- 1.0 t_0)))
       (*
        (* re (* re re))
        (+ 0.16666666666666666 (* (* im im) -0.08333333333333333)))))))
double code(double re, double im) {
	double t_0 = re * (0.5 + (re * 0.16666666666666666));
	double tmp;
	if (re <= -175.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2e+88) {
		tmp = 1.0 + ((re * (1.0 + (t_0 * (re * (-0.5 + (re * -0.16666666666666666)))))) / (1.0 - t_0));
	} else {
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = re * (0.5d0 + (re * 0.16666666666666666d0))
    if (re <= (-175.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 2d+88) then
        tmp = 1.0d0 + ((re * (1.0d0 + (t_0 * (re * ((-0.5d0) + (re * (-0.16666666666666666d0))))))) / (1.0d0 - t_0))
    else
        tmp = (re * (re * re)) * (0.16666666666666666d0 + ((im * im) * (-0.08333333333333333d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = re * (0.5 + (re * 0.16666666666666666));
	double tmp;
	if (re <= -175.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2e+88) {
		tmp = 1.0 + ((re * (1.0 + (t_0 * (re * (-0.5 + (re * -0.16666666666666666)))))) / (1.0 - t_0));
	} else {
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	}
	return tmp;
}
def code(re, im):
	t_0 = re * (0.5 + (re * 0.16666666666666666))
	tmp = 0
	if re <= -175.0:
		tmp = -0.5 * (im * im)
	elif re <= 2e+88:
		tmp = 1.0 + ((re * (1.0 + (t_0 * (re * (-0.5 + (re * -0.16666666666666666)))))) / (1.0 - t_0))
	else:
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333))
	return tmp
function code(re, im)
	t_0 = Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))
	tmp = 0.0
	if (re <= -175.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 2e+88)
		tmp = Float64(1.0 + Float64(Float64(re * Float64(1.0 + Float64(t_0 * Float64(re * Float64(-0.5 + Float64(re * -0.16666666666666666)))))) / Float64(1.0 - t_0)));
	else
		tmp = Float64(Float64(re * Float64(re * re)) * Float64(0.16666666666666666 + Float64(Float64(im * im) * -0.08333333333333333)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = re * (0.5 + (re * 0.16666666666666666));
	tmp = 0.0;
	if (re <= -175.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 2e+88)
		tmp = 1.0 + ((re * (1.0 + (t_0 * (re * (-0.5 + (re * -0.16666666666666666)))))) / (1.0 - t_0));
	else
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -175.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2e+88], N[(1.0 + N[(N[(re * N[(1.0 + N[(t$95$0 * N[(re * N[(-0.5 + N[(re * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(re * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(0.16666666666666666 + N[(N[(im * im), $MachinePrecision] * -0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;re \leq 2 \cdot 10^{+88}:\\
\;\;\;\;1 + \frac{re \cdot \left(1 + t\_0 \cdot \left(re \cdot \left(-0.5 + re \cdot -0.16666666666666666\right)\right)\right)}{1 - t\_0}\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -175 < re < 1.99999999999999992e88

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6454.9%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified54.9%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6448.3%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified48.3%

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)} \]
    9. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \left(\left(1 + re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right) \cdot \color{blue}{re}\right)\right) \]
      2. flip-+N/A

        \[\leadsto \mathsf{+.f64}\left(1, \left(\frac{1 \cdot 1 - \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right)}{1 - re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)} \cdot re\right)\right) \]
      3. associate-*l/N/A

        \[\leadsto \mathsf{+.f64}\left(1, \left(\frac{\left(1 \cdot 1 - \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right)\right) \cdot re}{\color{blue}{1 - re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)}}\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(\left(1 \cdot 1 - \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right)\right) \cdot re\right), \color{blue}{\left(1 - re \cdot \left(\frac{1}{2} + re \cdot \frac{1}{6}\right)\right)}\right)\right) \]
    10. Applied egg-rr51.5%

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

    if 1.99999999999999992e88 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6473.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified73.5%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6469.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified69.8%

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

      \[\leadsto \color{blue}{\frac{1}{6} \cdot \left({re}^{3} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
    10. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(\frac{1}{6} \cdot {re}^{3}\right) \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left({re}^{3} \cdot \frac{1}{6}\right) \cdot \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto {re}^{3} \cdot \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({re}^{3}\right), \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)}\right) \]
      5. cube-multN/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \left(re \cdot re\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot {re}^{2}\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left({re}^{2}\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left(re \cdot re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      10. distribute-lft-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot 1 + \color{blue}{\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} + \color{blue}{\frac{1}{6}} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)}\right)\right) \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{\frac{1}{6}}\right)\right)\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left({im}^{2} \cdot \frac{-1}{2}\right) \cdot \frac{1}{6}\right)\right)\right) \]
      15. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \color{blue}{\left(\frac{-1}{2} \cdot \frac{1}{6}\right)}\right)\right)\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \frac{-1}{12}\right)\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \left(\frac{1}{6} \cdot \color{blue}{\frac{-1}{2}}\right)\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left({im}^{2}\right), \color{blue}{\left(\frac{1}{6} \cdot \frac{-1}{2}\right)}\right)\right)\right) \]
      19. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left(im \cdot im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      21. metadata-eval69.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \frac{-1}{12}\right)\right)\right) \]
    11. Simplified69.8%

      \[\leadsto \color{blue}{\left(re \cdot \left(re \cdot re\right)\right) \cdot \left(0.16666666666666666 + \left(im \cdot im\right) \cdot -0.08333333333333333\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification49.3%

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

Alternative 8: 47.9% accurate, 6.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.5 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;re \leq -450:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 3.8 \cdot 10^{-14}:\\ \;\;\;\;1 + re \cdot \left(1 + \frac{re \cdot \left(re \cdot -0.25\right)}{re \cdot \left(re \cdot 0.16666666666666666\right) - \frac{re}{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t\_0\right) \cdot \left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.5 (* im im))))
   (if (<= re -450.0)
     t_0
     (if (<= re 3.8e-14)
       (+
        1.0
        (*
         re
         (+
          1.0
          (/
           (* re (* re -0.25))
           (- (* re (* re 0.16666666666666666)) (/ re 2.0))))))
       (*
        (+ 1.0 t_0)
        (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))))))))
double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -450.0) {
		tmp = t_0;
	} else if (re <= 3.8e-14) {
		tmp = 1.0 + (re * (1.0 + ((re * (re * -0.25)) / ((re * (re * 0.16666666666666666)) - (re / 2.0)))));
	} else {
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-0.5d0) * (im * im)
    if (re <= (-450.0d0)) then
        tmp = t_0
    else if (re <= 3.8d-14) then
        tmp = 1.0d0 + (re * (1.0d0 + ((re * (re * (-0.25d0))) / ((re * (re * 0.16666666666666666d0)) - (re / 2.0d0)))))
    else
        tmp = (1.0d0 + t_0) * (1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0))))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -450.0) {
		tmp = t_0;
	} else if (re <= 3.8e-14) {
		tmp = 1.0 + (re * (1.0 + ((re * (re * -0.25)) / ((re * (re * 0.16666666666666666)) - (re / 2.0)))));
	} else {
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.5 * (im * im)
	tmp = 0
	if re <= -450.0:
		tmp = t_0
	elif re <= 3.8e-14:
		tmp = 1.0 + (re * (1.0 + ((re * (re * -0.25)) / ((re * (re * 0.16666666666666666)) - (re / 2.0)))))
	else:
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))))
	return tmp
function code(re, im)
	t_0 = Float64(-0.5 * Float64(im * im))
	tmp = 0.0
	if (re <= -450.0)
		tmp = t_0;
	elseif (re <= 3.8e-14)
		tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(Float64(re * Float64(re * -0.25)) / Float64(Float64(re * Float64(re * 0.16666666666666666)) - Float64(re / 2.0))))));
	else
		tmp = Float64(Float64(1.0 + t_0) * Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.5 * (im * im);
	tmp = 0.0;
	if (re <= -450.0)
		tmp = t_0;
	elseif (re <= 3.8e-14)
		tmp = 1.0 + (re * (1.0 + ((re * (re * -0.25)) / ((re * (re * 0.16666666666666666)) - (re / 2.0)))));
	else
		tmp = (1.0 + t_0) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -450.0], t$95$0, If[LessEqual[re, 3.8e-14], N[(1.0 + N[(re * N[(1.0 + N[(N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision] / N[(N[(re * N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] - N[(re / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + t$95$0), $MachinePrecision] * N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.5 \cdot \left(im \cdot im\right)\\
\mathbf{if}\;re \leq -450:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq 3.8 \cdot 10^{-14}:\\
\;\;\;\;1 + re \cdot \left(1 + \frac{re \cdot \left(re \cdot -0.25\right)}{re \cdot \left(re \cdot 0.16666666666666666\right) - \frac{re}{2}}\right)\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -450 < re < 3.8000000000000002e-14

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.1%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.1%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6453.1%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified53.1%

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)} \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(re \cdot \frac{1}{6} + \color{blue}{\frac{1}{2}}\right)\right)\right)\right)\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(re \cdot \frac{1}{6}\right) + \color{blue}{re \cdot \frac{1}{2}}\right)\right)\right)\right) \]
      3. flip-+N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(\frac{\left(re \cdot \left(re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(re \cdot \frac{1}{6}\right)\right) - \left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)}{\color{blue}{re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}}}\right)\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(\left(re \cdot \left(re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(re \cdot \frac{1}{6}\right)\right) - \left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right), \color{blue}{\left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)}\right)\right)\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\left(re \cdot \left(re \cdot \frac{1}{6}\right)\right) \cdot \left(re \cdot \left(re \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(\color{blue}{re \cdot \left(re \cdot \frac{1}{6}\right)} - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      6. swap-sqrN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\left(re \cdot re\right) \cdot \left(\left(re \cdot \frac{1}{6}\right) \cdot \left(re \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(\color{blue}{re} \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\left(re \cdot re\right), \left(\left(re \cdot \frac{1}{6}\right) \cdot \left(re \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(\color{blue}{re} \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \left(\left(re \cdot \frac{1}{6}\right) \cdot \left(re \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      9. swap-sqrN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \left(\left(re \cdot re\right) \cdot \left(\frac{1}{6} \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\left(re \cdot re\right), \left(\frac{1}{6} \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \left(\frac{1}{6} \cdot \frac{1}{6}\right)\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \left(\left(re \cdot \frac{1}{2}\right) \cdot \left(re \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(re \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      13. swap-sqrN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \left(\left(re \cdot re\right) \cdot \left(\frac{1}{2} \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \color{blue}{\left(re \cdot \frac{1}{6}\right)} - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\left(re \cdot re\right), \left(\frac{1}{2} \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \color{blue}{\left(re \cdot \frac{1}{6}\right)} - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      15. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \left(\frac{1}{2} \cdot \frac{1}{2}\right)\right)\right), \left(re \cdot \left(\color{blue}{re} \cdot \frac{1}{6}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \left(re \cdot \left(re \cdot \color{blue}{\frac{1}{6}}\right) - re \cdot \frac{1}{2}\right)\right)\right)\right)\right) \]
      17. --lowering--.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \mathsf{\_.f64}\left(\left(re \cdot \left(re \cdot \frac{1}{6}\right)\right), \color{blue}{\left(re \cdot \frac{1}{2}\right)}\right)\right)\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \left(re \cdot \frac{1}{6}\right)\right), \left(\color{blue}{re} \cdot \frac{1}{2}\right)\right)\right)\right)\right)\right) \]
      19. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left(re \cdot \frac{1}{2}\right)\right)\right)\right)\right)\right) \]
      20. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left(re \cdot \frac{1}{\color{blue}{2}}\right)\right)\right)\right)\right)\right) \]
      21. div-invN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{36}\right)\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, re\right), \frac{1}{4}\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left(\frac{re}{\color{blue}{2}}\right)\right)\right)\right)\right)\right) \]
    10. Applied egg-rr53.1%

      \[\leadsto 1 + re \cdot \left(1 + \color{blue}{\frac{\left(re \cdot re\right) \cdot \left(\left(re \cdot re\right) \cdot 0.027777777777777776\right) - \left(re \cdot re\right) \cdot 0.25}{re \cdot \left(re \cdot 0.16666666666666666\right) - \frac{re}{2}}}\right) \]
    11. Taylor expanded in re around 0

      \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\color{blue}{\left(\frac{-1}{4} \cdot {re}^{2}\right)}, \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
    12. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left({re}^{2} \cdot \frac{-1}{4}\right), \mathsf{\_.f64}\left(\color{blue}{\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)}, \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(\left(re \cdot re\right) \cdot \frac{-1}{4}\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(\color{blue}{re}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\left(re \cdot \left(re \cdot \frac{-1}{4}\right)\right), \mathsf{\_.f64}\left(\color{blue}{\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)}, \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(re, \left(re \cdot \frac{-1}{4}\right)\right), \mathsf{\_.f64}\left(\color{blue}{\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)}, \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
      5. *-lowering-*.f6453.1%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{/.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \frac{-1}{4}\right)\right), \mathsf{\_.f64}\left(\mathsf{*.f64}\left(re, \color{blue}{\mathsf{*.f64}\left(re, \frac{1}{6}\right)}\right), \mathsf{/.f64}\left(re, 2\right)\right)\right)\right)\right)\right) \]
    13. Simplified53.1%

      \[\leadsto 1 + re \cdot \left(1 + \frac{\color{blue}{re \cdot \left(re \cdot -0.25\right)}}{re \cdot \left(re \cdot 0.16666666666666666\right) - \frac{re}{2}}\right) \]

    if 3.8000000000000002e-14 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6470.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified70.8%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6459.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified59.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -450:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 3.8 \cdot 10^{-14}:\\ \;\;\;\;1 + re \cdot \left(1 + \frac{re \cdot \left(re \cdot -0.25\right)}{re \cdot \left(re \cdot 0.16666666666666666\right) - \frac{re}{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + -0.5 \cdot \left(im \cdot im\right)\right) \cdot \left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 47.9% accurate, 6.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.5 \cdot \left(im \cdot im\right)\\ t_1 := 1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\ \mathbf{if}\;re \leq -590:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 4.5 \cdot 10^{-14}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t\_0\right) \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.5 (* im im)))
        (t_1 (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))))
   (if (<= re -590.0) t_0 (if (<= re 4.5e-14) t_1 (* (+ 1.0 t_0) t_1)))))
double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double t_1 = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	double tmp;
	if (re <= -590.0) {
		tmp = t_0;
	} else if (re <= 4.5e-14) {
		tmp = t_1;
	} else {
		tmp = (1.0 + t_0) * t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-0.5d0) * (im * im)
    t_1 = 1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))
    if (re <= (-590.0d0)) then
        tmp = t_0
    else if (re <= 4.5d-14) then
        tmp = t_1
    else
        tmp = (1.0d0 + t_0) * t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double t_1 = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	double tmp;
	if (re <= -590.0) {
		tmp = t_0;
	} else if (re <= 4.5e-14) {
		tmp = t_1;
	} else {
		tmp = (1.0 + t_0) * t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.5 * (im * im)
	t_1 = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))
	tmp = 0
	if re <= -590.0:
		tmp = t_0
	elif re <= 4.5e-14:
		tmp = t_1
	else:
		tmp = (1.0 + t_0) * t_1
	return tmp
function code(re, im)
	t_0 = Float64(-0.5 * Float64(im * im))
	t_1 = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666))))))
	tmp = 0.0
	if (re <= -590.0)
		tmp = t_0;
	elseif (re <= 4.5e-14)
		tmp = t_1;
	else
		tmp = Float64(Float64(1.0 + t_0) * t_1);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.5 * (im * im);
	t_1 = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	tmp = 0.0;
	if (re <= -590.0)
		tmp = t_0;
	elseif (re <= 4.5e-14)
		tmp = t_1;
	else
		tmp = (1.0 + t_0) * t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -590.0], t$95$0, If[LessEqual[re, 4.5e-14], t$95$1, N[(N[(1.0 + t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;re \leq 4.5 \cdot 10^{-14}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;\left(1 + t\_0\right) \cdot t\_1\\


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -590 < re < 4.4999999999999998e-14

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.1%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.1%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6453.1%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified53.1%

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

    if 4.4999999999999998e-14 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6470.8%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified70.8%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6459.2%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified59.2%

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

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

Alternative 10: 47.9% accurate, 8.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -420:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 2700:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -420 < re < 2700

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.4%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.4%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6451.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified51.9%

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

    if 2700 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6471.7%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified71.7%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6462.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified62.3%

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

      \[\leadsto \color{blue}{\frac{1}{6} \cdot \left({re}^{3} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
    10. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(\frac{1}{6} \cdot {re}^{3}\right) \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left({re}^{3} \cdot \frac{1}{6}\right) \cdot \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto {re}^{3} \cdot \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({re}^{3}\right), \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)}\right) \]
      5. cube-multN/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \left(re \cdot re\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot {re}^{2}\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left({re}^{2}\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left(re \cdot re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      10. distribute-lft-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot 1 + \color{blue}{\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} + \color{blue}{\frac{1}{6}} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)}\right)\right) \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{\frac{1}{6}}\right)\right)\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left({im}^{2} \cdot \frac{-1}{2}\right) \cdot \frac{1}{6}\right)\right)\right) \]
      15. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \color{blue}{\left(\frac{-1}{2} \cdot \frac{1}{6}\right)}\right)\right)\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \frac{-1}{12}\right)\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \left(\frac{1}{6} \cdot \color{blue}{\frac{-1}{2}}\right)\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left({im}^{2}\right), \color{blue}{\left(\frac{1}{6} \cdot \frac{-1}{2}\right)}\right)\right)\right) \]
      19. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left(im \cdot im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      21. metadata-eval62.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \frac{-1}{12}\right)\right)\right) \]
    11. Simplified62.3%

      \[\leadsto \color{blue}{\left(re \cdot \left(re \cdot re\right)\right) \cdot \left(0.16666666666666666 + \left(im \cdot im\right) \cdot -0.08333333333333333\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 11: 47.9% accurate, 8.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -480:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 115:\\ \;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(re \cdot \left(re \cdot re\right)\right) \cdot \left(0.16666666666666666 + \left(im \cdot im\right) \cdot -0.08333333333333333\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -480.0)
   (* -0.5 (* im im))
   (if (<= re 115.0)
     (+ 1.0 (* re (+ 1.0 (* re 0.5))))
     (*
      (* re (* re re))
      (+ 0.16666666666666666 (* (* im im) -0.08333333333333333))))))
double code(double re, double im) {
	double tmp;
	if (re <= -480.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 115.0) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-480.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 115.0d0) then
        tmp = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
    else
        tmp = (re * (re * re)) * (0.16666666666666666d0 + ((im * im) * (-0.08333333333333333d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -480.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 115.0) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -480.0:
		tmp = -0.5 * (im * im)
	elif re <= 115.0:
		tmp = 1.0 + (re * (1.0 + (re * 0.5)))
	else:
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -480.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 115.0)
		tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))));
	else
		tmp = Float64(Float64(re * Float64(re * re)) * Float64(0.16666666666666666 + Float64(Float64(im * im) * -0.08333333333333333)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -480.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 115.0)
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	else
		tmp = (re * (re * re)) * (0.16666666666666666 + ((im * im) * -0.08333333333333333));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -480.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 115.0], N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(re * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(0.16666666666666666 + N[(N[(im * im), $MachinePrecision] * -0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -480:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 115:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -480 < re < 115

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6452.7%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified52.7%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + \frac{1}{2} \cdot re\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + \frac{1}{2} \cdot re\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + \frac{1}{2} \cdot re\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
      5. *-lowering-*.f6452.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
    8. Simplified52.5%

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

    if 115 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re} + \frac{-1}{2} \cdot \left({im}^{2} \cdot e^{re}\right)} \]
    4. Step-by-step derivation
      1. *-lft-identityN/A

        \[\leadsto 1 \cdot e^{re} + \color{blue}{\frac{-1}{2}} \cdot \left({im}^{2} \cdot e^{re}\right) \]
      2. associate-*r*N/A

        \[\leadsto 1 \cdot e^{re} + \left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{e^{re}} \]
      3. distribute-rgt-inN/A

        \[\leadsto e^{re} \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(e^{re}\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      5. exp-lowering-exp.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right)\right) \]
      9. *-lowering-*.f6472.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{exp.f64}\left(re\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right)\right) \]
    5. Simplified72.6%

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

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{1}, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
      7. *-lowering-*.f6460.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, im\right)\right)\right)\right) \]
    8. Simplified60.5%

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

      \[\leadsto \color{blue}{\frac{1}{6} \cdot \left({re}^{3} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
    10. Step-by-step derivation
      1. associate-*r*N/A

        \[\leadsto \left(\frac{1}{6} \cdot {re}^{3}\right) \cdot \color{blue}{\left(1 + \frac{-1}{2} \cdot {im}^{2}\right)} \]
      2. *-commutativeN/A

        \[\leadsto \left({re}^{3} \cdot \frac{1}{6}\right) \cdot \left(\color{blue}{1} + \frac{-1}{2} \cdot {im}^{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto {re}^{3} \cdot \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({re}^{3}\right), \color{blue}{\left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)}\right) \]
      5. cube-multN/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot \left(re \cdot re\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(re \cdot {re}^{2}\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left({re}^{2}\right)\right), \left(\color{blue}{\frac{1}{6}} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \left(re \cdot re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      10. distribute-lft-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} \cdot 1 + \color{blue}{\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)}\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \left(\frac{1}{6} + \color{blue}{\frac{1}{6}} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{6} \cdot \left(\frac{-1}{2} \cdot {im}^{2}\right)\right)}\right)\right) \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left(\frac{-1}{2} \cdot {im}^{2}\right) \cdot \color{blue}{\frac{1}{6}}\right)\right)\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left(\left({im}^{2} \cdot \frac{-1}{2}\right) \cdot \frac{1}{6}\right)\right)\right) \]
      15. associate-*l*N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \color{blue}{\left(\frac{-1}{2} \cdot \frac{1}{6}\right)}\right)\right)\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \frac{-1}{12}\right)\right)\right) \]
      17. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \left({im}^{2} \cdot \left(\frac{1}{6} \cdot \color{blue}{\frac{-1}{2}}\right)\right)\right)\right) \]
      18. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left({im}^{2}\right), \color{blue}{\left(\frac{1}{6} \cdot \frac{-1}{2}\right)}\right)\right)\right) \]
      19. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\left(im \cdot im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      20. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \left(\color{blue}{\frac{1}{6}} \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      21. metadata-eval60.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, re\right)\right), \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(im, im\right), \frac{-1}{12}\right)\right)\right) \]
    11. Simplified60.5%

      \[\leadsto \color{blue}{\left(re \cdot \left(re \cdot re\right)\right) \cdot \left(0.16666666666666666 + \left(im \cdot im\right) \cdot -0.08333333333333333\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 12: 46.8% accurate, 9.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -600:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 1.7:\\ \;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -600.0)
   (* -0.5 (* im im))
   (if (<= re 1.7)
     (+ 1.0 (* re (+ 1.0 (* re 0.5))))
     (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))))
double code(double re, double im) {
	double tmp;
	if (re <= -600.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 1.7) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-600.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 1.7d0) then
        tmp = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
    else
        tmp = re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -600.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 1.7) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -600.0:
		tmp = -0.5 * (im * im)
	elif re <= 1.7:
		tmp = 1.0 + (re * (1.0 + (re * 0.5)))
	else:
		tmp = re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -600.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 1.7)
		tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))));
	else
		tmp = Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -600.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 1.7)
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	else
		tmp = re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -600.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.7], N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -600:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 1.7:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -600 < re < 1.69999999999999996

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + \frac{1}{2} \cdot re\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + \frac{1}{2} \cdot re\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + \frac{1}{2} \cdot re\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
      5. *-lowering-*.f6452.8%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
    8. Simplified52.8%

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

    if 1.69999999999999996 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6467.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified67.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified48.9%

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

      \[\leadsto \color{blue}{{re}^{3} \cdot \left(\frac{1}{6} + \left(\frac{1}{2} \cdot \frac{1}{re} + \frac{1}{{re}^{2}}\right)\right)} \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \left(\left(re \cdot re\right) \cdot re\right) \cdot \left(\color{blue}{\frac{1}{6}} + \left(\frac{1}{2} \cdot \frac{1}{re} + \frac{1}{{re}^{2}}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \left({re}^{2} \cdot re\right) \cdot \left(\frac{1}{6} + \left(\frac{1}{2} \cdot \frac{1}{re} + \frac{1}{{re}^{2}}\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \color{blue}{\left(re \cdot \left(\frac{1}{6} + \left(\frac{1}{2} \cdot \frac{1}{re} + \frac{1}{{re}^{2}}\right)\right)\right)} \]
      4. associate-+r+N/A

        \[\leadsto {re}^{2} \cdot \left(re \cdot \left(\left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right) + \color{blue}{\frac{1}{{re}^{2}}}\right)\right) \]
      5. distribute-lft-inN/A

        \[\leadsto {re}^{2} \cdot \left(re \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right) + \color{blue}{re \cdot \frac{1}{{re}^{2}}}\right) \]
      6. +-commutativeN/A

        \[\leadsto {re}^{2} \cdot \left(re \cdot \left(\frac{1}{2} \cdot \frac{1}{re} + \frac{1}{6}\right) + re \cdot \frac{1}{{re}^{2}}\right) \]
      7. distribute-rgt-inN/A

        \[\leadsto {re}^{2} \cdot \left(\left(\left(\frac{1}{2} \cdot \frac{1}{re}\right) \cdot re + \frac{1}{6} \cdot re\right) + \color{blue}{re} \cdot \frac{1}{{re}^{2}}\right) \]
      8. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \left(\left(\frac{1}{2} \cdot \left(\frac{1}{re} \cdot re\right) + \frac{1}{6} \cdot re\right) + re \cdot \frac{1}{{re}^{2}}\right) \]
      9. lft-mult-inverseN/A

        \[\leadsto {re}^{2} \cdot \left(\left(\frac{1}{2} \cdot 1 + \frac{1}{6} \cdot re\right) + re \cdot \frac{1}{{re}^{2}}\right) \]
      10. metadata-evalN/A

        \[\leadsto {re}^{2} \cdot \left(\left(\frac{1}{2} + \frac{1}{6} \cdot re\right) + re \cdot \frac{1}{{re}^{2}}\right) \]
      11. distribute-lft-outN/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) + \color{blue}{{re}^{2} \cdot \left(re \cdot \frac{1}{{re}^{2}}\right)} \]
      12. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) + \left({re}^{2} \cdot re\right) \cdot \color{blue}{\frac{1}{{re}^{2}}} \]
      13. unpow2N/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) + \left(\left(re \cdot re\right) \cdot re\right) \cdot \frac{1}{{re}^{2}} \]
      14. unpow3N/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) + {re}^{3} \cdot \frac{\color{blue}{1}}{{re}^{2}} \]
    11. Simplified48.9%

      \[\leadsto \color{blue}{re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 13: 46.8% accurate, 10.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -550:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 2.8:\\ \;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -550.0)
   (* -0.5 (* im im))
   (if (<= re 2.8)
     (+ 1.0 (* re (+ 1.0 (* re 0.5))))
     (* (+ 0.5 (* re 0.16666666666666666)) (* re re)))))
double code(double re, double im) {
	double tmp;
	if (re <= -550.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2.8) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-550.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 2.8d0) then
        tmp = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
    else
        tmp = (0.5d0 + (re * 0.16666666666666666d0)) * (re * re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -550.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2.8) {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	} else {
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -550.0:
		tmp = -0.5 * (im * im)
	elif re <= 2.8:
		tmp = 1.0 + (re * (1.0 + (re * 0.5)))
	else:
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -550.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 2.8)
		tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))));
	else
		tmp = Float64(Float64(0.5 + Float64(re * 0.16666666666666666)) * Float64(re * re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -550.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 2.8)
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	else
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -550.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8], N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -550:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 2.8:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)\\


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -550 < re < 2.7999999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + \frac{1}{2} \cdot re\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + \frac{1}{2} \cdot re\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + \frac{1}{2} \cdot re\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right)\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \left(re \cdot \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
      5. *-lowering-*.f6452.8%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{2}}\right)\right)\right)\right) \]
    8. Simplified52.8%

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

    if 2.7999999999999998 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6467.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified67.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified48.9%

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

      \[\leadsto \color{blue}{{re}^{3} \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right)} \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \left(\left(re \cdot re\right) \cdot re\right) \cdot \left(\color{blue}{\frac{1}{6}} + \frac{1}{2} \cdot \frac{1}{re}\right) \]
      2. unpow2N/A

        \[\leadsto \left({re}^{2} \cdot re\right) \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right) \]
      3. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \color{blue}{\left(re \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto {re}^{2} \cdot \left(re \cdot \left(\frac{1}{2} \cdot \frac{1}{re} + \color{blue}{\frac{1}{6}}\right)\right) \]
      5. distribute-rgt-inN/A

        \[\leadsto {re}^{2} \cdot \left(\left(\frac{1}{2} \cdot \frac{1}{re}\right) \cdot re + \color{blue}{\frac{1}{6} \cdot re}\right) \]
      6. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{re} \cdot re\right) + \color{blue}{\frac{1}{6}} \cdot re\right) \]
      7. lft-mult-inverseN/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} \cdot 1 + \frac{1}{6} \cdot re\right) \]
      8. metadata-evalN/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \color{blue}{\frac{1}{6}} \cdot re\right) \]
      9. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) \cdot \color{blue}{{re}^{2}} \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{2} + \frac{1}{6} \cdot re\right), \color{blue}{\left({re}^{2}\right)}\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right), \left({\color{blue}{re}}^{2}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right), \left({re}^{2}\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left({re}^{2}\right)\right) \]
      14. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left(re \cdot \color{blue}{re}\right)\right) \]
      15. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \mathsf{*.f64}\left(re, \color{blue}{re}\right)\right) \]
    11. Simplified48.9%

      \[\leadsto \color{blue}{\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 14: 46.6% accurate, 10.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -26:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 1.9:\\ \;\;\;\;re + 1\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -26.0)
   (* -0.5 (* im im))
   (if (<= re 1.9)
     (+ re 1.0)
     (* (+ 0.5 (* re 0.16666666666666666)) (* re re)))))
double code(double re, double im) {
	double tmp;
	if (re <= -26.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 1.9) {
		tmp = re + 1.0;
	} else {
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-26.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 1.9d0) then
        tmp = re + 1.0d0
    else
        tmp = (0.5d0 + (re * 0.16666666666666666d0)) * (re * re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -26.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 1.9) {
		tmp = re + 1.0;
	} else {
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -26.0:
		tmp = -0.5 * (im * im)
	elif re <= 1.9:
		tmp = re + 1.0
	else:
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -26.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 1.9)
		tmp = Float64(re + 1.0);
	else
		tmp = Float64(Float64(0.5 + Float64(re * 0.16666666666666666)) * Float64(re * re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -26.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 1.9)
		tmp = re + 1.0;
	else
		tmp = (0.5 + (re * 0.16666666666666666)) * (re * re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -26.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.9], N[(re + 1.0), $MachinePrecision], N[(N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -26:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 1.9:\\
\;\;\;\;re + 1\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)\\


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -26 < re < 1.8999999999999999

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re} \]
    7. Step-by-step derivation
      1. +-lowering-+.f6452.6%

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{re}\right) \]
    8. Simplified52.6%

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

    if 1.8999999999999999 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6467.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified67.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified48.9%

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

      \[\leadsto \color{blue}{{re}^{3} \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right)} \]
    10. Step-by-step derivation
      1. unpow3N/A

        \[\leadsto \left(\left(re \cdot re\right) \cdot re\right) \cdot \left(\color{blue}{\frac{1}{6}} + \frac{1}{2} \cdot \frac{1}{re}\right) \]
      2. unpow2N/A

        \[\leadsto \left({re}^{2} \cdot re\right) \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right) \]
      3. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \color{blue}{\left(re \cdot \left(\frac{1}{6} + \frac{1}{2} \cdot \frac{1}{re}\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto {re}^{2} \cdot \left(re \cdot \left(\frac{1}{2} \cdot \frac{1}{re} + \color{blue}{\frac{1}{6}}\right)\right) \]
      5. distribute-rgt-inN/A

        \[\leadsto {re}^{2} \cdot \left(\left(\frac{1}{2} \cdot \frac{1}{re}\right) \cdot re + \color{blue}{\frac{1}{6} \cdot re}\right) \]
      6. associate-*l*N/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{re} \cdot re\right) + \color{blue}{\frac{1}{6}} \cdot re\right) \]
      7. lft-mult-inverseN/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} \cdot 1 + \frac{1}{6} \cdot re\right) \]
      8. metadata-evalN/A

        \[\leadsto {re}^{2} \cdot \left(\frac{1}{2} + \color{blue}{\frac{1}{6}} \cdot re\right) \]
      9. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{6} \cdot re\right) \cdot \color{blue}{{re}^{2}} \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{2} + \frac{1}{6} \cdot re\right), \color{blue}{\left({re}^{2}\right)}\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{1}{6} \cdot re\right)\right), \left({\color{blue}{re}}^{2}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \frac{1}{6}\right)\right), \left({re}^{2}\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left({re}^{2}\right)\right) \]
      14. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \left(re \cdot \color{blue}{re}\right)\right) \]
      15. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \frac{1}{6}\right)\right), \mathsf{*.f64}\left(re, \color{blue}{re}\right)\right) \]
    11. Simplified48.9%

      \[\leadsto \color{blue}{\left(0.5 + re \cdot 0.16666666666666666\right) \cdot \left(re \cdot re\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification45.7%

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

Alternative 15: 46.6% accurate, 11.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -206:\\ \;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;re \leq 2.8:\\ \;\;\;\;re + 1\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(re \cdot \left(re \cdot 0.16666666666666666\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -206.0)
   (* -0.5 (* im im))
   (if (<= re 2.8) (+ re 1.0) (* re (* re (* re 0.16666666666666666))))))
double code(double re, double im) {
	double tmp;
	if (re <= -206.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2.8) {
		tmp = re + 1.0;
	} else {
		tmp = re * (re * (re * 0.16666666666666666));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= (-206.0d0)) then
        tmp = (-0.5d0) * (im * im)
    else if (re <= 2.8d0) then
        tmp = re + 1.0d0
    else
        tmp = re * (re * (re * 0.16666666666666666d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -206.0) {
		tmp = -0.5 * (im * im);
	} else if (re <= 2.8) {
		tmp = re + 1.0;
	} else {
		tmp = re * (re * (re * 0.16666666666666666));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -206.0:
		tmp = -0.5 * (im * im)
	elif re <= 2.8:
		tmp = re + 1.0
	else:
		tmp = re * (re * (re * 0.16666666666666666))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -206.0)
		tmp = Float64(-0.5 * Float64(im * im));
	elseif (re <= 2.8)
		tmp = Float64(re + 1.0);
	else
		tmp = Float64(re * Float64(re * Float64(re * 0.16666666666666666)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -206.0)
		tmp = -0.5 * (im * im);
	elseif (re <= 2.8)
		tmp = re + 1.0;
	else
		tmp = re * (re * (re * 0.16666666666666666));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -206.0], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8], N[(re + 1.0), $MachinePrecision], N[(re * N[(re * N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -206:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\

\mathbf{elif}\;re \leq 2.8:\\
\;\;\;\;re + 1\\

\mathbf{else}:\\
\;\;\;\;re \cdot \left(re \cdot \left(re \cdot 0.16666666666666666\right)\right)\\


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f642.5%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified2.5%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6427.4%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified27.4%

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

    if -206 < re < 2.7999999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re} \]
    7. Step-by-step derivation
      1. +-lowering-+.f6452.6%

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{re}\right) \]
    8. Simplified52.6%

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

    if 2.7999999999999998 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6467.0%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified67.0%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(1 + re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \color{blue}{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)}\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot re\right)}\right)\right)\right)\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right)\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(re, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right)\right) \]
    8. Simplified48.9%

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

      \[\leadsto \color{blue}{\frac{1}{6} \cdot {re}^{3}} \]
    10. Step-by-step derivation
      1. cube-multN/A

        \[\leadsto \frac{1}{6} \cdot \left(re \cdot \color{blue}{\left(re \cdot re\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \frac{1}{6} \cdot \left(re \cdot {re}^{\color{blue}{2}}\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(\frac{1}{6} \cdot re\right) \cdot \color{blue}{{re}^{2}} \]
      4. *-commutativeN/A

        \[\leadsto {re}^{2} \cdot \color{blue}{\left(\frac{1}{6} \cdot re\right)} \]
      5. unpow2N/A

        \[\leadsto \left(re \cdot re\right) \cdot \left(\color{blue}{\frac{1}{6}} \cdot re\right) \]
      6. associate-*r*N/A

        \[\leadsto re \cdot \color{blue}{\left(re \cdot \left(\frac{1}{6} \cdot re\right)\right)} \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(re, \color{blue}{\left(re \cdot \left(\frac{1}{6} \cdot re\right)\right)}\right) \]
      8. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \color{blue}{\left(\frac{1}{6} \cdot re\right)}\right)\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \left(re \cdot \color{blue}{\frac{1}{6}}\right)\right)\right) \]
      10. *-lowering-*.f6448.9%

        \[\leadsto \mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \mathsf{*.f64}\left(re, \color{blue}{\frac{1}{6}}\right)\right)\right) \]
    11. Simplified48.9%

      \[\leadsto \color{blue}{re \cdot \left(re \cdot \left(re \cdot 0.16666666666666666\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification45.7%

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

Alternative 16: 36.9% accurate, 13.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.5 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;re \leq -340:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;re \leq 8.2 \cdot 10^{+20}:\\ \;\;\;\;re + 1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.5 (* im im))))
   (if (<= re -340.0) t_0 (if (<= re 8.2e+20) (+ re 1.0) t_0))))
double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -340.0) {
		tmp = t_0;
	} else if (re <= 8.2e+20) {
		tmp = re + 1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-0.5d0) * (im * im)
    if (re <= (-340.0d0)) then
        tmp = t_0
    else if (re <= 8.2d+20) then
        tmp = re + 1.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -0.5 * (im * im);
	double tmp;
	if (re <= -340.0) {
		tmp = t_0;
	} else if (re <= 8.2e+20) {
		tmp = re + 1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.5 * (im * im)
	tmp = 0
	if re <= -340.0:
		tmp = t_0
	elif re <= 8.2e+20:
		tmp = re + 1.0
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(-0.5 * Float64(im * im))
	tmp = 0.0
	if (re <= -340.0)
		tmp = t_0;
	elseif (re <= 8.2e+20)
		tmp = Float64(re + 1.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.5 * (im * im);
	tmp = 0.0;
	if (re <= -340.0)
		tmp = t_0;
	elseif (re <= 8.2e+20)
		tmp = re + 1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -340.0], t$95$0, If[LessEqual[re, 8.2e+20], N[(re + 1.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.5 \cdot \left(im \cdot im\right)\\
\mathbf{if}\;re \leq -340:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;re \leq 8.2 \cdot 10^{+20}:\\
\;\;\;\;re + 1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -340 or 8.2e20 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    4. Step-by-step derivation
      1. cos-lowering-cos.f643.1%

        \[\leadsto \mathsf{cos.f64}\left(im\right) \]
    5. Simplified3.1%

      \[\leadsto \color{blue}{\cos im} \]
    6. Taylor expanded in im around 0

      \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot {im}^{2}} \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot {im}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right)\right) \]
      4. *-lowering-*.f648.9%

        \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right)\right) \]
    8. Simplified8.9%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot {im}^{2}} \]
    10. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left({im}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \left(im \cdot \color{blue}{im}\right)\right) \]
      3. *-lowering-*.f6421.1%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(im, \color{blue}{im}\right)\right) \]
    11. Simplified21.1%

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

    if -340 < re < 8.2e20

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Taylor expanded in im around 0

      \[\leadsto \color{blue}{e^{re}} \]
    4. Step-by-step derivation
      1. exp-lowering-exp.f6453.4%

        \[\leadsto \mathsf{exp.f64}\left(re\right) \]
    5. Simplified53.4%

      \[\leadsto \color{blue}{e^{re}} \]
    6. Taylor expanded in re around 0

      \[\leadsto \color{blue}{1 + re} \]
    7. Step-by-step derivation
      1. +-lowering-+.f6451.6%

        \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{re}\right) \]
    8. Simplified51.6%

      \[\leadsto \color{blue}{1 + re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification37.2%

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

Alternative 17: 28.7% accurate, 67.7× speedup?

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

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

    \[e^{re} \cdot \cos im \]
  2. Add Preprocessing
  3. Taylor expanded in im around 0

    \[\leadsto \color{blue}{e^{re}} \]
  4. Step-by-step derivation
    1. exp-lowering-exp.f6467.6%

      \[\leadsto \mathsf{exp.f64}\left(re\right) \]
  5. Simplified67.6%

    \[\leadsto \color{blue}{e^{re}} \]
  6. Taylor expanded in re around 0

    \[\leadsto \color{blue}{1 + re} \]
  7. Step-by-step derivation
    1. +-lowering-+.f6428.7%

      \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{re}\right) \]
  8. Simplified28.7%

    \[\leadsto \color{blue}{1 + re} \]
  9. Final simplification28.7%

    \[\leadsto re + 1 \]
  10. Add Preprocessing

Alternative 18: 28.2% accurate, 203.0× speedup?

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

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

    \[e^{re} \cdot \cos im \]
  2. Add Preprocessing
  3. Taylor expanded in im around 0

    \[\leadsto \color{blue}{e^{re}} \]
  4. Step-by-step derivation
    1. exp-lowering-exp.f6467.6%

      \[\leadsto \mathsf{exp.f64}\left(re\right) \]
  5. Simplified67.6%

    \[\leadsto \color{blue}{e^{re}} \]
  6. Taylor expanded in re around 0

    \[\leadsto \color{blue}{1} \]
  7. Step-by-step derivation
    1. Simplified28.3%

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

    Reproduce

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