math.exp on complex, real part

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

    \[e^{re} \cdot \cos im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. expm1-log1p-u71.5%

      \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
    2. expm1-undefine71.5%

      \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
    3. exp-diff71.5%

      \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
    4. log1p-undefine71.5%

      \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
    5. rem-exp-log100.0%

      \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
    6. exp-1-e100.0%

      \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
  4. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
  5. Step-by-step derivation
    1. *-commutative100.0%

      \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
    2. clear-num100.0%

      \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
    3. un-div-inv100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
    4. clear-num100.0%

      \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
    5. e-exp-1100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
    6. div-exp100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
    7. add-exp-log71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
    8. expm1-undefine71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
    9. log1p-define71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
    10. *-rgt-identity71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
    11. expm1-log1p-u100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
    12. *-rgt-identity100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
  6. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
  7. Add Preprocessing

Alternative 2: 92.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{re} \leq 0.02 \lor \neg \left(e^{re} \leq 1.01\right):\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= (exp re) 0.02) (not (<= (exp re) 1.01))) (exp re) (cos im)))
double code(double re, double im) {
	double tmp;
	if ((exp(re) <= 0.02) || !(exp(re) <= 1.01)) {
		tmp = exp(re);
	} else {
		tmp = cos(im);
	}
	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.02d0) .or. (.not. (exp(re) <= 1.01d0))) then
        tmp = exp(re)
    else
        tmp = cos(im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((Math.exp(re) <= 0.02) || !(Math.exp(re) <= 1.01)) {
		tmp = Math.exp(re);
	} else {
		tmp = Math.cos(im);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (math.exp(re) <= 0.02) or not (math.exp(re) <= 1.01):
		tmp = math.exp(re)
	else:
		tmp = math.cos(im)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((exp(re) <= 0.02) || !(exp(re) <= 1.01))
		tmp = exp(re);
	else
		tmp = cos(im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((exp(re) <= 0.02) || ~((exp(re) <= 1.01)))
		tmp = exp(re);
	else
		tmp = cos(im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.02], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.01]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.02 \lor \neg \left(e^{re} \leq 1.01\right):\\
\;\;\;\;e^{re}\\

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


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

    1. Initial program 100.0%

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

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

    if 0.0200000000000000004 < (exp.f64 re) < 1.01000000000000001

    1. Initial program 100.0%

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

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

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

Alternative 3: 100.0% accurate, 1.0× speedup?

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

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

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

    \[\leadsto \cos im \cdot e^{re} \]
  4. Add Preprocessing

Alternative 4: 96.5% accurate, 1.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;\cos im \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 2 regimes
  2. if re < -0.065000000000000002 or 0.0126 < re < 7.4999999999999999e82

    1. Initial program 100.0%

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

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

    if -0.065000000000000002 < re < 0.0126 or 7.4999999999999999e82 < re

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.065 \lor \neg \left(re \leq 0.0126\right) \land re \leq 7.5 \cdot 10^{+82}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \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 5: 96.3% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.034 \lor \neg \left(re \leq 0.0068\right) \land re \leq 1.85 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -0.034000000000000002 or 0.00679999999999999962 < re < 1.84999999999999997e154

    1. Initial program 100.0%

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

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

    if -0.034000000000000002 < re < 0.00679999999999999962 or 1.84999999999999997e154 < re

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -0.034 \lor \neg \left(re \leq 0.0068\right) \land re \leq 1.85 \cdot 10^{+154}:\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\cos im \cdot \left(1 + re \cdot \left(1 + re \cdot 0.5\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 92.7% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.034 \lor \neg \left(re \leq 0.00185\right):\\
\;\;\;\;e^{re}\\

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


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

    1. Initial program 100.0%

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

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

    if -0.034000000000000002 < re < 0.0018500000000000001

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\cos im + re \cdot \cos im} \]
    4. Step-by-step derivation
      1. distribute-rgt1-in99.0%

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

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

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

Alternative 7: 74.3% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.07:\\ \;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\ \mathbf{elif}\;re \leq 0.00155:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;1 + 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 -0.07)
   (/ 1.0 (+ 1.0 (* re (+ (* re 0.5) -1.0))))
   (if (<= re 0.00155)
     (cos im)
     (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))))))
double code(double re, double im) {
	double tmp;
	if (re <= -0.07) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else if (re <= 0.00155) {
		tmp = cos(im);
	} else {
		tmp = 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) :: tmp
    if (re <= (-0.07d0)) then
        tmp = 1.0d0 / (1.0d0 + (re * ((re * 0.5d0) + (-1.0d0))))
    else if (re <= 0.00155d0) then
        tmp = cos(im)
    else
        tmp = 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 tmp;
	if (re <= -0.07) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else if (re <= 0.00155) {
		tmp = Math.cos(im);
	} else {
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -0.07:
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)))
	elif re <= 0.00155:
		tmp = math.cos(im)
	else:
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -0.07)
		tmp = Float64(1.0 / Float64(1.0 + Float64(re * Float64(Float64(re * 0.5) + -1.0))));
	elseif (re <= 0.00155)
		tmp = cos(im);
	else
		tmp = 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)
	tmp = 0.0;
	if (re <= -0.07)
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	elseif (re <= 0.00155)
		tmp = cos(im);
	else
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -0.07], N[(1.0 / N[(1.0 + N[(re * N[(N[(re * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 0.00155], N[Cos[im], $MachinePrecision], N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.07:\\
\;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\

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

\mathbf{else}:\\
\;\;\;\;1 + 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 < -0.070000000000000007

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u0.0%

        \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
      2. expm1-undefine0.0%

        \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
      3. exp-diff0.0%

        \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
      4. log1p-undefine0.0%

        \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
      5. rem-exp-log100.0%

        \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
      6. exp-1-e100.0%

        \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
    5. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
      2. clear-num100.0%

        \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
      3. un-div-inv100.0%

        \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
      4. clear-num100.0%

        \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
      5. e-exp-1100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
      6. div-exp100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
      7. add-exp-log0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
      8. expm1-undefine0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
      9. log1p-define0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
      10. *-rgt-identity0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
      11. expm1-log1p-u100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
      12. *-rgt-identity100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
    7. Taylor expanded in re around 0 53.7%

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

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

    if -0.070000000000000007 < re < 0.00154999999999999995

    1. Initial program 100.0%

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

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

    if 0.00154999999999999995 < re

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 8: 53.5% accurate, 11.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -1.1:\\ \;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + 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 -1.1)
   (/ 1.0 (+ 1.0 (* re (+ (* re 0.5) -1.0))))
   (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))))
double code(double re, double im) {
	double tmp;
	if (re <= -1.1) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else {
		tmp = 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) :: tmp
    if (re <= (-1.1d0)) then
        tmp = 1.0d0 / (1.0d0 + (re * ((re * 0.5d0) + (-1.0d0))))
    else
        tmp = 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 tmp;
	if (re <= -1.1) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else {
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -1.1:
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)))
	else:
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -1.1)
		tmp = Float64(1.0 / Float64(1.0 + Float64(re * Float64(Float64(re * 0.5) + -1.0))));
	else
		tmp = 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)
	tmp = 0.0;
	if (re <= -1.1)
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	else
		tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -1.1], N[(1.0 / N[(1.0 + N[(re * N[(N[(re * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1:\\
\;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u0.0%

        \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
      2. expm1-undefine0.0%

        \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
      3. exp-diff0.0%

        \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
      4. log1p-undefine0.0%

        \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
      5. rem-exp-log100.0%

        \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
      6. exp-1-e100.0%

        \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
    5. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
      2. clear-num100.0%

        \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
      3. un-div-inv100.0%

        \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
      4. clear-num100.0%

        \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
      5. e-exp-1100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
      6. div-exp100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
      7. add-exp-log0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
      8. expm1-undefine0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
      9. log1p-define0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
      10. *-rgt-identity0.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
      11. expm1-log1p-u100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
      12. *-rgt-identity100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
    7. Taylor expanded in re around 0 53.7%

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

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

    if -1.1000000000000001 < re

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 9: 50.5% accurate, 12.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -0.0001:\\ \;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= re -0.0001)
   (/ 1.0 (+ 1.0 (* re (+ (* re 0.5) -1.0))))
   (+ 1.0 (* re (+ 1.0 (* re 0.5))))))
double code(double re, double im) {
	double tmp;
	if (re <= -0.0001) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else {
		tmp = 1.0 + (re * (1.0 + (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.0001d0)) then
        tmp = 1.0d0 / (1.0d0 + (re * ((re * 0.5d0) + (-1.0d0))))
    else
        tmp = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= -0.0001) {
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	} else {
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= -0.0001:
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)))
	else:
		tmp = 1.0 + (re * (1.0 + (re * 0.5)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= -0.0001)
		tmp = Float64(1.0 / Float64(1.0 + Float64(re * Float64(Float64(re * 0.5) + -1.0))));
	else
		tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= -0.0001)
		tmp = 1.0 / (1.0 + (re * ((re * 0.5) + -1.0)));
	else
		tmp = 1.0 + (re * (1.0 + (re * 0.5)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, -0.0001], N[(1.0 / N[(1.0 + N[(re * N[(N[(re * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0001:\\
\;\;\;\;\frac{1}{1 + re \cdot \left(re \cdot 0.5 + -1\right)}\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u1.3%

        \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
      2. expm1-undefine1.4%

        \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
      3. exp-diff1.4%

        \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
      4. log1p-undefine1.4%

        \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
      5. rem-exp-log100.0%

        \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
      6. exp-1-e100.0%

        \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
    5. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
      2. clear-num100.0%

        \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
      3. un-div-inv100.0%

        \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
      4. clear-num100.0%

        \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
      5. e-exp-1100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
      6. div-exp100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
      7. add-exp-log1.4%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
      8. expm1-undefine1.4%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
      9. log1p-define1.4%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
      10. *-rgt-identity1.4%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
      11. expm1-log1p-u100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
      12. *-rgt-identity100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
    7. Taylor expanded in re around 0 53.6%

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

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

    if -1.00000000000000005e-4 < re

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{1 + re \cdot \left(1 + 0.5 \cdot re\right)} \]
    5. Step-by-step derivation
      1. *-commutative83.9%

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

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

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

Alternative 10: 38.3% accurate, 14.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.95 \cdot 10^{+164}:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 1.94999999999999993e164 < im

    1. Initial program 100.0%

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

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

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

        \[\leadsto 1 + -0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    6. Applied egg-rr29.3%

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

Alternative 11: 37.8% accurate, 16.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.95 \cdot 10^{+164}:\\
\;\;\;\;1 + re \cdot \left(re \cdot 0.5\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto 1 + re \cdot \color{blue}{\left(re \cdot \left(0.5 + \frac{1}{re}\right)\right)} \]
    8. Taylor expanded in re around inf 35.5%

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

    if 1.94999999999999993e164 < im

    1. Initial program 100.0%

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

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

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

        \[\leadsto 1 + -0.5 \cdot \color{blue}{\left(im \cdot im\right)} \]
    6. Applied egg-rr29.3%

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

Alternative 12: 33.1% accurate, 16.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 28000:\\
\;\;\;\;\frac{1}{1 - re}\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u61.6%

        \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
      2. expm1-undefine61.6%

        \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
      3. exp-diff61.6%

        \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
      4. log1p-undefine61.6%

        \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
      5. rem-exp-log100.0%

        \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
      6. exp-1-e100.0%

        \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
    5. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
      2. clear-num100.0%

        \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
      3. un-div-inv100.0%

        \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
      4. clear-num100.0%

        \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
      5. e-exp-1100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
      6. div-exp100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
      7. add-exp-log61.6%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
      8. expm1-undefine61.6%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
      9. log1p-define61.6%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
      10. *-rgt-identity61.6%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
      11. expm1-log1p-u100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
      12. *-rgt-identity100.0%

        \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
    7. Taylor expanded in re around 0 62.3%

      \[\leadsto \frac{\cos im}{\color{blue}{1 + -1 \cdot re}} \]
    8. Step-by-step derivation
      1. neg-mul-162.3%

        \[\leadsto \frac{\cos im}{1 + \color{blue}{\left(-re\right)}} \]
      2. unsub-neg62.3%

        \[\leadsto \frac{\cos im}{\color{blue}{1 - re}} \]
    9. Simplified62.3%

      \[\leadsto \frac{\cos im}{\color{blue}{1 - re}} \]
    10. Taylor expanded in im around 0 33.4%

      \[\leadsto \color{blue}{\frac{1}{1 - re}} \]

    if 28000 < re

    1. Initial program 100.0%

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

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

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

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

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

Alternative 13: 29.6% accurate, 40.6× speedup?

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

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

    \[e^{re} \cdot \cos im \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. expm1-log1p-u71.5%

      \[\leadsto e^{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(re\right)\right)}} \cdot \cos im \]
    2. expm1-undefine71.5%

      \[\leadsto e^{\color{blue}{e^{\mathsf{log1p}\left(re\right)} - 1}} \cdot \cos im \]
    3. exp-diff71.5%

      \[\leadsto \color{blue}{\frac{e^{e^{\mathsf{log1p}\left(re\right)}}}{e^{1}}} \cdot \cos im \]
    4. log1p-undefine71.5%

      \[\leadsto \frac{e^{e^{\color{blue}{\log \left(1 + re\right)}}}}{e^{1}} \cdot \cos im \]
    5. rem-exp-log100.0%

      \[\leadsto \frac{e^{\color{blue}{1 + re}}}{e^{1}} \cdot \cos im \]
    6. exp-1-e100.0%

      \[\leadsto \frac{e^{1 + re}}{\color{blue}{e}} \cdot \cos im \]
  4. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{e^{1 + re}}{e}} \cdot \cos im \]
  5. Step-by-step derivation
    1. *-commutative100.0%

      \[\leadsto \color{blue}{\cos im \cdot \frac{e^{1 + re}}{e}} \]
    2. clear-num100.0%

      \[\leadsto \cos im \cdot \color{blue}{\frac{1}{\frac{e}{e^{1 + re}}}} \]
    3. un-div-inv100.0%

      \[\leadsto \color{blue}{\frac{\cos im}{\frac{e}{e^{1 + re}}}} \]
    4. clear-num100.0%

      \[\leadsto \frac{\cos im}{\color{blue}{\frac{1}{\frac{e^{1 + re}}{e}}}} \]
    5. e-exp-1100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{\frac{e^{1 + re}}{\color{blue}{e^{1}}}}} \]
    6. div-exp100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{\color{blue}{e^{\left(1 + re\right) - 1}}}} \]
    7. add-exp-log71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{e^{\log \left(1 + re\right)}} - 1}}} \]
    8. expm1-undefine71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{\mathsf{expm1}\left(\log \left(1 + re\right)\right)}}}} \]
    9. log1p-define71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(re\right)}\right)}}} \]
    10. *-rgt-identity71.5%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{re \cdot 1}\right)\right)}}} \]
    11. expm1-log1p-u100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re \cdot 1}}}} \]
    12. *-rgt-identity100.0%

      \[\leadsto \frac{\cos im}{\frac{1}{e^{\color{blue}{re}}}} \]
  6. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{\cos im}{\frac{1}{e^{re}}}} \]
  7. Taylor expanded in re around 0 46.5%

    \[\leadsto \frac{\cos im}{\color{blue}{1 + -1 \cdot re}} \]
  8. Step-by-step derivation
    1. neg-mul-146.5%

      \[\leadsto \frac{\cos im}{1 + \color{blue}{\left(-re\right)}} \]
    2. unsub-neg46.5%

      \[\leadsto \frac{\cos im}{\color{blue}{1 - re}} \]
  9. Simplified46.5%

    \[\leadsto \frac{\cos im}{\color{blue}{1 - re}} \]
  10. Taylor expanded in im around 0 25.1%

    \[\leadsto \color{blue}{\frac{1}{1 - re}} \]
  11. Add Preprocessing

Alternative 14: 29.5% accurate, 67.7× speedup?

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

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

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

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

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

      \[\leadsto \color{blue}{re + 1} \]
  6. Simplified24.7%

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

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

Alternative 15: 28.9% 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 70.3%

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

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

Reproduce

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