math.sin on complex, imaginary part

Percentage Accurate: 54.8% → 99.6%
Time: 7.2s
Alternatives: 10
Speedup: 2.8×

Specification

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

\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 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: 54.8% accurate, 1.0× speedup?

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

\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}

Alternative 1: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-5}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (<= t_0 (- INFINITY))
     (log (exp (* (- im) (cos re))))
     (if (<= t_0 4e-5)
       (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
       (* (* (cos re) 0.5) t_0)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = log(exp((-im * cos(re))));
	} else if (t_0 <= 4e-5) {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else {
		tmp = (cos(re) * 0.5) * t_0;
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.log(Math.exp((-im * Math.cos(re))));
	} else if (t_0 <= 4e-5) {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else {
		tmp = (Math.cos(re) * 0.5) * t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = math.log(math.exp((-im * math.cos(re))))
	elif t_0 <= 4e-5:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	else:
		tmp = (math.cos(re) * 0.5) * t_0
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = log(exp(Float64(Float64(-im) * cos(re))));
	elseif (t_0 <= 4e-5)
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	else
		tmp = Float64(Float64(cos(re) * 0.5) * t_0);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = log(exp((-im * cos(re))));
	elseif (t_0 <= 4e-5)
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	else
		tmp = (cos(re) * 0.5) * t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[Log[N[Exp[N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, 4e-5], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*5.2%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-15.2%

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

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out5.2%

        \[\leadsto \color{blue}{-im \cdot \cos re} \]
      2. add-sqr-sqrt5.2%

        \[\leadsto -\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re \]
      3. sqrt-unprod56.8%

        \[\leadsto -\color{blue}{\sqrt{im \cdot im}} \cdot \cos re \]
      4. sqr-neg56.8%

        \[\leadsto -\sqrt{\color{blue}{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re \]
      5. sqrt-unprod0.0%

        \[\leadsto -\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re \]
      6. add-sqr-sqrt0.3%

        \[\leadsto -\color{blue}{\left(-im\right)} \cdot \cos re \]
      7. log1p-expm1-u0.0%

        \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      8. log1p-udef0.0%

        \[\leadsto -\color{blue}{\log \left(1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      9. neg-log0.0%

        \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)}\right)} \]
      10. add-sqr-sqrt0.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re\right)}\right) \]
      11. sqrt-unprod100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re\right)}\right) \]
      12. sqr-neg100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\sqrt{\color{blue}{im \cdot im}} \cdot \cos re\right)}\right) \]
      13. sqrt-unprod100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re\right)}\right) \]
      14. add-sqr-sqrt100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{im} \cdot \cos re\right)}\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(im \cdot \cos re\right)}\right)} \]
    9. Taylor expanded in im around inf 100.0%

      \[\leadsto \log \color{blue}{\left(\frac{1}{e^{im \cdot \cos re}}\right)} \]
    10. Step-by-step derivation
      1. rec-exp100.0%

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

        \[\leadsto \log \left(e^{\color{blue}{\left(-im\right) \cdot \cos re}}\right) \]
    11. Simplified100.0%

      \[\leadsto \log \color{blue}{\left(e^{\left(-im\right) \cdot \cos re}\right)} \]

    if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 4.00000000000000033e-5

    1. Initial program 7.8%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub07.8%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.8%

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg99.8%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg99.8%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--99.8%

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

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified99.8%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]

    if 4.00000000000000033e-5 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -\infty:\\ \;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\ \mathbf{elif}\;e^{-im} - e^{im} \leq 4 \cdot 10^{-5}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array} \]

Alternative 2: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -700 \lor \neg \left(im \leq 720\right):\\ \;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -700.0) (not (<= im 720.0)))
   (log (exp (* (- im) (cos re))))
   (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))))
double code(double re, double im) {
	double tmp;
	if ((im <= -700.0) || !(im <= 720.0)) {
		tmp = log(exp((-im * cos(re))));
	} else {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-700.0d0)) .or. (.not. (im <= 720.0d0))) then
        tmp = log(exp((-im * cos(re))))
    else
        tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -700.0) || !(im <= 720.0)) {
		tmp = Math.log(Math.exp((-im * Math.cos(re))));
	} else {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -700.0) or not (im <= 720.0):
		tmp = math.log(math.exp((-im * math.cos(re))))
	else:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -700.0) || !(im <= 720.0))
		tmp = log(exp(Float64(Float64(-im) * cos(re))));
	else
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -700.0) || ~((im <= 720.0)))
		tmp = log(exp((-im * cos(re))));
	else
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -700.0], N[Not[LessEqual[im, 720.0]], $MachinePrecision]], N[Log[N[Exp[N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -700 \lor \neg \left(im \leq 720\right):\\
\;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -700 or 720 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*5.3%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-15.3%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified5.3%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out5.3%

        \[\leadsto \color{blue}{-im \cdot \cos re} \]
      2. add-sqr-sqrt2.7%

        \[\leadsto -\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re \]
      3. sqrt-unprod29.6%

        \[\leadsto -\color{blue}{\sqrt{im \cdot im}} \cdot \cos re \]
      4. sqr-neg29.6%

        \[\leadsto -\sqrt{\color{blue}{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re \]
      5. sqrt-unprod0.2%

        \[\leadsto -\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re \]
      6. add-sqr-sqrt0.3%

        \[\leadsto -\color{blue}{\left(-im\right)} \cdot \cos re \]
      7. log1p-expm1-u0.0%

        \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      8. log1p-udef0.0%

        \[\leadsto -\color{blue}{\log \left(1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      9. neg-log0.0%

        \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)}\right)} \]
      10. add-sqr-sqrt0.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re\right)}\right) \]
      11. sqrt-unprod51.9%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re\right)}\right) \]
      12. sqr-neg51.9%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\sqrt{\color{blue}{im \cdot im}} \cdot \cos re\right)}\right) \]
      13. sqrt-unprod51.9%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re\right)}\right) \]
      14. add-sqr-sqrt100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{im} \cdot \cos re\right)}\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(im \cdot \cos re\right)}\right)} \]
    9. Taylor expanded in im around inf 100.0%

      \[\leadsto \log \color{blue}{\left(\frac{1}{e^{im \cdot \cos re}}\right)} \]
    10. Step-by-step derivation
      1. rec-exp100.0%

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

        \[\leadsto \log \left(e^{\color{blue}{\left(-im\right) \cdot \cos re}}\right) \]
    11. Simplified100.0%

      \[\leadsto \log \color{blue}{\left(e^{\left(-im\right) \cdot \cos re}\right)} \]

    if -700 < im < 720

    1. Initial program 9.2%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub09.2%

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

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg98.9%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg98.9%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--98.9%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative98.9%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified98.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -700 \lor \neg \left(im \leq 720\right):\\ \;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 3: 93.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -\log \left(e^{im}\right)\\ t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -210000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (log (exp im))))
        (t_1 (* -0.16666666666666666 (* (cos re) (pow im 3.0)))))
   (if (<= im -2.4e+141)
     t_1
     (if (<= im -210000000000.0)
       t_0
       (if (<= im 700.0) (* (- im) (cos re)) (if (<= im 5e+95) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = -log(exp(im));
	double t_1 = -0.16666666666666666 * (cos(re) * pow(im, 3.0));
	double tmp;
	if (im <= -2.4e+141) {
		tmp = t_1;
	} else if (im <= -210000000000.0) {
		tmp = t_0;
	} else if (im <= 700.0) {
		tmp = -im * cos(re);
	} else if (im <= 5e+95) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -log(exp(im))
    t_1 = (-0.16666666666666666d0) * (cos(re) * (im ** 3.0d0))
    if (im <= (-2.4d+141)) then
        tmp = t_1
    else if (im <= (-210000000000.0d0)) then
        tmp = t_0
    else if (im <= 700.0d0) then
        tmp = -im * cos(re)
    else if (im <= 5d+95) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -Math.log(Math.exp(im));
	double t_1 = -0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0));
	double tmp;
	if (im <= -2.4e+141) {
		tmp = t_1;
	} else if (im <= -210000000000.0) {
		tmp = t_0;
	} else if (im <= 700.0) {
		tmp = -im * Math.cos(re);
	} else if (im <= 5e+95) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = -math.log(math.exp(im))
	t_1 = -0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0))
	tmp = 0
	if im <= -2.4e+141:
		tmp = t_1
	elif im <= -210000000000.0:
		tmp = t_0
	elif im <= 700.0:
		tmp = -im * math.cos(re)
	elif im <= 5e+95:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(-log(exp(im)))
	t_1 = Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0)))
	tmp = 0.0
	if (im <= -2.4e+141)
		tmp = t_1;
	elseif (im <= -210000000000.0)
		tmp = t_0;
	elseif (im <= 700.0)
		tmp = Float64(Float64(-im) * cos(re));
	elseif (im <= 5e+95)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -log(exp(im));
	t_1 = -0.16666666666666666 * (cos(re) * (im ^ 3.0));
	tmp = 0.0;
	if (im <= -2.4e+141)
		tmp = t_1;
	elseif (im <= -210000000000.0)
		tmp = t_0;
	elseif (im <= 700.0)
		tmp = -im * cos(re);
	elseif (im <= 5e+95)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = (-N[Log[N[Exp[im], $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4e+141], t$95$1, If[LessEqual[im, -210000000000.0], t$95$0, If[LessEqual[im, 700.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5e+95], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -\log \left(e^{im}\right)\\
t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -210000000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 700:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.39999999999999997e141 or 5.00000000000000025e95 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg98.8%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg98.8%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--98.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative98.8%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified98.8%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    7. Taylor expanded in im around inf 98.8%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)} \]

    if -2.39999999999999997e141 < im < -2.1e11 or 700 < im < 5.00000000000000025e95

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*3.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-13.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified3.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out3.7%

        \[\leadsto \color{blue}{-im \cdot \cos re} \]
      2. add-sqr-sqrt1.5%

        \[\leadsto -\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re \]
      3. sqrt-unprod1.8%

        \[\leadsto -\color{blue}{\sqrt{im \cdot im}} \cdot \cos re \]
      4. sqr-neg1.8%

        \[\leadsto -\sqrt{\color{blue}{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re \]
      5. sqrt-unprod0.3%

        \[\leadsto -\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re \]
      6. add-sqr-sqrt0.5%

        \[\leadsto -\color{blue}{\left(-im\right)} \cdot \cos re \]
      7. log1p-expm1-u0.0%

        \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      8. log1p-udef0.0%

        \[\leadsto -\color{blue}{\log \left(1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      9. neg-log0.0%

        \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)}\right)} \]
      10. add-sqr-sqrt0.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re\right)}\right) \]
      11. sqrt-unprod42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re\right)}\right) \]
      12. sqr-neg42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\sqrt{\color{blue}{im \cdot im}} \cdot \cos re\right)}\right) \]
      13. sqrt-unprod42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re\right)}\right) \]
      14. add-sqr-sqrt100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{im} \cdot \cos re\right)}\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(im \cdot \cos re\right)}\right)} \]
    9. Taylor expanded in re around 0 78.8%

      \[\leadsto \color{blue}{\log \left(\frac{1}{e^{im}}\right)} \]
    10. Step-by-step derivation
      1. log-rec78.8%

        \[\leadsto \color{blue}{-\log \left(e^{im}\right)} \]
    11. Simplified78.8%

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

    if -2.1e11 < im < 700

    1. Initial program 10.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub010.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified10.7%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*96.8%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-196.8%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -210000000000:\\ \;\;\;\;-\log \left(e^{im}\right)\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\ \;\;\;\;-\log \left(e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 4: 93.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -\log \left(e^{im}\right)\\ t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -210000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (log (exp im))))
        (t_1 (* -0.16666666666666666 (* (cos re) (pow im 3.0)))))
   (if (<= im -2.4e+141)
     t_1
     (if (<= im -210000000000.0)
       t_0
       (if (<= im 700.0)
         (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
         (if (<= im 5e+95) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = -log(exp(im));
	double t_1 = -0.16666666666666666 * (cos(re) * pow(im, 3.0));
	double tmp;
	if (im <= -2.4e+141) {
		tmp = t_1;
	} else if (im <= -210000000000.0) {
		tmp = t_0;
	} else if (im <= 700.0) {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 5e+95) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = -log(exp(im))
    t_1 = (-0.16666666666666666d0) * (cos(re) * (im ** 3.0d0))
    if (im <= (-2.4d+141)) then
        tmp = t_1
    else if (im <= (-210000000000.0d0)) then
        tmp = t_0
    else if (im <= 700.0d0) then
        tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    else if (im <= 5d+95) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -Math.log(Math.exp(im));
	double t_1 = -0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0));
	double tmp;
	if (im <= -2.4e+141) {
		tmp = t_1;
	} else if (im <= -210000000000.0) {
		tmp = t_0;
	} else if (im <= 700.0) {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 5e+95) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = -math.log(math.exp(im))
	t_1 = -0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0))
	tmp = 0
	if im <= -2.4e+141:
		tmp = t_1
	elif im <= -210000000000.0:
		tmp = t_0
	elif im <= 700.0:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	elif im <= 5e+95:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(-log(exp(im)))
	t_1 = Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0)))
	tmp = 0.0
	if (im <= -2.4e+141)
		tmp = t_1;
	elseif (im <= -210000000000.0)
		tmp = t_0;
	elseif (im <= 700.0)
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	elseif (im <= 5e+95)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -log(exp(im));
	t_1 = -0.16666666666666666 * (cos(re) * (im ^ 3.0));
	tmp = 0.0;
	if (im <= -2.4e+141)
		tmp = t_1;
	elseif (im <= -210000000000.0)
		tmp = t_0;
	elseif (im <= 700.0)
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	elseif (im <= 5e+95)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = (-N[Log[N[Exp[im], $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4e+141], t$95$1, If[LessEqual[im, -210000000000.0], t$95$0, If[LessEqual[im, 700.0], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5e+95], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -\log \left(e^{im}\right)\\
t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -210000000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 700:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.39999999999999997e141 or 5.00000000000000025e95 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg98.8%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg98.8%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--98.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative98.8%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified98.8%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    7. Taylor expanded in im around inf 98.8%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)} \]

    if -2.39999999999999997e141 < im < -2.1e11 or 700 < im < 5.00000000000000025e95

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*3.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-13.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified3.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out3.7%

        \[\leadsto \color{blue}{-im \cdot \cos re} \]
      2. add-sqr-sqrt1.5%

        \[\leadsto -\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re \]
      3. sqrt-unprod1.8%

        \[\leadsto -\color{blue}{\sqrt{im \cdot im}} \cdot \cos re \]
      4. sqr-neg1.8%

        \[\leadsto -\sqrt{\color{blue}{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re \]
      5. sqrt-unprod0.3%

        \[\leadsto -\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re \]
      6. add-sqr-sqrt0.5%

        \[\leadsto -\color{blue}{\left(-im\right)} \cdot \cos re \]
      7. log1p-expm1-u0.0%

        \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      8. log1p-udef0.0%

        \[\leadsto -\color{blue}{\log \left(1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      9. neg-log0.0%

        \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)}\right)} \]
      10. add-sqr-sqrt0.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re\right)}\right) \]
      11. sqrt-unprod42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re\right)}\right) \]
      12. sqr-neg42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\sqrt{\color{blue}{im \cdot im}} \cdot \cos re\right)}\right) \]
      13. sqrt-unprod42.3%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re\right)}\right) \]
      14. add-sqr-sqrt100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{im} \cdot \cos re\right)}\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(im \cdot \cos re\right)}\right)} \]
    9. Taylor expanded in re around 0 78.8%

      \[\leadsto \color{blue}{\log \left(\frac{1}{e^{im}}\right)} \]
    10. Step-by-step derivation
      1. log-rec78.8%

        \[\leadsto \color{blue}{-\log \left(e^{im}\right)} \]
    11. Simplified78.8%

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

    if -2.1e11 < im < 700

    1. Initial program 10.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub010.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified10.7%

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

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

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

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg97.3%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--97.3%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative97.3%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified97.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -210000000000:\\ \;\;\;\;-\log \left(e^{im}\right)\\ \mathbf{elif}\;im \leq 700:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\ \;\;\;\;-\log \left(e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 5: 86.1% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -210000000000 \lor \neg \left(im \leq 700\right):\\
\;\;\;\;-\log \left(e^{im}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -2.1e11 or 700 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*5.3%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-15.3%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified5.3%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Step-by-step derivation
      1. distribute-lft-neg-out5.3%

        \[\leadsto \color{blue}{-im \cdot \cos re} \]
      2. add-sqr-sqrt2.8%

        \[\leadsto -\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re \]
      3. sqrt-unprod30.0%

        \[\leadsto -\color{blue}{\sqrt{im \cdot im}} \cdot \cos re \]
      4. sqr-neg30.0%

        \[\leadsto -\sqrt{\color{blue}{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re \]
      5. sqrt-unprod0.1%

        \[\leadsto -\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re \]
      6. add-sqr-sqrt0.3%

        \[\leadsto -\color{blue}{\left(-im\right)} \cdot \cos re \]
      7. log1p-expm1-u0.0%

        \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      8. log1p-udef0.0%

        \[\leadsto -\color{blue}{\log \left(1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)\right)} \]
      9. neg-log0.0%

        \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(\left(-im\right) \cdot \cos re\right)}\right)} \]
      10. add-sqr-sqrt0.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \cdot \cos re\right)}\right) \]
      11. sqrt-unprod52.7%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \cdot \cos re\right)}\right) \]
      12. sqr-neg52.7%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\sqrt{\color{blue}{im \cdot im}} \cdot \cos re\right)}\right) \]
      13. sqrt-unprod52.7%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \cdot \cos re\right)}\right) \]
      14. add-sqr-sqrt100.0%

        \[\leadsto \log \left(\frac{1}{1 + \mathsf{expm1}\left(\color{blue}{im} \cdot \cos re\right)}\right) \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\log \left(\frac{1}{1 + \mathsf{expm1}\left(im \cdot \cos re\right)}\right)} \]
    9. Taylor expanded in re around 0 72.5%

      \[\leadsto \color{blue}{\log \left(\frac{1}{e^{im}}\right)} \]
    10. Step-by-step derivation
      1. log-rec72.5%

        \[\leadsto \color{blue}{-\log \left(e^{im}\right)} \]
    11. Simplified72.5%

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

    if -2.1e11 < im < 700

    1. Initial program 10.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub010.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified10.7%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*96.8%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-196.8%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified96.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -210000000000 \lor \neg \left(im \leq 700\right):\\ \;\;\;\;-\log \left(e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \end{array} \]

Alternative 6: 75.7% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{if}\;im \leq -4.2 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -700:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\ \mathbf{elif}\;im \leq 1650000000:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (* (pow im 3.0) -0.16666666666666666) im)))
   (if (<= im -4.2e+101)
     t_0
     (if (<= im -700.0)
       (* (pow re 2.0) (* im 0.5))
       (if (<= im 1650000000.0) (* (- im) (cos re)) t_0)))))
double code(double re, double im) {
	double t_0 = (pow(im, 3.0) * -0.16666666666666666) - im;
	double tmp;
	if (im <= -4.2e+101) {
		tmp = t_0;
	} else if (im <= -700.0) {
		tmp = pow(re, 2.0) * (im * 0.5);
	} else if (im <= 1650000000.0) {
		tmp = -im * cos(re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((im ** 3.0d0) * (-0.16666666666666666d0)) - im
    if (im <= (-4.2d+101)) then
        tmp = t_0
    else if (im <= (-700.0d0)) then
        tmp = (re ** 2.0d0) * (im * 0.5d0)
    else if (im <= 1650000000.0d0) then
        tmp = -im * cos(re)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (Math.pow(im, 3.0) * -0.16666666666666666) - im;
	double tmp;
	if (im <= -4.2e+101) {
		tmp = t_0;
	} else if (im <= -700.0) {
		tmp = Math.pow(re, 2.0) * (im * 0.5);
	} else if (im <= 1650000000.0) {
		tmp = -im * Math.cos(re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = (math.pow(im, 3.0) * -0.16666666666666666) - im
	tmp = 0
	if im <= -4.2e+101:
		tmp = t_0
	elif im <= -700.0:
		tmp = math.pow(re, 2.0) * (im * 0.5)
	elif im <= 1650000000.0:
		tmp = -im * math.cos(re)
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)
	tmp = 0.0
	if (im <= -4.2e+101)
		tmp = t_0;
	elseif (im <= -700.0)
		tmp = Float64((re ^ 2.0) * Float64(im * 0.5));
	elseif (im <= 1650000000.0)
		tmp = Float64(Float64(-im) * cos(re));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = ((im ^ 3.0) * -0.16666666666666666) - im;
	tmp = 0.0;
	if (im <= -4.2e+101)
		tmp = t_0;
	elseif (im <= -700.0)
		tmp = (re ^ 2.0) * (im * 0.5);
	elseif (im <= 1650000000.0)
		tmp = -im * cos(re);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]}, If[LessEqual[im, -4.2e+101], t$95$0, If[LessEqual[im, -700.0], N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1650000000.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\
\mathbf{if}\;im \leq -4.2 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -700:\\
\;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\

\mathbf{elif}\;im \leq 1650000000:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.2e101 or 1.65e9 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg79.4%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg79.4%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--79.4%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative79.4%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified79.4%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    7. Taylor expanded in re around 0 57.3%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]

    if -4.2e101 < im < -700

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*3.6%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-13.6%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified3.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5 + -1\right)} \]
    10. Taylor expanded in re around inf 31.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot {re}^{2}\right)} \]
    11. Step-by-step derivation
      1. associate-*r*31.3%

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

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

        \[\leadsto \color{blue}{{re}^{2} \cdot \left(im \cdot 0.5\right)} \]
    12. Simplified31.3%

      \[\leadsto \color{blue}{{re}^{2} \cdot \left(im \cdot 0.5\right)} \]

    if -700 < im < 1.65e9

    1. Initial program 9.2%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub09.2%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*98.3%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-198.3%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.2 \cdot 10^{+101}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{elif}\;im \leq -700:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\ \mathbf{elif}\;im \leq 1650000000:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \end{array} \]

Alternative 7: 75.8% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{if}\;im \leq -4.5 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -480:\\ \;\;\;\;im \cdot \left(0.5 \cdot {re}^{2} + -1\right)\\ \mathbf{elif}\;im \leq 1650000000:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (* (pow im 3.0) -0.16666666666666666) im)))
   (if (<= im -4.5e+101)
     t_0
     (if (<= im -480.0)
       (* im (+ (* 0.5 (pow re 2.0)) -1.0))
       (if (<= im 1650000000.0) (* (- im) (cos re)) t_0)))))
double code(double re, double im) {
	double t_0 = (pow(im, 3.0) * -0.16666666666666666) - im;
	double tmp;
	if (im <= -4.5e+101) {
		tmp = t_0;
	} else if (im <= -480.0) {
		tmp = im * ((0.5 * pow(re, 2.0)) + -1.0);
	} else if (im <= 1650000000.0) {
		tmp = -im * cos(re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((im ** 3.0d0) * (-0.16666666666666666d0)) - im
    if (im <= (-4.5d+101)) then
        tmp = t_0
    else if (im <= (-480.0d0)) then
        tmp = im * ((0.5d0 * (re ** 2.0d0)) + (-1.0d0))
    else if (im <= 1650000000.0d0) then
        tmp = -im * cos(re)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (Math.pow(im, 3.0) * -0.16666666666666666) - im;
	double tmp;
	if (im <= -4.5e+101) {
		tmp = t_0;
	} else if (im <= -480.0) {
		tmp = im * ((0.5 * Math.pow(re, 2.0)) + -1.0);
	} else if (im <= 1650000000.0) {
		tmp = -im * Math.cos(re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = (math.pow(im, 3.0) * -0.16666666666666666) - im
	tmp = 0
	if im <= -4.5e+101:
		tmp = t_0
	elif im <= -480.0:
		tmp = im * ((0.5 * math.pow(re, 2.0)) + -1.0)
	elif im <= 1650000000.0:
		tmp = -im * math.cos(re)
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)
	tmp = 0.0
	if (im <= -4.5e+101)
		tmp = t_0;
	elseif (im <= -480.0)
		tmp = Float64(im * Float64(Float64(0.5 * (re ^ 2.0)) + -1.0));
	elseif (im <= 1650000000.0)
		tmp = Float64(Float64(-im) * cos(re));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = ((im ^ 3.0) * -0.16666666666666666) - im;
	tmp = 0.0;
	if (im <= -4.5e+101)
		tmp = t_0;
	elseif (im <= -480.0)
		tmp = im * ((0.5 * (re ^ 2.0)) + -1.0);
	elseif (im <= 1650000000.0)
		tmp = -im * cos(re);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]}, If[LessEqual[im, -4.5e+101], t$95$0, If[LessEqual[im, -480.0], N[(im * N[(N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1650000000.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\
\mathbf{if}\;im \leq -4.5 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -480:\\
\;\;\;\;im \cdot \left(0.5 \cdot {re}^{2} + -1\right)\\

\mathbf{elif}\;im \leq 1650000000:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.5000000000000002e101 or 1.65e9 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

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

        \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + -1 \cdot \left(im \cdot \cos re\right)} \]
      2. mul-1-neg79.4%

        \[\leadsto -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right) + \color{blue}{\left(-im \cdot \cos re\right)} \]
      3. unsub-neg79.4%

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - im \cdot \cos re \]
      5. distribute-rgt-out--79.4%

        \[\leadsto \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} \]
      6. *-commutative79.4%

        \[\leadsto \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
    6. Simplified79.4%

      \[\leadsto \color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    7. Taylor expanded in re around 0 57.3%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]

    if -4.5000000000000002e101 < im < -480

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*3.6%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-13.6%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified3.6%

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

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

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

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

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

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

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

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

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

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

    if -480 < im < 1.65e9

    1. Initial program 9.2%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub09.2%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*98.3%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-198.3%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.5 \cdot 10^{+101}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{elif}\;im \leq -480:\\ \;\;\;\;im \cdot \left(0.5 \cdot {re}^{2} + -1\right)\\ \mathbf{elif}\;im \leq 1650000000:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \end{array} \]

Alternative 8: 58.5% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -650 \lor \neg \left(im \leq 1.7 \cdot 10^{+50}\right):\\
\;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -650 or 1.6999999999999999e50 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub0100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*5.4%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-15.4%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified5.4%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    7. Taylor expanded in re around 0 28.5%

      \[\leadsto \color{blue}{-1 \cdot im + 0.5 \cdot \left(im \cdot {re}^{2}\right)} \]
    8. Step-by-step derivation
      1. mul-1-neg28.5%

        \[\leadsto \color{blue}{\left(-im\right)} + 0.5 \cdot \left(im \cdot {re}^{2}\right) \]
      2. +-commutative28.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{im \cdot \left({re}^{2} \cdot 0.5 + -1\right)} \]
    10. Taylor expanded in re around inf 26.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(im \cdot {re}^{2}\right)} \]
    11. Step-by-step derivation
      1. associate-*r*26.2%

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

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

        \[\leadsto \color{blue}{{re}^{2} \cdot \left(im \cdot 0.5\right)} \]
    12. Simplified26.2%

      \[\leadsto \color{blue}{{re}^{2} \cdot \left(im \cdot 0.5\right)} \]

    if -650 < im < 1.6999999999999999e50

    1. Initial program 16.7%

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. neg-sub016.7%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified16.7%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*90.5%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
      2. neg-mul-190.5%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
    6. Simplified90.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -650 \lor \neg \left(im \leq 1.7 \cdot 10^{+50}\right):\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \end{array} \]

Alternative 9: 51.7% accurate, 3.0× speedup?

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

\\
\left(-im\right) \cdot \cos re
\end{array}
Derivation
  1. Initial program 56.4%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. neg-sub056.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
  3. Simplified56.4%

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

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  5. Step-by-step derivation
    1. associate-*r*50.0%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
    2. neg-mul-150.0%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
  6. Simplified50.0%

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

    \[\leadsto \left(-im\right) \cdot \cos re \]

Alternative 10: 29.9% accurate, 154.5× 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 Float64(-im)
end
function tmp = code(re, im)
	tmp = -im;
end
code[re_, im_] := (-im)
\begin{array}{l}

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

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. neg-sub056.4%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
  3. Simplified56.4%

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

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  5. Step-by-step derivation
    1. associate-*r*50.0%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
    2. neg-mul-150.0%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \cos re \]
  6. Simplified50.0%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
  7. Taylor expanded in re around 0 28.6%

    \[\leadsto \color{blue}{-1 \cdot im} \]
  8. Step-by-step derivation
    1. mul-1-neg28.6%

      \[\leadsto \color{blue}{-im} \]
  9. Simplified28.6%

    \[\leadsto \color{blue}{-im} \]
  10. Final simplification28.6%

    \[\leadsto -im \]

Developer target: 99.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))