math.cos on complex, imaginary part

Percentage Accurate: 66.4% → 99.8%
Time: 8.1s
Alternatives: 10
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 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 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.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -0.4 \lor \neg \left(t_0 \leq 5 \cdot 10^{-9}\right):\\ \;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\sin 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.4) (not (<= t_0 5e-9)))
     (* t_0 (* 0.5 (sin re)))
     (* (sin 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.4) || !(t_0 <= 5e-9)) {
		tmp = t_0 * (0.5 * sin(re));
	} else {
		tmp = sin(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.4d0)) .or. (.not. (t_0 <= 5d-9))) then
        tmp = t_0 * (0.5d0 * sin(re))
    else
        tmp = sin(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.4) || !(t_0 <= 5e-9)) {
		tmp = t_0 * (0.5 * Math.sin(re));
	} else {
		tmp = Math.sin(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.4) or not (t_0 <= 5e-9):
		tmp = t_0 * (0.5 * math.sin(re))
	else:
		tmp = math.sin(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.4) || !(t_0 <= 5e-9))
		tmp = Float64(t_0 * Float64(0.5 * sin(re)));
	else
		tmp = Float64(sin(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.4) || ~((t_0 <= 5e-9)))
		tmp = t_0 * (0.5 * sin(re));
	else
		tmp = sin(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.4], N[Not[LessEqual[t$95$0, 5e-9]], $MachinePrecision]], N[(t$95$0 * N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[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.4 \lor \neg \left(t_0 \leq 5 \cdot 10^{-9}\right):\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\

\mathbf{else}:\\
\;\;\;\;\sin 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 (neg.f64 im)) (exp.f64 im)) < -0.40000000000000002 or 5.0000000000000001e-9 < (-.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 -0.40000000000000002 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 5.0000000000000001e-9

    1. Initial program 31.0%

      \[\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}{-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + -1 \cdot \left(\sin re \cdot im\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg99.8%

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

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

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

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

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

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

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

Alternative 2: 94.5% 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 := -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\ \mathbf{if}\;im \leq -8.6 \cdot 10^{+127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -108000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 0.039:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 5.7 \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 (* -0.16666666666666666 (* (sin re) (pow im 3.0)))))
   (if (<= im -8.6e+127)
     t_1
     (if (<= im -108000.0)
       t_0
       (if (<= im 0.039)
         (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))
         (if (<= im 5.7e+102) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = (exp(-im) - exp(im)) * (0.5 * re);
	double t_1 = -0.16666666666666666 * (sin(re) * pow(im, 3.0));
	double tmp;
	if (im <= -8.6e+127) {
		tmp = t_1;
	} else if (im <= -108000.0) {
		tmp = t_0;
	} else if (im <= 0.039) {
		tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 5.7e+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 = (-0.16666666666666666d0) * (sin(re) * (im ** 3.0d0))
    if (im <= (-8.6d+127)) then
        tmp = t_1
    else if (im <= (-108000.0d0)) then
        tmp = t_0
    else if (im <= 0.039d0) then
        tmp = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    else if (im <= 5.7d+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 = -0.16666666666666666 * (Math.sin(re) * Math.pow(im, 3.0));
	double tmp;
	if (im <= -8.6e+127) {
		tmp = t_1;
	} else if (im <= -108000.0) {
		tmp = t_0;
	} else if (im <= 0.039) {
		tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else if (im <= 5.7e+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 = -0.16666666666666666 * (math.sin(re) * math.pow(im, 3.0))
	tmp = 0
	if im <= -8.6e+127:
		tmp = t_1
	elif im <= -108000.0:
		tmp = t_0
	elif im <= 0.039:
		tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	elif im <= 5.7e+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(-0.16666666666666666 * Float64(sin(re) * (im ^ 3.0)))
	tmp = 0.0
	if (im <= -8.6e+127)
		tmp = t_1;
	elseif (im <= -108000.0)
		tmp = t_0;
	elseif (im <= 0.039)
		tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	elseif (im <= 5.7e+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 = -0.16666666666666666 * (sin(re) * (im ^ 3.0));
	tmp = 0.0;
	if (im <= -8.6e+127)
		tmp = t_1;
	elseif (im <= -108000.0)
		tmp = t_0;
	elseif (im <= 0.039)
		tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	elseif (im <= 5.7e+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[(-0.16666666666666666 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -8.6e+127], t$95$1, If[LessEqual[im, -108000.0], t$95$0, If[LessEqual[im, 0.039], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.7e+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 := -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -8.6 \cdot 10^{+127}:\\
\;\;\;\;t_1\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -8.59999999999999968e127 or 5.6999999999999999e102 < 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}{-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + -1 \cdot \left(\sin re \cdot im\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg100.0%

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

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

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

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

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

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

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

    if -8.59999999999999968e127 < im < -108000 or 0.0389999999999999999 < im < 5.6999999999999999e102

    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 82.9%

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

    if -108000 < im < 0.0389999999999999999

    1. Initial program 33.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -8.6 \cdot 10^{+127}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -108000:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{elif}\;im \leq 0.039:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq 5.7 \cdot 10^{+102}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 3: 85.0% accurate, 1.5× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.35e92 or 2.39999999999999991 < 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 86.0%

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

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

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

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

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

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

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

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

    if -2.35e92 < im < -700

    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.0%

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

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

        \[\leadsto -\color{blue}{im \cdot \sin re} \]
      3. distribute-lft-neg-in3.0%

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

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

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

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

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

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

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

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

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

    if -700 < im < 2.39999999999999991

    1. Initial program 32.5%

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

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

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

        \[\leadsto -\color{blue}{im \cdot \sin re} \]
      3. distribute-lft-neg-in98.0%

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

      \[\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 -2.35 \cdot 10^{+92}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -700:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{elif}\;im \leq 2.4:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 4: 85.2% accurate, 1.5× speedup?

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

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

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

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


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

    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 97.7%

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

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

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

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

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

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

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

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

    if -2.35e92 < im < -520

    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.0%

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

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

        \[\leadsto -\color{blue}{im \cdot \sin re} \]
      3. distribute-lft-neg-in3.0%

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

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

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

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

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

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

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

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

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

    if -520 < im

    1. Initial program 49.5%

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

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

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

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

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

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

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

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

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

Alternative 5: 70.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ t_1 := im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{if}\;im \leq -2.65 \cdot 10^{+213}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2.6 \cdot 10^{+182}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -5.5 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -520:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 0.225:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 3 \cdot 10^{+217}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* -0.16666666666666666 (* re (pow im 3.0))))
        (t_1 (* im (- (* 0.16666666666666666 (pow re 3.0)) re))))
   (if (<= im -2.65e+213)
     t_0
     (if (<= im -2.6e+182)
       t_1
       (if (<= im -5.5e+28)
         t_0
         (if (<= im -520.0)
           t_1
           (if (<= im 0.225)
             (* im (- (sin re)))
             (if (<= im 3e+217) t_1 t_0))))))))
double code(double re, double im) {
	double t_0 = -0.16666666666666666 * (re * pow(im, 3.0));
	double t_1 = im * ((0.16666666666666666 * pow(re, 3.0)) - re);
	double tmp;
	if (im <= -2.65e+213) {
		tmp = t_0;
	} else if (im <= -2.6e+182) {
		tmp = t_1;
	} else if (im <= -5.5e+28) {
		tmp = t_0;
	} else if (im <= -520.0) {
		tmp = t_1;
	} else if (im <= 0.225) {
		tmp = im * -sin(re);
	} else if (im <= 3e+217) {
		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 = (-0.16666666666666666d0) * (re * (im ** 3.0d0))
    t_1 = im * ((0.16666666666666666d0 * (re ** 3.0d0)) - re)
    if (im <= (-2.65d+213)) then
        tmp = t_0
    else if (im <= (-2.6d+182)) then
        tmp = t_1
    else if (im <= (-5.5d+28)) then
        tmp = t_0
    else if (im <= (-520.0d0)) then
        tmp = t_1
    else if (im <= 0.225d0) then
        tmp = im * -sin(re)
    else if (im <= 3d+217) 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 = -0.16666666666666666 * (re * Math.pow(im, 3.0));
	double t_1 = im * ((0.16666666666666666 * Math.pow(re, 3.0)) - re);
	double tmp;
	if (im <= -2.65e+213) {
		tmp = t_0;
	} else if (im <= -2.6e+182) {
		tmp = t_1;
	} else if (im <= -5.5e+28) {
		tmp = t_0;
	} else if (im <= -520.0) {
		tmp = t_1;
	} else if (im <= 0.225) {
		tmp = im * -Math.sin(re);
	} else if (im <= 3e+217) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = -0.16666666666666666 * (re * math.pow(im, 3.0))
	t_1 = im * ((0.16666666666666666 * math.pow(re, 3.0)) - re)
	tmp = 0
	if im <= -2.65e+213:
		tmp = t_0
	elif im <= -2.6e+182:
		tmp = t_1
	elif im <= -5.5e+28:
		tmp = t_0
	elif im <= -520.0:
		tmp = t_1
	elif im <= 0.225:
		tmp = im * -math.sin(re)
	elif im <= 3e+217:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(-0.16666666666666666 * Float64(re * (im ^ 3.0)))
	t_1 = Float64(im * Float64(Float64(0.16666666666666666 * (re ^ 3.0)) - re))
	tmp = 0.0
	if (im <= -2.65e+213)
		tmp = t_0;
	elseif (im <= -2.6e+182)
		tmp = t_1;
	elseif (im <= -5.5e+28)
		tmp = t_0;
	elseif (im <= -520.0)
		tmp = t_1;
	elseif (im <= 0.225)
		tmp = Float64(im * Float64(-sin(re)));
	elseif (im <= 3e+217)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = -0.16666666666666666 * (re * (im ^ 3.0));
	t_1 = im * ((0.16666666666666666 * (re ^ 3.0)) - re);
	tmp = 0.0;
	if (im <= -2.65e+213)
		tmp = t_0;
	elseif (im <= -2.6e+182)
		tmp = t_1;
	elseif (im <= -5.5e+28)
		tmp = t_0;
	elseif (im <= -520.0)
		tmp = t_1;
	elseif (im <= 0.225)
		tmp = im * -sin(re);
	elseif (im <= 3e+217)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(-0.16666666666666666 * N[(re * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(im * N[(N[(0.16666666666666666 * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.65e+213], t$95$0, If[LessEqual[im, -2.6e+182], t$95$1, If[LessEqual[im, -5.5e+28], t$95$0, If[LessEqual[im, -520.0], t$95$1, If[LessEqual[im, 0.225], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 3e+217], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -2.6 \cdot 10^{+182}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -5.5 \cdot 10^{+28}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;im \leq 3 \cdot 10^{+217}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -2.6499999999999999e213 or -2.6e182 < im < -5.5000000000000003e28 or 2.99999999999999976e217 < 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 69.0%

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

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

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

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

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

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

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

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

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

    if -2.6499999999999999e213 < im < -2.6e182 or -5.5000000000000003e28 < im < -520 or 0.225000000000000006 < im < 2.99999999999999976e217

    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.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if -520 < im < 0.225000000000000006

    1. Initial program 32.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.65 \cdot 10^{+213}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -2.6 \cdot 10^{+182}:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{elif}\;im \leq -5.5 \cdot 10^{+28}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -520:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{elif}\;im \leq 0.225:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{elif}\;im \leq 3 \cdot 10^{+217}:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ \end{array} \]

Alternative 6: 75.7% accurate, 2.6× speedup?

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

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

\mathbf{elif}\;im \leq -2.6 \cdot 10^{+182}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq -1.65 \cdot 10^{+31}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;im \leq 1.6 \cdot 10^{-5}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -3.0000000000000001e213 or -2.6e182 < im < -1.64999999999999996e31

    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 61.8%

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

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

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

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

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

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

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

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

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

    if -3.0000000000000001e213 < im < -2.6e182 or -1.64999999999999996e31 < im < -660

    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.0%

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

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

        \[\leadsto -\color{blue}{im \cdot \sin re} \]
      3. distribute-lft-neg-in4.0%

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

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

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

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

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

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

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

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

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

    if -660 < im < 1.59999999999999993e-5

    1. Initial program 32.0%

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

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

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

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

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

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

    if 1.59999999999999993e-5 < 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 74.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3 \cdot 10^{+213}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -2.6 \cdot 10^{+182}:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{elif}\;im \leq -1.65 \cdot 10^{+31}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\ \mathbf{elif}\;im \leq -660:\\ \;\;\;\;im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)\\ \mathbf{elif}\;im \leq 1.6 \cdot 10^{-5}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 7: 76.3% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.02 \cdot 10^{+29} \lor \neg \left(im \leq 8 \cdot 10^{+82}\right):\\ \;\;\;\;-0.16666666666666666 \cdot \left(re \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.02e+29) (not (<= im 8e+82)))
   (* -0.16666666666666666 (* re (pow im 3.0)))
   (* im (- (sin re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -1.02e+29) || !(im <= 8e+82)) {
		tmp = -0.16666666666666666 * (re * 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.02d+29)) .or. (.not. (im <= 8d+82))) then
        tmp = (-0.16666666666666666d0) * (re * (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.02e+29) || !(im <= 8e+82)) {
		tmp = -0.16666666666666666 * (re * Math.pow(im, 3.0));
	} else {
		tmp = im * -Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -1.02e+29) or not (im <= 8e+82):
		tmp = -0.16666666666666666 * (re * math.pow(im, 3.0))
	else:
		tmp = im * -math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -1.02e+29) || !(im <= 8e+82))
		tmp = Float64(-0.16666666666666666 * Float64(re * (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.02e+29) || ~((im <= 8e+82)))
		tmp = -0.16666666666666666 * (re * (im ^ 3.0));
	else
		tmp = im * -sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -1.02e+29], N[Not[LessEqual[im, 8e+82]], $MachinePrecision]], N[(-0.16666666666666666 * N[(re * 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.02 \cdot 10^{+29} \lor \neg \left(im \leq 8 \cdot 10^{+82}\right):\\
\;\;\;\;-0.16666666666666666 \cdot \left(re \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.0200000000000001e29 or 7.9999999999999997e82 < 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 75.4%

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

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

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

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

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

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

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

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

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

    if -1.0200000000000001e29 < im < 7.9999999999999997e82

    1. Initial program 40.3%

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

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

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

        \[\leadsto -\color{blue}{im \cdot \sin re} \]
      3. distribute-lft-neg-in87.0%

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

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

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

Alternative 8: 51.2% accurate, 3.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Final simplification54.5%

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

Alternative 9: 33.5% 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 63.9%

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

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

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

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

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

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

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

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

Alternative 10: 3.2% accurate, 102.7× speedup?

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

\\
re \cdot 13.5
\end{array}
Derivation
  1. Initial program 63.9%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Applied egg-rr3.6%

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{27} \]
  3. Taylor expanded in re around 0 3.4%

    \[\leadsto \color{blue}{13.5 \cdot re} \]
  4. Step-by-step derivation
    1. *-commutative3.4%

      \[\leadsto \color{blue}{re \cdot 13.5} \]
  5. Simplified3.4%

    \[\leadsto \color{blue}{re \cdot 13.5} \]
  6. Final simplification3.4%

    \[\leadsto re \cdot 13.5 \]

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 2023193 
(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))))