math.sin on complex, imaginary part

Percentage Accurate: 54.7% → 99.7%
Time: 8.6s
Alternatives: 13
Speedup: 2.9×

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 13 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.7% 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.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+66} \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;t_1 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \left(-0.0003968253968253968 \cdot {im}^{7} + \left(im \cdot -2 + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* 0.5 (cos re))))
   (if (or (<= t_0 -5e+66) (not (<= t_0 2e-5)))
     (* t_1 t_0)
     (*
      t_1
      (+
       (* -0.0003968253968253968 (pow im 7.0))
       (+
        (* im -2.0)
        (+
         (* -0.016666666666666666 (pow im 5.0))
         (* -0.3333333333333333 (pow im 3.0)))))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = 0.5 * cos(re);
	double tmp;
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5)) {
		tmp = t_1 * t_0;
	} else {
		tmp = t_1 * ((-0.0003968253968253968 * pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * pow(im, 5.0)) + (-0.3333333333333333 * pow(im, 3.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) :: t_1
    real(8) :: tmp
    t_0 = exp(-im) - exp(im)
    t_1 = 0.5d0 * cos(re)
    if ((t_0 <= (-5d+66)) .or. (.not. (t_0 <= 2d-5))) then
        tmp = t_1 * t_0
    else
        tmp = t_1 * (((-0.0003968253968253968d0) * (im ** 7.0d0)) + ((im * (-2.0d0)) + (((-0.016666666666666666d0) * (im ** 5.0d0)) + ((-0.3333333333333333d0) * (im ** 3.0d0)))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = 0.5 * Math.cos(re);
	double tmp;
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5)) {
		tmp = t_1 * t_0;
	} else {
		tmp = t_1 * ((-0.0003968253968253968 * Math.pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * Math.pow(im, 5.0)) + (-0.3333333333333333 * Math.pow(im, 3.0)))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = 0.5 * math.cos(re)
	tmp = 0
	if (t_0 <= -5e+66) or not (t_0 <= 2e-5):
		tmp = t_1 * t_0
	else:
		tmp = t_1 * ((-0.0003968253968253968 * math.pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * math.pow(im, 5.0)) + (-0.3333333333333333 * math.pow(im, 3.0)))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(0.5 * cos(re))
	tmp = 0.0
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5))
		tmp = Float64(t_1 * t_0);
	else
		tmp = Float64(t_1 * Float64(Float64(-0.0003968253968253968 * (im ^ 7.0)) + Float64(Float64(im * -2.0) + Float64(Float64(-0.016666666666666666 * (im ^ 5.0)) + Float64(-0.3333333333333333 * (im ^ 3.0))))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = 0.5 * cos(re);
	tmp = 0.0;
	if ((t_0 <= -5e+66) || ~((t_0 <= 2e-5)))
		tmp = t_1 * t_0;
	else
		tmp = t_1 * ((-0.0003968253968253968 * (im ^ 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * (im ^ 5.0)) + (-0.3333333333333333 * (im ^ 3.0)))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e+66], N[Not[LessEqual[t$95$0, 2e-5]], $MachinePrecision]], N[(t$95$1 * t$95$0), $MachinePrecision], N[(t$95$1 * N[(N[(-0.0003968253968253968 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(im * -2.0), $MachinePrecision] + N[(N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := 0.5 \cdot \cos re\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+66} \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\
\;\;\;\;t_1 \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(-0.0003968253968253968 \cdot {im}^{7} + \left(im \cdot -2 + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -4.99999999999999991e66 or 2.00000000000000016e-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. sub0-neg100.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)} \]

    if -4.99999999999999991e66 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 2.00000000000000016e-5

    1. Initial program 7.9%

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

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

      \[\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 \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -5 \cdot 10^{+66} \lor \neg \left(e^{-im} - e^{im} \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(-0.0003968253968253968 \cdot {im}^{7} + \left(im \cdot -2 + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)\\ \end{array} \]

Alternative 2: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+66} \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{5} \cdot -0.008333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (or (<= t_0 -5e+66) (not (<= t_0 2e-5)))
     (* (* 0.5 (cos re)) t_0)
     (*
      (cos re)
      (+
       (- (* (pow im 3.0) -0.16666666666666666) im)
       (+
        (* (pow im 7.0) -0.0001984126984126984)
        (* (pow im 5.0) -0.008333333333333333)))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5)) {
		tmp = (0.5 * cos(re)) * t_0;
	} else {
		tmp = cos(re) * (((pow(im, 3.0) * -0.16666666666666666) - im) + ((pow(im, 7.0) * -0.0001984126984126984) + (pow(im, 5.0) * -0.008333333333333333)));
	}
	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 = exp(-im) - exp(im)
    if ((t_0 <= (-5d+66)) .or. (.not. (t_0 <= 2d-5))) then
        tmp = (0.5d0 * cos(re)) * t_0
    else
        tmp = cos(re) * ((((im ** 3.0d0) * (-0.16666666666666666d0)) - im) + (((im ** 7.0d0) * (-0.0001984126984126984d0)) + ((im ** 5.0d0) * (-0.008333333333333333d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5)) {
		tmp = (0.5 * Math.cos(re)) * t_0;
	} else {
		tmp = Math.cos(re) * (((Math.pow(im, 3.0) * -0.16666666666666666) - im) + ((Math.pow(im, 7.0) * -0.0001984126984126984) + (Math.pow(im, 5.0) * -0.008333333333333333)));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_0 <= -5e+66) or not (t_0 <= 2e-5):
		tmp = (0.5 * math.cos(re)) * t_0
	else:
		tmp = math.cos(re) * (((math.pow(im, 3.0) * -0.16666666666666666) - im) + ((math.pow(im, 7.0) * -0.0001984126984126984) + (math.pow(im, 5.0) * -0.008333333333333333)))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_0 <= -5e+66) || !(t_0 <= 2e-5))
		tmp = Float64(Float64(0.5 * cos(re)) * t_0);
	else
		tmp = Float64(cos(re) * Float64(Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im) + Float64(Float64((im ^ 7.0) * -0.0001984126984126984) + Float64((im ^ 5.0) * -0.008333333333333333))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_0 <= -5e+66) || ~((t_0 <= 2e-5)))
		tmp = (0.5 * cos(re)) * t_0;
	else
		tmp = cos(re) * ((((im ^ 3.0) * -0.16666666666666666) - im) + (((im ^ 7.0) * -0.0001984126984126984) + ((im ^ 5.0) * -0.008333333333333333)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e+66], N[Not[LessEqual[t$95$0, 2e-5]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision] + N[(N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision] + N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+66} \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{5} \cdot -0.008333333333333333\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -4.99999999999999991e66 or 2.00000000000000016e-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. sub0-neg100.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)} \]

    if -4.99999999999999991e66 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 2.00000000000000016e-5

    1. Initial program 7.9%

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

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

      \[\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}{-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(-1 \cdot \left(\cos re \cdot im\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right)\right)} \]
    5. Step-by-step derivation
      1. associate-+r+99.8%

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

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

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

        \[\leadsto \left(\left(-\color{blue}{im \cdot \cos re}\right) + -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]
      5. distribute-lft-neg-in99.8%

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

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

        \[\leadsto \left(\left(-im\right) \cdot \cos re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re}\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]
      8. distribute-rgt-out99.8%

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

        \[\leadsto \cos re \cdot \left(\left(-im\right) + -0.16666666666666666 \cdot {im}^{3}\right) + \left(\color{blue}{\left(\cos re \cdot {im}^{5}\right) \cdot -0.008333333333333333} + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]
      10. associate-*l*99.8%

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

        \[\leadsto \cos re \cdot \left(\left(-im\right) + -0.16666666666666666 \cdot {im}^{3}\right) + \left(\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right) + \color{blue}{\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984}\right) \]
      12. associate-*l*99.8%

        \[\leadsto \cos re \cdot \left(\left(-im\right) + -0.16666666666666666 \cdot {im}^{3}\right) + \left(\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right) + \color{blue}{\cos re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)}\right) \]
      13. distribute-lft-out99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -5 \cdot 10^{+66} \lor \neg \left(e^{-im} - e^{im} \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{5} \cdot -0.008333333333333333\right)\right)\\ \end{array} \]

Alternative 3: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -0.05 \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (or (<= t_0 -0.05) (not (<= t_0 2e-5)))
     (* (* 0.5 (cos re)) t_0)
     (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if ((t_0 <= -0.05) || !(t_0 <= 2e-5)) {
		tmp = (0.5 * cos(re)) * t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = exp(-im) - exp(im)
    if ((t_0 <= (-0.05d0)) .or. (.not. (t_0 <= 2d-5))) then
        tmp = (0.5d0 * cos(re)) * t_0
    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 t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_0 <= -0.05) || !(t_0 <= 2e-5)) {
		tmp = (0.5 * Math.cos(re)) * t_0;
	} else {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_0 <= -0.05) or not (t_0 <= 2e-5):
		tmp = (0.5 * math.cos(re)) * t_0
	else:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_0 <= -0.05) || !(t_0 <= 2e-5))
		tmp = Float64(Float64(0.5 * cos(re)) * t_0);
	else
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_0 <= -0.05) || ~((t_0 <= 2e-5)))
		tmp = (0.5 * cos(re)) * t_0;
	else
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.05], N[Not[LessEqual[t$95$0, 2e-5]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $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}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -0.05 \lor \neg \left(t_0 \leq 2 \cdot 10^{-5}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\

\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 (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -0.050000000000000003 or 2.00000000000000016e-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. sub0-neg100.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)} \]

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

    1. Initial program 7.2%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.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 99.8%

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

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

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

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

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

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

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

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

Alternative 4: 96.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \mathbf{if}\;im \leq -3.3 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.55:\\ \;\;\;\;t_0 \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq 0.0275:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\ \;\;\;\;0.5 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im)))
        (t_1 (* (pow im 7.0) (* (cos re) -0.0001984126984126984))))
   (if (<= im -3.3e+85)
     t_1
     (if (<= im -0.55)
       (* t_0 (+ 0.5 (* re (* re -0.25))))
       (if (<= im 0.0275)
         (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
         (if (<= im 2.5e+36) (* 0.5 t_0) t_1))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = pow(im, 7.0) * (cos(re) * -0.0001984126984126984);
	double tmp;
	if (im <= -3.3e+85) {
		tmp = t_1;
	} else if (im <= -0.55) {
		tmp = t_0 * (0.5 + (re * (re * -0.25)));
	} else if (im <= 0.0275) {
		tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 2.5e+36) {
		tmp = 0.5 * 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 = exp(-im) - exp(im)
    t_1 = (im ** 7.0d0) * (cos(re) * (-0.0001984126984126984d0))
    if (im <= (-3.3d+85)) then
        tmp = t_1
    else if (im <= (-0.55d0)) then
        tmp = t_0 * (0.5d0 + (re * (re * (-0.25d0))))
    else if (im <= 0.0275d0) then
        tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    else if (im <= 2.5d+36) then
        tmp = 0.5d0 * t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = Math.pow(im, 7.0) * (Math.cos(re) * -0.0001984126984126984);
	double tmp;
	if (im <= -3.3e+85) {
		tmp = t_1;
	} else if (im <= -0.55) {
		tmp = t_0 * (0.5 + (re * (re * -0.25)));
	} else if (im <= 0.0275) {
		tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 2.5e+36) {
		tmp = 0.5 * t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = math.pow(im, 7.0) * (math.cos(re) * -0.0001984126984126984)
	tmp = 0
	if im <= -3.3e+85:
		tmp = t_1
	elif im <= -0.55:
		tmp = t_0 * (0.5 + (re * (re * -0.25)))
	elif im <= 0.0275:
		tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	elif im <= 2.5e+36:
		tmp = 0.5 * t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64((im ^ 7.0) * Float64(cos(re) * -0.0001984126984126984))
	tmp = 0.0
	if (im <= -3.3e+85)
		tmp = t_1;
	elseif (im <= -0.55)
		tmp = Float64(t_0 * Float64(0.5 + Float64(re * Float64(re * -0.25))));
	elseif (im <= 0.0275)
		tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	elseif (im <= 2.5e+36)
		tmp = Float64(0.5 * t_0);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = (im ^ 7.0) * (cos(re) * -0.0001984126984126984);
	tmp = 0.0;
	if (im <= -3.3e+85)
		tmp = t_1;
	elseif (im <= -0.55)
		tmp = t_0 * (0.5 + (re * (re * -0.25)));
	elseif (im <= 0.0275)
		tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	elseif (im <= 2.5e+36)
		tmp = 0.5 * t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 7.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -3.3e+85], t$95$1, If[LessEqual[im, -0.55], N[(t$95$0 * N[(0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 0.0275], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.5e+36], N[(0.5 * t$95$0), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\
\mathbf{if}\;im \leq -3.3 \cdot 10^{+85}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -0.55:\\
\;\;\;\;t_0 \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\

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

\mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\
\;\;\;\;0.5 \cdot t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.2999999999999999e85 or 2.49999999999999988e36 < 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. sub0-neg100.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 99.1%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
    5. Taylor expanded in im around inf 99.1%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)} \]
    6. Step-by-step derivation
      1. *-commutative99.1%

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

        \[\leadsto \color{blue}{\left({im}^{7} \cdot \cos re\right)} \cdot -0.0001984126984126984 \]
      3. associate-*l*99.1%

        \[\leadsto \color{blue}{{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)} \]
    7. Simplified99.1%

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

    if -3.2999999999999999e85 < im < -0.55000000000000004

    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. sub0-neg100.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 re around 0 0.0%

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot \left(e^{-im} - e^{im}\right)} + 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
      3. distribute-rgt-out95.7%

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

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

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{{re}^{2} \cdot -0.25}\right) \]
      6. unpow295.7%

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      7. associate-*l*95.7%

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    6. Simplified95.7%

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

    if -0.55000000000000004 < im < 0.0275000000000000001

    1. Initial program 7.2%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.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 99.8%

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left({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 0.0275000000000000001 < im < 2.49999999999999988e36

    1. Initial program 99.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.3 \cdot 10^{+85}:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \mathbf{elif}\;im \leq -0.55:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq 0.0275:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \end{array} \]

Alternative 5: 86.6% accurate, 1.5× speedup?

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

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

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

\mathbf{elif}\;im \leq 1.02 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -3.20000000000000026e-4 or 0.0011199999999999999 < im < 1.02000000000000002e101

    1. Initial program 99.9%

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

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

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

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

    if -3.20000000000000026e-4 < im < 0.0011199999999999999

    1. Initial program 7.2%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.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 99.3%

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

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative99.3%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in99.3%

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

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

    if 1.02000000000000002e101 < 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. sub0-neg100.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.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-0.5 \cdot {re}^{2}\right) \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      6. *-commutative2.3%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      7. fma-neg2.3%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right)} + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      8. *-lft-identity2.3%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) + \color{blue}{1 \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right)} \]
      9. distribute-rgt-out81.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \cdot \left(-0.5 \cdot {re}^{2} + 1\right)} \]
      10. fma-neg81.4%

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

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

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

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

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

Alternative 6: 94.6% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\
\mathbf{if}\;im \leq -4.2:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -4.20000000000000018 or 2.49999999999999988e36 < 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. sub0-neg100.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 93.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
    5. Taylor expanded in im around inf 93.2%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984} \]
      2. *-commutative93.2%

        \[\leadsto \color{blue}{\left({im}^{7} \cdot \cos re\right)} \cdot -0.0001984126984126984 \]
      3. associate-*l*93.2%

        \[\leadsto \color{blue}{{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)} \]
    7. Simplified93.2%

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

    if -4.20000000000000018 < im < 8.8999999999999995e-4

    1. Initial program 7.2%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.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 99.3%

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

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative99.3%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in99.3%

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

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

    if 8.8999999999999995e-4 < im < 2.49999999999999988e36

    1. Initial program 99.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.2:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \mathbf{elif}\;im \leq 0.00089:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \end{array} \]

Alternative 7: 94.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\
\mathbf{if}\;im \leq -5.6:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -5.5999999999999996 or 2.49999999999999988e36 < 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. sub0-neg100.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 93.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
    5. Taylor expanded in im around inf 93.2%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984} \]
      2. *-commutative93.2%

        \[\leadsto \color{blue}{\left({im}^{7} \cdot \cos re\right)} \cdot -0.0001984126984126984 \]
      3. associate-*l*93.2%

        \[\leadsto \color{blue}{{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)} \]
    7. Simplified93.2%

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

    if -5.5999999999999996 < im < 0.029999999999999999

    1. Initial program 7.2%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Simplified7.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 99.8%

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left({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 0.029999999999999999 < im < 2.49999999999999988e36

    1. Initial program 99.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.6:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \mathbf{elif}\;im \leq 0.03:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 2.5 \cdot 10^{+36}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\ \end{array} \]

Alternative 8: 79.6% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -9 \cdot 10^{+23}:\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -8.99999999999999958e23

    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. sub0-neg100.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 97.2%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
    5. Taylor expanded in im around inf 97.2%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984} \]
      2. *-commutative97.2%

        \[\leadsto \color{blue}{\left({im}^{7} \cdot \cos re\right)} \cdot -0.0001984126984126984 \]
      3. associate-*l*97.2%

        \[\leadsto \color{blue}{{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)} \]
    7. Simplified97.2%

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

      \[\leadsto {im}^{7} \cdot \color{blue}{-0.0001984126984126984} \]

    if -8.99999999999999958e23 < im < 0.023

    1. Initial program 11.6%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\cos re \cdot im\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg94.7%

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative94.7%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in94.7%

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

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

    if 0.023 < im

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-0.5 \cdot {re}^{2}\right) \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)} + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      6. *-commutative8.1%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      7. fma-neg8.1%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \color{blue}{\mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right)} + \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \]
      8. *-lft-identity8.1%

        \[\leadsto \left(-0.5 \cdot {re}^{2}\right) \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) + \color{blue}{1 \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right)} \]
      9. distribute-rgt-out61.2%

        \[\leadsto \color{blue}{\mathsf{fma}\left({im}^{3}, -0.16666666666666666, -im\right) \cdot \left(-0.5 \cdot {re}^{2} + 1\right)} \]
      10. fma-neg61.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -9 \cdot 10^{+23}:\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\ \mathbf{elif}\;im \leq 0.023:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(\left(re \cdot re\right) \cdot -0.5 + 1\right)\\ \end{array} \]

Alternative 9: 59.5% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -480 \lor \neg \left(im \leq 2.65 \cdot 10^{+32}\right):\\
\;\;\;\;\left(re \cdot re\right) \cdot \left(im \cdot 0.5\right) - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -480 or 2.65e32 < 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. sub0-neg100.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.5%

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

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative5.5%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in5.5%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot \left(im \cdot 0.5\right) - im \]
      7. *-commutative23.5%

        \[\leadsto \left(re \cdot re\right) \cdot \color{blue}{\left(0.5 \cdot im\right)} - im \]
    9. Simplified23.5%

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

    if -480 < im < 2.65e32

    1. Initial program 13.6%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\cos re \cdot im\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg92.9%

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative92.9%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in92.9%

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

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

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

Alternative 10: 81.8% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.9 \cdot 10^{+20} \lor \neg \left(im \leq 560000000\right):\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.9e20 or 5.6e8 < 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. sub0-neg100.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 91.8%

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-0.0003968253968253968 \cdot {im}^{7} + \left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)} \]
    5. Taylor expanded in im around inf 91.8%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)} \]
    6. Step-by-step derivation
      1. *-commutative91.8%

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984} \]
      2. *-commutative91.8%

        \[\leadsto \color{blue}{\left({im}^{7} \cdot \cos re\right)} \cdot -0.0001984126984126984 \]
      3. associate-*l*91.8%

        \[\leadsto \color{blue}{{im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)} \]
    7. Simplified91.8%

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

      \[\leadsto {im}^{7} \cdot \color{blue}{-0.0001984126984126984} \]

    if -1.9e20 < im < 5.6e8

    1. Initial program 12.9%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(\cos re \cdot im\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg93.6%

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative93.6%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in93.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.9 \cdot 10^{+20} \lor \neg \left(im \leq 560000000\right):\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \end{array} \]

Alternative 11: 31.0% accurate, 27.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.7 \cdot 10^{+181}:\\
\;\;\;\;-im\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot -3\\


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

    1. Initial program 56.5%

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

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

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

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

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative49.5%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in49.5%

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

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

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

        \[\leadsto \color{blue}{-im} \]
    9. Simplified29.0%

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

    if 2.70000000000000007e181 < re

    1. Initial program 50.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot \left(e^{-im} - e^{im}\right)} + 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
      3. distribute-rgt-out23.5%

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

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

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

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      7. associate-*l*23.5%

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    6. Simplified23.5%

      \[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    7. Applied egg-rr30.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 2.7 \cdot 10^{+181}:\\ \;\;\;\;-im\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot -3\\ \end{array} \]

Alternative 12: 35.5% accurate, 27.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.1 \cdot 10^{+181}:\\
\;\;\;\;\left(re \cdot re\right) \cdot \left(im \cdot 0.5\right) - im\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot -3\\


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

    1. Initial program 56.5%

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

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

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

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

        \[\leadsto \color{blue}{-\cos re \cdot im} \]
      2. *-commutative49.5%

        \[\leadsto -\color{blue}{im \cdot \cos re} \]
      3. distribute-lft-neg-in49.5%

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

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

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

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

        \[\leadsto \color{blue}{0.5 \cdot \left({re}^{2} \cdot im\right) + \left(-im\right)} \]
      3. unsub-neg34.9%

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

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

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

        \[\leadsto \color{blue}{\left(re \cdot re\right)} \cdot \left(im \cdot 0.5\right) - im \]
      7. *-commutative34.9%

        \[\leadsto \left(re \cdot re\right) \cdot \color{blue}{\left(0.5 \cdot im\right)} - im \]
    9. Simplified34.9%

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

    if 3.09999999999999989e181 < re

    1. Initial program 50.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-0.25 \cdot {re}^{2}\right) \cdot \left(e^{-im} - e^{im}\right)} + 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
      3. distribute-rgt-out23.5%

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

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

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

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{\left(re \cdot re\right)} \cdot -0.25\right) \]
      7. associate-*l*23.5%

        \[\leadsto \left(e^{-im} - e^{im}\right) \cdot \left(0.5 + \color{blue}{re \cdot \left(re \cdot -0.25\right)}\right) \]
    6. Simplified23.5%

      \[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)} \]
    7. Applied egg-rr30.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 3.1 \cdot 10^{+181}:\\ \;\;\;\;\left(re \cdot re\right) \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot -3\\ \end{array} \]

Alternative 13: 29.2% 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.1%

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

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

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

    \[\leadsto \color{blue}{-1 \cdot \left(\cos re \cdot im\right)} \]
  5. Step-by-step derivation
    1. mul-1-neg49.9%

      \[\leadsto \color{blue}{-\cos re \cdot im} \]
    2. *-commutative49.9%

      \[\leadsto -\color{blue}{im \cdot \cos re} \]
    3. distribute-lft-neg-in49.9%

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

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

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

      \[\leadsto \color{blue}{-im} \]
  9. Simplified27.8%

    \[\leadsto \color{blue}{-im} \]
  10. Final simplification27.8%

    \[\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 2023240 
(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))))