math.exp on complex, imaginary part

Percentage Accurate: 100.0% → 100.0%
Time: 5.6s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

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

Alternative 1: 100.0% accurate, 0.5× speedup?

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e^{re} \cdot \sin im\right)\right)} \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e^{re} \cdot \sin im\right)\right)} \]
  5. Step-by-step derivation
    1. log1p-expm1-u100.0%

      \[\leadsto \color{blue}{e^{re} \cdot \sin im} \]
    2. *-commutative100.0%

      \[\leadsto \color{blue}{\sin im \cdot e^{re}} \]
    3. add-sqr-sqrt100.0%

      \[\leadsto \sin im \cdot \color{blue}{\left(\sqrt{e^{re}} \cdot \sqrt{e^{re}}\right)} \]
    4. associate-*r*100.0%

      \[\leadsto \color{blue}{\left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \sqrt{e^{re}}} \]
  6. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \sqrt{e^{re}}} \]
  7. Step-by-step derivation
    1. pow1/2100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{{\left(e^{re}\right)}^{0.5}} \]
    2. pow-exp100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{e^{re \cdot 0.5}} \]
  8. Applied egg-rr100.0%

    \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{e^{re \cdot 0.5}} \]
  9. Final simplification100.0%

    \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot e^{re \cdot 0.5} \]
  10. Add Preprocessing

Alternative 2: 93.2% accurate, 0.6× speedup?

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

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

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

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \sin im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log50.7%

        \[\leadsto e^{re} \cdot \color{blue}{e^{\log \sin im}} \]
      2. prod-exp50.7%

        \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    4. Applied egg-rr50.7%

      \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    5. Taylor expanded in re around inf 100.0%

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

    if 0.0 < (exp.f64 re) < 1.00000200000000006

    1. Initial program 100.0%

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

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

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

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

    if 1.00000200000000006 < (exp.f64 re)

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{im \cdot e^{re}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification93.7%

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

Alternative 3: 92.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;e^{re} \leq 1.000002:\\
\;\;\;\;\sin im\\

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


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

    1. Initial program 100.0%

      \[e^{re} \cdot \sin im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log50.7%

        \[\leadsto e^{re} \cdot \color{blue}{e^{\log \sin im}} \]
      2. prod-exp50.7%

        \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    4. Applied egg-rr50.7%

      \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    5. Taylor expanded in re around inf 100.0%

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

    if 0.0 < (exp.f64 re) < 1.00000200000000006

    1. Initial program 100.0%

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

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

    if 1.00000200000000006 < (exp.f64 re)

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{im \cdot e^{re}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification93.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{re} \leq 0:\\ \;\;\;\;e^{re}\\ \mathbf{elif}\;e^{re} \leq 1.000002:\\ \;\;\;\;\sin im\\ \mathbf{else}:\\ \;\;\;\;im \cdot e^{re}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 100.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{re \cdot 0.5}\\ t\_0 \cdot \left(\sin im \cdot t\_0\right) \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (exp (* re 0.5)))) (* t_0 (* (sin im) t_0))))
double code(double re, double im) {
	double t_0 = exp((re * 0.5));
	return t_0 * (sin(im) * t_0);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    t_0 = exp((re * 0.5d0))
    code = t_0 * (sin(im) * t_0)
end function
public static double code(double re, double im) {
	double t_0 = Math.exp((re * 0.5));
	return t_0 * (Math.sin(im) * t_0);
}
def code(re, im):
	t_0 = math.exp((re * 0.5))
	return t_0 * (math.sin(im) * t_0)
function code(re, im)
	t_0 = exp(Float64(re * 0.5))
	return Float64(t_0 * Float64(sin(im) * t_0))
end
function tmp = code(re, im)
	t_0 = exp((re * 0.5));
	tmp = t_0 * (sin(im) * t_0);
end
code[re_, im_] := Block[{t$95$0 = N[Exp[N[(re * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(N[Sin[im], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{re \cdot 0.5}\\
t\_0 \cdot \left(\sin im \cdot t\_0\right)
\end{array}
\end{array}
Derivation
  1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e^{re} \cdot \sin im\right)\right)} \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(e^{re} \cdot \sin im\right)\right)} \]
  5. Step-by-step derivation
    1. log1p-expm1-u100.0%

      \[\leadsto \color{blue}{e^{re} \cdot \sin im} \]
    2. *-commutative100.0%

      \[\leadsto \color{blue}{\sin im \cdot e^{re}} \]
    3. add-sqr-sqrt100.0%

      \[\leadsto \sin im \cdot \color{blue}{\left(\sqrt{e^{re}} \cdot \sqrt{e^{re}}\right)} \]
    4. associate-*r*100.0%

      \[\leadsto \color{blue}{\left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \sqrt{e^{re}}} \]
  6. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \sqrt{e^{re}}} \]
  7. Step-by-step derivation
    1. pow1/2100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{{\left(e^{re}\right)}^{0.5}} \]
    2. pow-exp100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{e^{re \cdot 0.5}} \]
  8. Applied egg-rr100.0%

    \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{e^{re \cdot 0.5}} \]
  9. Step-by-step derivation
    1. pow1/2100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{{\left(e^{re}\right)}^{0.5}} \]
    2. pow-exp100.0%

      \[\leadsto \left(\sin im \cdot \sqrt{e^{re}}\right) \cdot \color{blue}{e^{re \cdot 0.5}} \]
  10. Applied egg-rr100.0%

    \[\leadsto \left(\sin im \cdot \color{blue}{e^{re \cdot 0.5}}\right) \cdot e^{re \cdot 0.5} \]
  11. Final simplification100.0%

    \[\leadsto e^{re \cdot 0.5} \cdot \left(\sin im \cdot e^{re \cdot 0.5}\right) \]
  12. Add Preprocessing

Alternative 5: 100.0% accurate, 1.0× speedup?

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

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

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

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

Alternative 6: 61.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-7} \lor \neg \left(re \leq 250000\right):\\
\;\;\;\;e^{re}\\

\mathbf{else}:\\
\;\;\;\;im + im \cdot re\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -4.99999999999999977e-7 or 2.5e5 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \sin im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log55.5%

        \[\leadsto e^{re} \cdot \color{blue}{e^{\log \sin im}} \]
      2. prod-exp55.5%

        \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    4. Applied egg-rr55.5%

      \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    5. Taylor expanded in re around inf 81.7%

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

    if -4.99999999999999977e-7 < re < 2.5e5

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{im + im \cdot re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.6%

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

Alternative 7: 85.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq -55 \lor \neg \left(re \leq 250000\right):\\ \;\;\;\;e^{re}\\ \mathbf{else}:\\ \;\;\;\;\sin im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= re -55.0) (not (<= re 250000.0))) (exp re) (sin im)))
double code(double re, double im) {
	double tmp;
	if ((re <= -55.0) || !(re <= 250000.0)) {
		tmp = exp(re);
	} else {
		tmp = sin(im);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((re <= (-55.0d0)) .or. (.not. (re <= 250000.0d0))) then
        tmp = exp(re)
    else
        tmp = sin(im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((re <= -55.0) || !(re <= 250000.0)) {
		tmp = Math.exp(re);
	} else {
		tmp = Math.sin(im);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (re <= -55.0) or not (re <= 250000.0):
		tmp = math.exp(re)
	else:
		tmp = math.sin(im)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((re <= -55.0) || !(re <= 250000.0))
		tmp = exp(re);
	else
		tmp = sin(im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((re <= -55.0) || ~((re <= 250000.0)))
		tmp = exp(re);
	else
		tmp = sin(im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[re, -55.0], N[Not[LessEqual[re, 250000.0]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Sin[im], $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < -55 or 2.5e5 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \sin im \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-exp-log55.2%

        \[\leadsto e^{re} \cdot \color{blue}{e^{\log \sin im}} \]
      2. prod-exp55.2%

        \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    4. Applied egg-rr55.2%

      \[\leadsto \color{blue}{e^{re + \log \sin im}} \]
    5. Taylor expanded in re around inf 82.1%

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

    if -55 < re < 2.5e5

    1. Initial program 100.0%

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

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

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

Alternative 8: 30.1% accurate, 25.3× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;im \cdot re\\


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

    1. Initial program 100.0%

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

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

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

    if 1 < re

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{im + im \cdot re} \]
    5. Taylor expanded in re around inf 14.9%

      \[\leadsto \color{blue}{im \cdot re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification29.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1:\\ \;\;\;\;im\\ \mathbf{else}:\\ \;\;\;\;im \cdot re\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 30.0% accurate, 40.6× speedup?

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

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

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

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

    \[\leadsto \color{blue}{im + im \cdot re} \]
  5. Final simplification29.0%

    \[\leadsto im + im \cdot re \]
  6. Add Preprocessing

Alternative 10: 26.9% accurate, 203.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{im} \]
  5. Final simplification25.9%

    \[\leadsto im \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024030 
(FPCore (re im)
  :name "math.exp on complex, imaginary part"
  :precision binary64
  (* (exp re) (sin im)))