math.sin on complex, imaginary part

Percentage Accurate: 54.4% → 99.6%
Time: 9.4s
Alternatives: 11
Speedup: 2.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -9.9999999999999999e52 or 2.00000000000000007e-10 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 100.0%

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

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

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

    if -9.9999999999999999e52 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 2.00000000000000007e-10

    1. Initial program 8.1%

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

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
    5. Step-by-step derivation
      1. distribute-lft-in99.8%

        \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(-2 \cdot im\right) + \left(0.5 \cdot \cos re\right) \cdot \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)} \]
      2. fma-def99.8%

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

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

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

        \[\leadsto \mathsf{fma}\left(\cos re \cdot 0.5, im \cdot -2, \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right) \]
      6. associate-*l*99.8%

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

        \[\leadsto \mathsf{fma}\left(\cos re \cdot 0.5, im \cdot -2, \cos re \cdot \left(0.5 \cdot \left(\color{blue}{{im}^{3} \cdot -0.3333333333333333} + -0.016666666666666666 \cdot {im}^{5}\right)\right)\right) \]
      8. fma-def99.8%

        \[\leadsto \mathsf{fma}\left(\cos re \cdot 0.5, im \cdot -2, \cos re \cdot \left(0.5 \cdot \color{blue}{\mathsf{fma}\left({im}^{3}, -0.3333333333333333, -0.016666666666666666 \cdot {im}^{5}\right)}\right)\right) \]
    6. Applied egg-rr99.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -1 \cdot 10^{+53} \lor \neg \left(e^{-im} - e^{im} \leq 2 \cdot 10^{-10}\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}^{5} \cdot -0.008333333333333333\right) - im\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 -0.004 \lor \neg \left(t_0 \leq 2 \cdot 10^{-10}\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.004) (not (<= t_0 2e-10)))
     (* (* 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.004) || !(t_0 <= 2e-10)) {
		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.004d0)) .or. (.not. (t_0 <= 2d-10))) 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.004) || !(t_0 <= 2e-10)) {
		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.004) or not (t_0 <= 2e-10):
		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.004) || !(t_0 <= 2e-10))
		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.004) || ~((t_0 <= 2e-10)))
		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.004], N[Not[LessEqual[t$95$0, 2e-10]], $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.004 \lor \neg \left(t_0 \leq 2 \cdot 10^{-10}\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.0040000000000000001 or 2.00000000000000007e-10 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 99.8%

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

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

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

    if -0.0040000000000000001 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 2.00000000000000007e-10

    1. Initial program 6.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -0.004 \lor \neg \left(e^{-im} - e^{im} \leq 2 \cdot 10^{-10}\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 3: 93.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\ \mathbf{if}\;im \leq -3.9 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -0.106:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 2.45 \cdot 10^{+58}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (cos re) (* (pow im 5.0) -0.008333333333333333))))
   (if (<= im -3.9e+62)
     t_0
     (if (<= im -0.106)
       (* 0.5 (- (exp (- im)) (exp im)))
       (if (<= im 1.1e+19)
         (* im (- (cos re)))
         (if (<= im 2.45e+58) (- (* (pow re 2.0) (* im 0.5)) im) t_0))))))
double code(double re, double im) {
	double t_0 = cos(re) * (pow(im, 5.0) * -0.008333333333333333);
	double tmp;
	if (im <= -3.9e+62) {
		tmp = t_0;
	} else if (im <= -0.106) {
		tmp = 0.5 * (exp(-im) - exp(im));
	} else if (im <= 1.1e+19) {
		tmp = im * -cos(re);
	} else if (im <= 2.45e+58) {
		tmp = (pow(re, 2.0) * (im * 0.5)) - 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 = cos(re) * ((im ** 5.0d0) * (-0.008333333333333333d0))
    if (im <= (-3.9d+62)) then
        tmp = t_0
    else if (im <= (-0.106d0)) then
        tmp = 0.5d0 * (exp(-im) - exp(im))
    else if (im <= 1.1d+19) then
        tmp = im * -cos(re)
    else if (im <= 2.45d+58) then
        tmp = ((re ** 2.0d0) * (im * 0.5d0)) - im
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.cos(re) * (Math.pow(im, 5.0) * -0.008333333333333333);
	double tmp;
	if (im <= -3.9e+62) {
		tmp = t_0;
	} else if (im <= -0.106) {
		tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
	} else if (im <= 1.1e+19) {
		tmp = im * -Math.cos(re);
	} else if (im <= 2.45e+58) {
		tmp = (Math.pow(re, 2.0) * (im * 0.5)) - im;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.cos(re) * (math.pow(im, 5.0) * -0.008333333333333333)
	tmp = 0
	if im <= -3.9e+62:
		tmp = t_0
	elif im <= -0.106:
		tmp = 0.5 * (math.exp(-im) - math.exp(im))
	elif im <= 1.1e+19:
		tmp = im * -math.cos(re)
	elif im <= 2.45e+58:
		tmp = (math.pow(re, 2.0) * (im * 0.5)) - im
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(cos(re) * Float64((im ^ 5.0) * -0.008333333333333333))
	tmp = 0.0
	if (im <= -3.9e+62)
		tmp = t_0;
	elseif (im <= -0.106)
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)));
	elseif (im <= 1.1e+19)
		tmp = Float64(im * Float64(-cos(re)));
	elseif (im <= 2.45e+58)
		tmp = Float64(Float64((re ^ 2.0) * Float64(im * 0.5)) - im);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = cos(re) * ((im ^ 5.0) * -0.008333333333333333);
	tmp = 0.0;
	if (im <= -3.9e+62)
		tmp = t_0;
	elseif (im <= -0.106)
		tmp = 0.5 * (exp(-im) - exp(im));
	elseif (im <= 1.1e+19)
		tmp = im * -cos(re);
	elseif (im <= 2.45e+58)
		tmp = ((re ^ 2.0) * (im * 0.5)) - im;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -3.9e+62], t$95$0, If[LessEqual[im, -0.106], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.1e+19], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 2.45e+58], N[(N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\
\mathbf{if}\;im \leq -3.9 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -0.106:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

\mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.9e62 or 2.45000000000000009e58 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -3.9e62 < im < -0.105999999999999997

    1. Initial program 100.0%

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

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

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

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

    if -0.105999999999999997 < im < 1.1e19

    1. Initial program 11.3%

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

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

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

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

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

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

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

    if 1.1e19 < im < 2.45000000000000009e58

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.9 \cdot 10^{+62}:\\ \;\;\;\;\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\ \mathbf{elif}\;im \leq -0.106:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 2.45 \cdot 10^{+58}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\ \end{array} \]

Alternative 4: 93.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\
\mathbf{if}\;im \leq -3.9 \cdot 10^{+62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -0.12:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.9e62 or 4.20000000000000024e58 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -3.9e62 < im < -0.12

    1. Initial program 100.0%

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

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

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

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

    if -0.12 < im < 1.1e19

    1. Initial program 11.3%

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

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

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

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

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

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

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

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

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

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

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

    if 1.1e19 < im < 4.20000000000000024e58

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3.9 \cdot 10^{+62}:\\ \;\;\;\;\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\ \mathbf{elif}\;im \leq -0.12:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 4.2 \cdot 10^{+58}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)\\ \end{array} \]

Alternative 5: 82.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.106:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+97}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -0.106)
   (* 0.5 (- (exp (- im)) (exp im)))
   (if (<= im 1.1e+19)
     (* im (- (cos re)))
     (if (<= im 1.8e+97)
       (- (* (pow re 2.0) (* im 0.5)) im)
       (- (* (pow im 5.0) -0.008333333333333333) im)))))
double code(double re, double im) {
	double tmp;
	if (im <= -0.106) {
		tmp = 0.5 * (exp(-im) - exp(im));
	} else if (im <= 1.1e+19) {
		tmp = im * -cos(re);
	} else if (im <= 1.8e+97) {
		tmp = (pow(re, 2.0) * (im * 0.5)) - im;
	} else {
		tmp = (pow(im, 5.0) * -0.008333333333333333) - im;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= (-0.106d0)) then
        tmp = 0.5d0 * (exp(-im) - exp(im))
    else if (im <= 1.1d+19) then
        tmp = im * -cos(re)
    else if (im <= 1.8d+97) then
        tmp = ((re ** 2.0d0) * (im * 0.5d0)) - im
    else
        tmp = ((im ** 5.0d0) * (-0.008333333333333333d0)) - im
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -0.106) {
		tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
	} else if (im <= 1.1e+19) {
		tmp = im * -Math.cos(re);
	} else if (im <= 1.8e+97) {
		tmp = (Math.pow(re, 2.0) * (im * 0.5)) - im;
	} else {
		tmp = (Math.pow(im, 5.0) * -0.008333333333333333) - im;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -0.106:
		tmp = 0.5 * (math.exp(-im) - math.exp(im))
	elif im <= 1.1e+19:
		tmp = im * -math.cos(re)
	elif im <= 1.8e+97:
		tmp = (math.pow(re, 2.0) * (im * 0.5)) - im
	else:
		tmp = (math.pow(im, 5.0) * -0.008333333333333333) - im
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -0.106)
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)));
	elseif (im <= 1.1e+19)
		tmp = Float64(im * Float64(-cos(re)));
	elseif (im <= 1.8e+97)
		tmp = Float64(Float64((re ^ 2.0) * Float64(im * 0.5)) - im);
	else
		tmp = Float64(Float64((im ^ 5.0) * -0.008333333333333333) - im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -0.106)
		tmp = 0.5 * (exp(-im) - exp(im));
	elseif (im <= 1.1e+19)
		tmp = im * -cos(re);
	elseif (im <= 1.8e+97)
		tmp = ((re ^ 2.0) * (im * 0.5)) - im;
	else
		tmp = ((im ^ 5.0) * -0.008333333333333333) - im;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -0.106], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.1e+19], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 1.8e+97], N[(N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] - im), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\

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

\mathbf{else}:\\
\;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -0.105999999999999997

    1. Initial program 100.0%

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

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

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

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

    if -0.105999999999999997 < im < 1.1e19

    1. Initial program 11.3%

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

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

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

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

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

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

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

    if 1.1e19 < im < 1.79999999999999983e97

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.79999999999999983e97 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{\left(0.5 \cdot -0.016666666666666666\right) \cdot {im}^{5}}\right) \]
      8. metadata-eval100.0%

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{-0.008333333333333333} \cdot {im}^{5}\right) \]
      9. mul-1-neg100.0%

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

        \[\leadsto \cos re \cdot \left(\left(-im\right) + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) \]
    8. Simplified100.0%

      \[\leadsto \color{blue}{\cos re \cdot \left(\left(-im\right) + {im}^{5} \cdot -0.008333333333333333\right)} \]
    9. Taylor expanded in re around 0 80.5%

      \[\leadsto \color{blue}{-0.008333333333333333 \cdot {im}^{5} - im} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification87.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -0.106:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+19}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+97}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\ \end{array} \]

Alternative 6: 90.0% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos re \cdot \left(\color{blue}{-1} \cdot im + 0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\right) \]
    7. associate-*r*89.2%

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

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

      \[\leadsto \cos re \cdot \left(\color{blue}{\left(-im\right)} + -0.008333333333333333 \cdot {im}^{5}\right) \]
    10. *-commutative89.2%

      \[\leadsto \cos re \cdot \left(\left(-im\right) + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) \]
  8. Simplified89.2%

    \[\leadsto \color{blue}{\cos re \cdot \left(\left(-im\right) + {im}^{5} \cdot -0.008333333333333333\right)} \]
  9. Taylor expanded in re around inf 89.2%

    \[\leadsto \color{blue}{\cos re \cdot \left(-0.008333333333333333 \cdot {im}^{5} - im\right)} \]
  10. Final simplification89.2%

    \[\leadsto \cos re \cdot \left({im}^{5} \cdot -0.008333333333333333 - im\right) \]

Alternative 7: 79.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{5} \cdot -0.008333333333333333 - im\\ \mathbf{if}\;im \leq -1.6 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 620:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{+97}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (* (pow im 5.0) -0.008333333333333333) im)))
   (if (<= im -1.6e+23)
     t_0
     (if (<= im 620.0)
       (* im (- (cos re)))
       (if (<= im 1.7e+97) (- (* (pow re 2.0) (* im 0.5)) im) t_0)))))
double code(double re, double im) {
	double t_0 = (pow(im, 5.0) * -0.008333333333333333) - im;
	double tmp;
	if (im <= -1.6e+23) {
		tmp = t_0;
	} else if (im <= 620.0) {
		tmp = im * -cos(re);
	} else if (im <= 1.7e+97) {
		tmp = (pow(re, 2.0) * (im * 0.5)) - 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 ** 5.0d0) * (-0.008333333333333333d0)) - im
    if (im <= (-1.6d+23)) then
        tmp = t_0
    else if (im <= 620.0d0) then
        tmp = im * -cos(re)
    else if (im <= 1.7d+97) then
        tmp = ((re ** 2.0d0) * (im * 0.5d0)) - 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, 5.0) * -0.008333333333333333) - im;
	double tmp;
	if (im <= -1.6e+23) {
		tmp = t_0;
	} else if (im <= 620.0) {
		tmp = im * -Math.cos(re);
	} else if (im <= 1.7e+97) {
		tmp = (Math.pow(re, 2.0) * (im * 0.5)) - im;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = (math.pow(im, 5.0) * -0.008333333333333333) - im
	tmp = 0
	if im <= -1.6e+23:
		tmp = t_0
	elif im <= 620.0:
		tmp = im * -math.cos(re)
	elif im <= 1.7e+97:
		tmp = (math.pow(re, 2.0) * (im * 0.5)) - im
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(Float64((im ^ 5.0) * -0.008333333333333333) - im)
	tmp = 0.0
	if (im <= -1.6e+23)
		tmp = t_0;
	elseif (im <= 620.0)
		tmp = Float64(im * Float64(-cos(re)));
	elseif (im <= 1.7e+97)
		tmp = Float64(Float64((re ^ 2.0) * Float64(im * 0.5)) - im);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = ((im ^ 5.0) * -0.008333333333333333) - im;
	tmp = 0.0;
	if (im <= -1.6e+23)
		tmp = t_0;
	elseif (im <= 620.0)
		tmp = im * -cos(re);
	elseif (im <= 1.7e+97)
		tmp = ((re ^ 2.0) * (im * 0.5)) - im;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] - im), $MachinePrecision]}, If[LessEqual[im, -1.6e+23], t$95$0, If[LessEqual[im, 620.0], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 1.7e+97], N[(N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{5} \cdot -0.008333333333333333 - im\\
\mathbf{if}\;im \leq -1.6 \cdot 10^{+23}:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.6e23 or 1.70000000000000005e97 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \left(\color{blue}{-1} \cdot im + 0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\right) \]
      7. associate-*r*93.1%

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{\left(0.5 \cdot -0.016666666666666666\right) \cdot {im}^{5}}\right) \]
      8. metadata-eval93.1%

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{-0.008333333333333333} \cdot {im}^{5}\right) \]
      9. mul-1-neg93.1%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-im\right)} + -0.008333333333333333 \cdot {im}^{5}\right) \]
      10. *-commutative93.1%

        \[\leadsto \cos re \cdot \left(\left(-im\right) + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) \]
    8. Simplified93.1%

      \[\leadsto \color{blue}{\cos re \cdot \left(\left(-im\right) + {im}^{5} \cdot -0.008333333333333333\right)} \]
    9. Taylor expanded in re around 0 71.0%

      \[\leadsto \color{blue}{-0.008333333333333333 \cdot {im}^{5} - im} \]

    if -1.6e23 < im < 620

    1. Initial program 13.7%

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

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

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

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

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

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

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

    if 620 < im < 1.70000000000000005e97

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.6 \cdot 10^{+23}:\\ \;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\ \mathbf{elif}\;im \leq 620:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{+97}:\\ \;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right) - im\\ \mathbf{else}:\\ \;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\ \end{array} \]

Alternative 8: 75.3% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -4.2 \cdot 10^{+46} \lor \neg \left(im \leq 1.7 \cdot 10^{+97}\right):\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -4.2e46 or 1.70000000000000005e97 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.2e46 < im < 1.70000000000000005e97

    1. Initial program 24.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.2 \cdot 10^{+46} \lor \neg \left(im \leq 1.7 \cdot 10^{+97}\right):\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \]

Alternative 9: 77.9% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.48 \cdot 10^{+23} \lor \neg \left(im \leq 1.7 \cdot 10^{+97}\right):\\
\;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.4799999999999999e23 or 1.70000000000000005e97 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos re \cdot \left(\color{blue}{-1} \cdot im + 0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\right) \]
      7. associate-*r*93.1%

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{\left(0.5 \cdot -0.016666666666666666\right) \cdot {im}^{5}}\right) \]
      8. metadata-eval93.1%

        \[\leadsto \cos re \cdot \left(-1 \cdot im + \color{blue}{-0.008333333333333333} \cdot {im}^{5}\right) \]
      9. mul-1-neg93.1%

        \[\leadsto \cos re \cdot \left(\color{blue}{\left(-im\right)} + -0.008333333333333333 \cdot {im}^{5}\right) \]
      10. *-commutative93.1%

        \[\leadsto \cos re \cdot \left(\left(-im\right) + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) \]
    8. Simplified93.1%

      \[\leadsto \color{blue}{\cos re \cdot \left(\left(-im\right) + {im}^{5} \cdot -0.008333333333333333\right)} \]
    9. Taylor expanded in re around 0 71.0%

      \[\leadsto \color{blue}{-0.008333333333333333 \cdot {im}^{5} - im} \]

    if -1.4799999999999999e23 < im < 1.70000000000000005e97

    1. Initial program 22.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.48 \cdot 10^{+23} \lor \neg \left(im \leq 1.7 \cdot 10^{+97}\right):\\ \;\;\;\;{im}^{5} \cdot -0.008333333333333333 - im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\cos re\right)\\ \end{array} \]

Alternative 10: 51.9% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 11: 29.9% accurate, 154.5× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-im} \]
  10. Final simplification30.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 2023318 
(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))))