math.cos on complex, imaginary part

Percentage Accurate: 66.4% → 99.7%
Time: 9.4s
Alternatives: 11
Speedup: 2.8×

Specification

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

\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-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: 66.4% accurate, 1.0× speedup?

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

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

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -10000000 \lor \neg \left(t_0 \leq 0.001\right):\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -1e7 or 1e-3 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]

    if -1e7 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 1e-3

    1. Initial program 35.6%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 99.8%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*99.8%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out99.8%

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

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

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{3} \cdot -0.16666666666666666\right)} \]
    5. Taylor expanded in re around inf 99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -10000000 \lor \neg \left(e^{-im} - e^{im} \leq 0.001\right):\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \end{array} \]

Alternative 2: 93.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \mathbf{if}\;im \leq -1.7 \cdot 10^{+106}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -510:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(27 - im \cdot \sin re\right)\right)\\ \mathbf{elif}\;im \leq 1950:\\ \;\;\;\;\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (pow im 3.0) (* (sin re) -0.16666666666666666))))
   (if (<= im -1.7e+106)
     t_0
     (if (<= im -510.0)
       (log1p (expm1 (- 27.0 (* im (sin re)))))
       (if (<= im 1950.0)
         (* (sin re) (- (* -0.16666666666666666 (pow im 3.0)) im))
         (if (<= im 5.6e+102)
           (* (- (exp (- im)) (exp im)) (* 0.5 re))
           t_0))))))
double code(double re, double im) {
	double t_0 = pow(im, 3.0) * (sin(re) * -0.16666666666666666);
	double tmp;
	if (im <= -1.7e+106) {
		tmp = t_0;
	} else if (im <= -510.0) {
		tmp = log1p(expm1((27.0 - (im * sin(re)))));
	} else if (im <= 1950.0) {
		tmp = sin(re) * ((-0.16666666666666666 * pow(im, 3.0)) - im);
	} else if (im <= 5.6e+102) {
		tmp = (exp(-im) - exp(im)) * (0.5 * re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.pow(im, 3.0) * (Math.sin(re) * -0.16666666666666666);
	double tmp;
	if (im <= -1.7e+106) {
		tmp = t_0;
	} else if (im <= -510.0) {
		tmp = Math.log1p(Math.expm1((27.0 - (im * Math.sin(re)))));
	} else if (im <= 1950.0) {
		tmp = Math.sin(re) * ((-0.16666666666666666 * Math.pow(im, 3.0)) - im);
	} else if (im <= 5.6e+102) {
		tmp = (Math.exp(-im) - Math.exp(im)) * (0.5 * re);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.pow(im, 3.0) * (math.sin(re) * -0.16666666666666666)
	tmp = 0
	if im <= -1.7e+106:
		tmp = t_0
	elif im <= -510.0:
		tmp = math.log1p(math.expm1((27.0 - (im * math.sin(re)))))
	elif im <= 1950.0:
		tmp = math.sin(re) * ((-0.16666666666666666 * math.pow(im, 3.0)) - im)
	elif im <= 5.6e+102:
		tmp = (math.exp(-im) - math.exp(im)) * (0.5 * re)
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64((im ^ 3.0) * Float64(sin(re) * -0.16666666666666666))
	tmp = 0.0
	if (im <= -1.7e+106)
		tmp = t_0;
	elseif (im <= -510.0)
		tmp = log1p(expm1(Float64(27.0 - Float64(im * sin(re)))));
	elseif (im <= 1950.0)
		tmp = Float64(sin(re) * Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) - im));
	elseif (im <= 5.6e+102)
		tmp = Float64(Float64(exp(Float64(-im)) - exp(im)) * Float64(0.5 * re));
	else
		tmp = t_0;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[Power[im, 3.0], $MachinePrecision] * N[(N[Sin[re], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.7e+106], t$95$0, If[LessEqual[im, -510.0], N[Log[1 + N[(Exp[N[(27.0 - N[(im * N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 1950.0], N[(N[Sin[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.6e+102], N[(N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\
\mathbf{if}\;im \leq -1.7 \cdot 10^{+106}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -510:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(27 - im \cdot \sin re\right)\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -1.69999999999999997e106 or 5.60000000000000037e102 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out100.0%

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

        \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{{im}^{3} \cdot -0.16666666666666666}\right) \]
    4. Simplified100.0%

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*100.0%

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

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

        \[\leadsto \color{blue}{{im}^{3} \cdot \left(-0.16666666666666666 \cdot \sin re\right)} \]
    8. Simplified100.0%

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

    if -1.69999999999999997e106 < im < -510

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 30.8%

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

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

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right) + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right)\right) - im \cdot \sin re} \]
      4. associate-*r*30.8%

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

        \[\leadsto \left(\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re + \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re}\right) - im \cdot \sin re \]
      6. distribute-rgt-out30.8%

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

        \[\leadsto \sin re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} + -0.008333333333333333 \cdot {im}^{5}\right) - im \cdot \sin re \]
      8. *-commutative30.8%

        \[\leadsto \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) - im \cdot \sin re \]
    4. Simplified30.8%

      \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 + {im}^{5} \cdot -0.008333333333333333\right) - im \cdot \sin re} \]
    5. Applied egg-rr3.0%

      \[\leadsto \color{blue}{27} - im \cdot \sin re \]
    6. Step-by-step derivation
      1. log1p-expm1-u66.2%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(27 - im \cdot \sin re\right)\right)} \]
      2. *-commutative66.2%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(27 - \color{blue}{\sin re \cdot im}\right)\right) \]
    7. Applied egg-rr66.2%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(27 - \sin re \cdot im\right)\right)} \]

    if -510 < im < 1950

    1. Initial program 37.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 97.6%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*97.6%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out97.6%

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

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

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{3} \cdot -0.16666666666666666\right)} \]
    5. Taylor expanded in re around inf 97.6%

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

    if 1950 < im < 5.60000000000000037e102

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 66.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.7 \cdot 10^{+106}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \mathbf{elif}\;im \leq -510:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(27 - im \cdot \sin re\right)\right)\\ \mathbf{elif}\;im \leq 1950:\\ \;\;\;\;\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \end{array} \]

Alternative 3: 94.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\
t_1 := {im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\
\mathbf{if}\;im \leq -1.85 \cdot 10^{+117}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.8499999999999999e117 or 5.60000000000000037e102 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 100.0%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*100.0%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out100.0%

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

        \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{{im}^{3} \cdot -0.16666666666666666}\right) \]
    4. Simplified100.0%

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*100.0%

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

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

        \[\leadsto \color{blue}{{im}^{3} \cdot \left(-0.16666666666666666 \cdot \sin re\right)} \]
    8. Simplified100.0%

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

    if -1.8499999999999999e117 < im < -8.5 or 1950 < im < 5.60000000000000037e102

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 67.8%

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

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

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

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

    if -8.5 < im < 1950

    1. Initial program 37.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 97.6%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*97.6%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out97.6%

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

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

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{3} \cdot -0.16666666666666666\right)} \]
    5. Taylor expanded in re around inf 97.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.85 \cdot 10^{+117}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \mathbf{elif}\;im \leq -8.5:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{elif}\;im \leq 1950:\\ \;\;\;\;\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \end{array} \]

Alternative 4: 85.7% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\
t_1 := {im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\
\mathbf{if}\;im \leq -5.2 \cdot 10^{+101}:\\
\;\;\;\;t_1\\

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

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

\mathbf{elif}\;im \leq 7.4 \cdot 10^{+96}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -5.2e101 or 7.39999999999999982e96 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 94.8%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*94.8%

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

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

        \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
      4. distribute-rgt-out94.8%

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + -0.16666666666666666 \cdot {im}^{3}\right)} \]
      5. *-commutative94.8%

        \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{{im}^{3} \cdot -0.16666666666666666}\right) \]
    4. Simplified94.8%

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{3} \cdot -0.16666666666666666\right)} \]
    5. Taylor expanded in re around inf 94.8%

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*94.8%

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

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

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

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

    if -5.2e101 < im < -2.2e11 or 620 < im < 7.39999999999999982e96

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 3.1%

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

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

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

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
    5. Taylor expanded in re around 0 32.0%

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

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

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

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

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

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

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

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

    if -2.2e11 < im < 620

    1. Initial program 37.7%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 96.2%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified96.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.2 \cdot 10^{+101}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \mathbf{elif}\;im \leq -220000000000:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{elif}\;im \leq 620:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 7.4 \cdot 10^{+96}:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right)\\ \end{array} \]

Alternative 5: 83.3% accurate, 1.5× speedup?

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

\\
\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)
\end{array}
Derivation
  1. Initial program 70.8%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Taylor expanded in im around 0 79.4%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
  3. Step-by-step derivation
    1. associate-*r*79.4%

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

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

      \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re} \]
    4. distribute-rgt-out79.4%

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

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

    \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{3} \cdot -0.16666666666666666\right)} \]
  5. Taylor expanded in re around inf 79.4%

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

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

Alternative 6: 77.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ t_1 := im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{if}\;im \leq -2.5 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -220000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 650:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 1.76 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* re (* -0.16666666666666666 (pow im 3.0))))
        (t_1 (* im (- (* (pow re 3.0) 0.16666666666666666) re))))
   (if (<= im -2.5e+81)
     t_0
     (if (<= im -220000000000.0)
       t_1
       (if (<= im 650.0) (* im (- (sin re))) (if (<= im 1.76e+93) t_1 t_0))))))
double code(double re, double im) {
	double t_0 = re * (-0.16666666666666666 * pow(im, 3.0));
	double t_1 = im * ((pow(re, 3.0) * 0.16666666666666666) - re);
	double tmp;
	if (im <= -2.5e+81) {
		tmp = t_0;
	} else if (im <= -220000000000.0) {
		tmp = t_1;
	} else if (im <= 650.0) {
		tmp = im * -sin(re);
	} else if (im <= 1.76e+93) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = re * ((-0.16666666666666666d0) * (im ** 3.0d0))
    t_1 = im * (((re ** 3.0d0) * 0.16666666666666666d0) - re)
    if (im <= (-2.5d+81)) then
        tmp = t_0
    else if (im <= (-220000000000.0d0)) then
        tmp = t_1
    else if (im <= 650.0d0) then
        tmp = im * -sin(re)
    else if (im <= 1.76d+93) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = re * (-0.16666666666666666 * Math.pow(im, 3.0));
	double t_1 = im * ((Math.pow(re, 3.0) * 0.16666666666666666) - re);
	double tmp;
	if (im <= -2.5e+81) {
		tmp = t_0;
	} else if (im <= -220000000000.0) {
		tmp = t_1;
	} else if (im <= 650.0) {
		tmp = im * -Math.sin(re);
	} else if (im <= 1.76e+93) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = re * (-0.16666666666666666 * math.pow(im, 3.0))
	t_1 = im * ((math.pow(re, 3.0) * 0.16666666666666666) - re)
	tmp = 0
	if im <= -2.5e+81:
		tmp = t_0
	elif im <= -220000000000.0:
		tmp = t_1
	elif im <= 650.0:
		tmp = im * -math.sin(re)
	elif im <= 1.76e+93:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(re * Float64(-0.16666666666666666 * (im ^ 3.0)))
	t_1 = Float64(im * Float64(Float64((re ^ 3.0) * 0.16666666666666666) - re))
	tmp = 0.0
	if (im <= -2.5e+81)
		tmp = t_0;
	elseif (im <= -220000000000.0)
		tmp = t_1;
	elseif (im <= 650.0)
		tmp = Float64(im * Float64(-sin(re)));
	elseif (im <= 1.76e+93)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = re * (-0.16666666666666666 * (im ^ 3.0));
	t_1 = im * (((re ^ 3.0) * 0.16666666666666666) - re);
	tmp = 0.0;
	if (im <= -2.5e+81)
		tmp = t_0;
	elseif (im <= -220000000000.0)
		tmp = t_1;
	elseif (im <= 650.0)
		tmp = im * -sin(re);
	elseif (im <= 1.76e+93)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(re * N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im * N[(N[(N[Power[re, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.5e+81], t$95$0, If[LessEqual[im, -220000000000.0], t$95$1, If[LessEqual[im, 650.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 1.76e+93], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\
t_1 := im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\
\mathbf{if}\;im \leq -2.5 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -220000000000:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 1.76 \cdot 10^{+93}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.4999999999999999e81 or 1.75999999999999994e93 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 74.2%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    6. Taylor expanded in im around inf 68.1%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*68.1%

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

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

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

    if -2.4999999999999999e81 < im < -2.2e11 or 650 < im < 1.75999999999999994e93

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 3.1%

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

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

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

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
    5. Taylor expanded in re around 0 34.2%

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

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

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

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

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

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

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

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

    if -2.2e11 < im < 650

    1. Initial program 37.7%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 96.2%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified96.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.5 \cdot 10^{+81}:\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -220000000000:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{elif}\;im \leq 650:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 1.76 \cdot 10^{+93}:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 7: 77.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.16666666666666666 \cdot {im}^{3}\\ t_1 := im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{if}\;im \leq -2.3 \cdot 10^{+81}:\\ \;\;\;\;re \cdot t_0\\ \mathbf{elif}\;im \leq -220000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 660:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 2.25 \cdot 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(t_0 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.16666666666666666 (pow im 3.0)))
        (t_1 (* im (- (* (pow re 3.0) 0.16666666666666666) re))))
   (if (<= im -2.3e+81)
     (* re t_0)
     (if (<= im -220000000000.0)
       t_1
       (if (<= im 660.0)
         (* im (- (sin re)))
         (if (<= im 2.25e+92) t_1 (* re (- t_0 im))))))))
double code(double re, double im) {
	double t_0 = -0.16666666666666666 * pow(im, 3.0);
	double t_1 = im * ((pow(re, 3.0) * 0.16666666666666666) - re);
	double tmp;
	if (im <= -2.3e+81) {
		tmp = re * t_0;
	} else if (im <= -220000000000.0) {
		tmp = t_1;
	} else if (im <= 660.0) {
		tmp = im * -sin(re);
	} else if (im <= 2.25e+92) {
		tmp = t_1;
	} else {
		tmp = re * (t_0 - 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) :: t_1
    real(8) :: tmp
    t_0 = (-0.16666666666666666d0) * (im ** 3.0d0)
    t_1 = im * (((re ** 3.0d0) * 0.16666666666666666d0) - re)
    if (im <= (-2.3d+81)) then
        tmp = re * t_0
    else if (im <= (-220000000000.0d0)) then
        tmp = t_1
    else if (im <= 660.0d0) then
        tmp = im * -sin(re)
    else if (im <= 2.25d+92) then
        tmp = t_1
    else
        tmp = re * (t_0 - im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = -0.16666666666666666 * Math.pow(im, 3.0);
	double t_1 = im * ((Math.pow(re, 3.0) * 0.16666666666666666) - re);
	double tmp;
	if (im <= -2.3e+81) {
		tmp = re * t_0;
	} else if (im <= -220000000000.0) {
		tmp = t_1;
	} else if (im <= 660.0) {
		tmp = im * -Math.sin(re);
	} else if (im <= 2.25e+92) {
		tmp = t_1;
	} else {
		tmp = re * (t_0 - im);
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.16666666666666666 * math.pow(im, 3.0)
	t_1 = im * ((math.pow(re, 3.0) * 0.16666666666666666) - re)
	tmp = 0
	if im <= -2.3e+81:
		tmp = re * t_0
	elif im <= -220000000000.0:
		tmp = t_1
	elif im <= 660.0:
		tmp = im * -math.sin(re)
	elif im <= 2.25e+92:
		tmp = t_1
	else:
		tmp = re * (t_0 - im)
	return tmp
function code(re, im)
	t_0 = Float64(-0.16666666666666666 * (im ^ 3.0))
	t_1 = Float64(im * Float64(Float64((re ^ 3.0) * 0.16666666666666666) - re))
	tmp = 0.0
	if (im <= -2.3e+81)
		tmp = Float64(re * t_0);
	elseif (im <= -220000000000.0)
		tmp = t_1;
	elseif (im <= 660.0)
		tmp = Float64(im * Float64(-sin(re)));
	elseif (im <= 2.25e+92)
		tmp = t_1;
	else
		tmp = Float64(re * Float64(t_0 - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.16666666666666666 * (im ^ 3.0);
	t_1 = im * (((re ^ 3.0) * 0.16666666666666666) - re);
	tmp = 0.0;
	if (im <= -2.3e+81)
		tmp = re * t_0;
	elseif (im <= -220000000000.0)
		tmp = t_1;
	elseif (im <= 660.0)
		tmp = im * -sin(re);
	elseif (im <= 2.25e+92)
		tmp = t_1;
	else
		tmp = re * (t_0 - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im * N[(N[(N[Power[re, 3.0], $MachinePrecision] * 0.16666666666666666), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.3e+81], N[(re * t$95$0), $MachinePrecision], If[LessEqual[im, -220000000000.0], t$95$1, If[LessEqual[im, 660.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 2.25e+92], t$95$1, N[(re * N[(t$95$0 - im), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.16666666666666666 \cdot {im}^{3}\\
t_1 := im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\
\mathbf{if}\;im \leq -2.3 \cdot 10^{+81}:\\
\;\;\;\;re \cdot t_0\\

\mathbf{elif}\;im \leq -220000000000:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 2.25 \cdot 10^{+92}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 75.0%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    6. Taylor expanded in im around inf 70.7%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*70.7%

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

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

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

    if -2.2999999999999999e81 < im < -2.2e11 or 660 < im < 2.25e92

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 3.1%

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

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

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

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
    5. Taylor expanded in re around 0 34.2%

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

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

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

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

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

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

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

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

    if -2.2e11 < im < 660

    1. Initial program 37.7%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 96.2%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified96.2%

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

    if 2.25e92 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 73.5%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.3 \cdot 10^{+81}:\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -220000000000:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{elif}\;im \leq 660:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 2.25 \cdot 10^{+92}:\\ \;\;\;\;im \cdot \left({re}^{3} \cdot 0.16666666666666666 - re\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\ \end{array} \]

Alternative 8: 75.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+16} \lor \neg \left(im \leq 9.2 \cdot 10^{+91}\right):\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -1.35e+16) (not (<= im 9.2e+91)))
   (* re (* -0.16666666666666666 (pow im 3.0)))
   (* im (- (sin re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -1.35e+16) || !(im <= 9.2e+91)) {
		tmp = re * (-0.16666666666666666 * pow(im, 3.0));
	} else {
		tmp = im * -sin(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.35d+16)) .or. (.not. (im <= 9.2d+91))) then
        tmp = re * ((-0.16666666666666666d0) * (im ** 3.0d0))
    else
        tmp = im * -sin(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -1.35e+16) || !(im <= 9.2e+91)) {
		tmp = re * (-0.16666666666666666 * Math.pow(im, 3.0));
	} else {
		tmp = im * -Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -1.35e+16) or not (im <= 9.2e+91):
		tmp = re * (-0.16666666666666666 * math.pow(im, 3.0))
	else:
		tmp = im * -math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -1.35e+16) || !(im <= 9.2e+91))
		tmp = Float64(re * Float64(-0.16666666666666666 * (im ^ 3.0)));
	else
		tmp = Float64(im * Float64(-sin(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -1.35e+16) || ~((im <= 9.2e+91)))
		tmp = re * (-0.16666666666666666 * (im ^ 3.0));
	else
		tmp = im * -sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -1.35e+16], N[Not[LessEqual[im, 9.2e+91]], $MachinePrecision]], N[(re * N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.35 \cdot 10^{+16} \lor \neg \left(im \leq 9.2 \cdot 10^{+91}\right):\\
\;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.35e16 or 9.19999999999999965e91 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in re around 0 71.1%

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    6. Taylor expanded in im around inf 57.6%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left({im}^{3} \cdot re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*57.6%

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

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

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

    if -1.35e16 < im < 9.19999999999999965e91

    1. Initial program 47.4%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 81.8%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified81.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+16} \lor \neg \left(im \leq 9.2 \cdot 10^{+91}\right):\\ \;\;\;\;re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \]

Alternative 9: 55.2% accurate, 2.8× speedup?

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

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

\mathbf{elif}\;im \leq 1.85 \cdot 10^{+184}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\

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


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 4.3%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified4.3%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
    5. Taylor expanded in re around 0 15.9%

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

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

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

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

    if -1.15e16 < im < 1.8499999999999999e184

    1. Initial program 53.3%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 73.0%

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

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

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified73.0%

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

    if 1.8499999999999999e184 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Taylor expanded in im around 0 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right) + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right)\right) - im \cdot \sin re} \]
      4. associate-*r*100.0%

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

        \[\leadsto \left(\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re + \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re}\right) - im \cdot \sin re \]
      6. distribute-rgt-out100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 + {im}^{5} \cdot -0.008333333333333333\right) - im \cdot \sin re} \]
    5. Applied egg-rr5.5%

      \[\leadsto \color{blue}{27} - im \cdot \sin re \]
    6. Taylor expanded in re around 0 30.6%

      \[\leadsto \color{blue}{27 + -1 \cdot \left(im \cdot re\right)} \]
    7. Step-by-step derivation
      1. mul-1-neg30.6%

        \[\leadsto 27 + \color{blue}{\left(-im \cdot re\right)} \]
      2. *-commutative30.6%

        \[\leadsto 27 + \left(-\color{blue}{re \cdot im}\right) \]
      3. unsub-neg30.6%

        \[\leadsto \color{blue}{27 - re \cdot im} \]
    8. Simplified30.6%

      \[\leadsto \color{blue}{27 - re \cdot im} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification53.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.15 \cdot 10^{+16}:\\ \;\;\;\;im \cdot \left(-re\right)\\ \mathbf{elif}\;im \leq 1.85 \cdot 10^{+184}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;27 - im \cdot re\\ \end{array} \]

Alternative 10: 32.3% accurate, 77.0× speedup?

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

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

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Taylor expanded in im around 0 47.4%

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

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

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
  4. Simplified47.4%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Taylor expanded in re around 0 33.9%

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

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

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

    \[\leadsto \color{blue}{\left(-im\right) \cdot re} \]
  8. Final simplification33.9%

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

Alternative 11: 2.7% accurate, 308.0× speedup?

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

\\
27
\end{array}
Derivation
  1. Initial program 70.8%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Taylor expanded in im around 0 85.0%

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

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

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

      \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right) + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right)\right) - im \cdot \sin re} \]
    4. associate-*r*85.0%

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

      \[\leadsto \left(\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \sin re + \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re}\right) - im \cdot \sin re \]
    6. distribute-rgt-out85.0%

      \[\leadsto \color{blue}{\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} + -0.008333333333333333 \cdot {im}^{5}\right)} - im \cdot \sin re \]
    7. *-commutative85.0%

      \[\leadsto \sin re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} + -0.008333333333333333 \cdot {im}^{5}\right) - im \cdot \sin re \]
    8. *-commutative85.0%

      \[\leadsto \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) - im \cdot \sin re \]
  4. Simplified85.0%

    \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 + {im}^{5} \cdot -0.008333333333333333\right) - im \cdot \sin re} \]
  5. Applied egg-rr3.8%

    \[\leadsto \color{blue}{27} - im \cdot \sin re \]
  6. Taylor expanded in im around 0 2.6%

    \[\leadsto \color{blue}{27} \]
  7. Final simplification2.6%

    \[\leadsto 27 \]

Developer target: 99.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\sin 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 \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\


\end{array}
\end{array}

Reproduce

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

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

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))