math.exp on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 6.9s
Alternatives: 9
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 9 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. Final simplification100.0%

    \[\leadsto e^{re} \cdot \cos im \]

Alternative 2: 92.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{re} \leq 0.8:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;e^{re} \leq 1.0018:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;e^{re}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (exp re) 0.8) (exp re) (if (<= (exp re) 1.0018) (cos im) (exp re))))
double code(double re, double im) {
	double tmp;
	if (exp(re) <= 0.8) {
		tmp = exp(re);
	} else if (exp(re) <= 1.0018) {
		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.8d0) then
        tmp = exp(re)
    else if (exp(re) <= 1.0018d0) 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.8) {
		tmp = Math.exp(re);
	} else if (Math.exp(re) <= 1.0018) {
		tmp = Math.cos(im);
	} else {
		tmp = Math.exp(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.exp(re) <= 0.8:
		tmp = math.exp(re)
	elif math.exp(re) <= 1.0018:
		tmp = math.cos(im)
	else:
		tmp = math.exp(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if (exp(re) <= 0.8)
		tmp = exp(re);
	elseif (exp(re) <= 1.0018)
		tmp = cos(im);
	else
		tmp = exp(re);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (exp(re) <= 0.8)
		tmp = exp(re);
	elseif (exp(re) <= 1.0018)
		tmp = cos(im);
	else
		tmp = exp(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.8], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.0018], N[Cos[im], $MachinePrecision], N[Exp[re], $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in im around 0 89.3%

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

    if 0.80000000000000004 < (exp.f64 re) < 1.00180000000000002

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 99.3%

      \[\leadsto \color{blue}{\cos im} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{re} \leq 0.8:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;e^{re} \leq 1.0018:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;e^{re}\\ \end{array} \]

Alternative 3: 97.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.27 \lor \neg \left(re \leq 0.00182\right) \land re \leq 10^{+103}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \cdot \left(\left(re + 1\right) + \left(re \cdot re\right) \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= re -0.27) (and (not (<= re 0.00182)) (<= re 1e+103)))
   (exp re)
   (*
    (cos im)
    (+ (+ re 1.0) (* (* re re) (+ 0.5 (* re 0.16666666666666666)))))))
double code(double re, double im) {
	double tmp;
	if ((re <= -0.27) || (!(re <= 0.00182) && (re <= 1e+103))) {
		tmp = exp(re);
	} else {
		tmp = cos(im) * ((re + 1.0) + ((re * 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 <= (-0.27d0)) .or. (.not. (re <= 0.00182d0)) .and. (re <= 1d+103)) then
        tmp = exp(re)
    else
        tmp = cos(im) * ((re + 1.0d0) + ((re * re) * (0.5d0 + (re * 0.16666666666666666d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((re <= -0.27) || (!(re <= 0.00182) && (re <= 1e+103))) {
		tmp = Math.exp(re);
	} else {
		tmp = Math.cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (re <= -0.27) or (not (re <= 0.00182) and (re <= 1e+103)):
		tmp = math.exp(re)
	else:
		tmp = math.cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666))))
	return tmp
function code(re, im)
	tmp = 0.0
	if ((re <= -0.27) || (!(re <= 0.00182) && (re <= 1e+103)))
		tmp = exp(re);
	else
		tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(Float64(re * re) * Float64(0.5 + Float64(re * 0.16666666666666666)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((re <= -0.27) || (~((re <= 0.00182)) && (re <= 1e+103)))
		tmp = exp(re);
	else
		tmp = cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[re, -0.27], And[N[Not[LessEqual[re, 0.00182]], $MachinePrecision], LessEqual[re, 1e+103]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.27 \lor \neg \left(re \leq 0.00182\right) \land re \leq 10^{+103}:\\
\;\;\;\;e^{re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -0.27000000000000002 or 0.00182 < re < 1e103

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in im around 0 95.9%

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

    if -0.27000000000000002 < re < 0.00182 or 1e103 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 99.5%

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

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

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

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

        \[\leadsto \left(\left(0.16666666666666666 \cdot {re}^{3}\right) \cdot \cos im + 0.5 \cdot \color{blue}{\left({re}^{2} \cdot \cos im\right)}\right) + \left(\cos im \cdot re + \cos im\right) \]
      5. associate-*r*99.5%

        \[\leadsto \left(\left(0.16666666666666666 \cdot {re}^{3}\right) \cdot \cos im + \color{blue}{\left(0.5 \cdot {re}^{2}\right) \cdot \cos im}\right) + \left(\cos im \cdot re + \cos im\right) \]
      6. distribute-rgt-out99.5%

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

        \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot {re}^{3} + 0.5 \cdot {re}^{2}\right) \cdot \cos im} + \left(\cos im \cdot re + \cos im\right) \]
      8. *-commutative99.5%

        \[\leadsto \left(0.16666666666666666 \cdot {re}^{3} + 0.5 \cdot {re}^{2}\right) \cdot \cos im + \left(\color{blue}{re \cdot \cos im} + \cos im\right) \]
      9. distribute-lft1-in99.5%

        \[\leadsto \left(0.16666666666666666 \cdot {re}^{3} + 0.5 \cdot {re}^{2}\right) \cdot \cos im + \color{blue}{\left(re + 1\right) \cdot \cos im} \]
      10. distribute-rgt-out99.5%

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

        \[\leadsto \cos im \cdot \color{blue}{\left(\left(re + 1\right) + \left(0.16666666666666666 \cdot {re}^{3} + 0.5 \cdot {re}^{2}\right)\right)} \]
      12. cube-mult99.5%

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

        \[\leadsto \cos im \cdot \left(\left(re + 1\right) + \left(0.16666666666666666 \cdot \left(re \cdot \color{blue}{{re}^{2}}\right) + 0.5 \cdot {re}^{2}\right)\right) \]
      14. associate-*r*99.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.27 \lor \neg \left(re \leq 0.00182\right) \land re \leq 10^{+103}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \cdot \left(\left(re + 1\right) + \left(re \cdot re\right) \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\ \end{array} \]

Alternative 4: 96.2% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := re \cdot \left(re \cdot 0.5\right)\\
\mathbf{if}\;re \leq -0.27:\\
\;\;\;\;e^{re}\\

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

\mathbf{elif}\;re \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\

\mathbf{else}:\\
\;\;\;\;\cos im \cdot t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -0.27000000000000002 or 0.00182 < re < 1.8999999999999999e154

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in im around 0 96.3%

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

    if -0.27000000000000002 < re < 0.00182

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 99.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.8999999999999999e154 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.27:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;re \leq 0.00182:\\ \;\;\;\;\cos im \cdot \left(\left(re + 1\right) + re \cdot \left(re \cdot 0.5\right)\right)\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \cdot \left(re \cdot \left(re \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 5: 96.1% accurate, 1.8× speedup?

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

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

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

\mathbf{elif}\;re \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < -0.27000000000000002 or 0.00169999999999999991 < re < 1.8999999999999999e154

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in im around 0 96.3%

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

    if -0.27000000000000002 < re < 0.00169999999999999991

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 99.1%

      \[\leadsto \color{blue}{\cos im \cdot re + \cos im} \]
    3. Step-by-step derivation
      1. *-rgt-identity99.1%

        \[\leadsto \cos im \cdot re + \color{blue}{\cos im \cdot 1} \]
      2. distribute-lft-in99.1%

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

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

    if 1.8999999999999999e154 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.27:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;re \leq 0.0017:\\ \;\;\;\;\cos im \cdot \left(re + 1\right)\\ \mathbf{elif}\;re \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \cdot \left(re \cdot \left(re \cdot 0.5\right)\right)\\ \end{array} \]

Alternative 6: 93.2% accurate, 1.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -0.27000000000000002 or 0.00175000000000000004 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in im around 0 89.8%

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

    if -0.27000000000000002 < re < 0.00175000000000000004

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 99.1%

      \[\leadsto \color{blue}{\cos im \cdot re + \cos im} \]
    3. Step-by-step derivation
      1. *-rgt-identity99.1%

        \[\leadsto \cos im \cdot re + \color{blue}{\cos im \cdot 1} \]
      2. distribute-lft-in99.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.27:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;re \leq 0.00175:\\ \;\;\;\;\cos im \cdot \left(re + 1\right)\\ \mathbf{else}:\\ \;\;\;\;e^{re}\\ \end{array} \]

Alternative 7: 59.3% accurate, 2.0× speedup?

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

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

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 67.0%

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

    if 3.79999999999999996e56 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 79.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\cos im \cdot \left(re \cdot re\right)\right) \cdot 0.5} \]
      3. associate-*r*79.2%

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot {re}^{2}} \]
    9. Step-by-step derivation
      1. *-commutative60.9%

        \[\leadsto \color{blue}{{re}^{2} \cdot 0.5} \]
      2. unpow260.9%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot 0.5 \]
      3. associate-*r*60.9%

        \[\leadsto \color{blue}{re \cdot \left(re \cdot 0.5\right)} \]
    10. Simplified60.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 3.8 \cdot 10^{+56}:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(re \cdot 0.5\right)\\ \end{array} \]

Alternative 8: 37.1% accurate, 28.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 16.5:\\
\;\;\;\;re + 1\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 71.0%

      \[\leadsto \color{blue}{\cos im \cdot re + \cos im} \]
    3. Step-by-step derivation
      1. *-rgt-identity71.0%

        \[\leadsto \cos im \cdot re + \color{blue}{\cos im \cdot 1} \]
      2. distribute-lft-in71.0%

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

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

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

    if 16.5 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0 64.4%

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

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

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

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

        \[\leadsto \left(0.5 \cdot {re}^{2}\right) \cdot \cos im + \color{blue}{\left(re + 1\right) \cdot \cos im} \]
      5. distribute-rgt-out64.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\cos im \cdot \left(re \cdot re\right)\right) \cdot 0.5} \]
      3. associate-*r*64.4%

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

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

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

      \[\leadsto \color{blue}{0.5 \cdot {re}^{2}} \]
    9. Step-by-step derivation
      1. *-commutative49.5%

        \[\leadsto \color{blue}{{re}^{2} \cdot 0.5} \]
      2. unpow249.5%

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot 0.5 \]
      3. associate-*r*49.5%

        \[\leadsto \color{blue}{re \cdot \left(re \cdot 0.5\right)} \]
    10. Simplified49.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 16.5:\\ \;\;\;\;re + 1\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(re \cdot 0.5\right)\\ \end{array} \]

Alternative 9: 28.5% 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. Taylor expanded in re around 0 55.4%

    \[\leadsto \color{blue}{\cos im \cdot re + \cos im} \]
  3. Step-by-step derivation
    1. *-rgt-identity55.4%

      \[\leadsto \cos im \cdot re + \color{blue}{\cos im \cdot 1} \]
    2. distribute-lft-in55.4%

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

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

    \[\leadsto \color{blue}{1 + re} \]
  6. Final simplification32.4%

    \[\leadsto re + 1 \]

Reproduce

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