math.sin on complex, imaginary part

Percentage Accurate: 54.6% → 99.8%
Time: 8.6s
Alternatives: 14
Speedup: 2.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 54.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -0.0100000000000000002 or 9.99999999999999955e-7 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 99.9%

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

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

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

    if -0.0100000000000000002 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 9.99999999999999955e-7

    1. Initial program 7.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq 0.005:\\ \;\;\;\;\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (<= t_0 0.005)
     (*
      (cos re)
      (+
       (fma (pow im 5.0) -0.008333333333333333 (- im))
       (+
        (* (pow im 7.0) -0.0001984126984126984)
        (* (pow im 3.0) -0.16666666666666666))))
     (* (* (cos re) 0.5) t_0))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if (t_0 <= 0.005) {
		tmp = cos(re) * (fma(pow(im, 5.0), -0.008333333333333333, -im) + ((pow(im, 7.0) * -0.0001984126984126984) + (pow(im, 3.0) * -0.16666666666666666)));
	} else {
		tmp = (cos(re) * 0.5) * t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if (t_0 <= 0.005)
		tmp = Float64(cos(re) * Float64(fma((im ^ 5.0), -0.008333333333333333, Float64(-im)) + Float64(Float64((im ^ 7.0) * -0.0001984126984126984) + Float64((im ^ 3.0) * -0.16666666666666666))));
	else
		tmp = Float64(Float64(cos(re) * 0.5) * t_0);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.005], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333 + (-im)), $MachinePrecision] + N[(N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision] + N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq 0.005:\\
\;\;\;\;\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right)\\

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


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

    1. Initial program 35.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{3} \cdot -0.16666666666666666 + {im}^{7} \cdot -0.0001984126984126984\right)\right)} \]

    if 0.0050000000000000001 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq 0.005:\\ \;\;\;\;\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array} \]

Alternative 3: 94.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := \cos re \cdot 0.5\\
\mathbf{if}\;t_0 \leq 0.005:\\
\;\;\;\;t_1 \cdot \left(im \cdot -2 + \left({im}^{5} \cdot -0.016666666666666666 + {im}^{3} \cdot -0.3333333333333333\right)\right)\\

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


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

    1. Initial program 35.3%

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

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

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

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

    if 0.0050000000000000001 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 100.0%

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

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

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

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

Alternative 4: 86.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{3} \cdot -0.16666666666666666\\ t_1 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\ t_2 := t_0 - im\\ t_3 := t_2 \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{if}\;im \leq -2 \cdot 10^{+238}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2 \cdot 10^{+167}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;im \leq -0.00098:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 0.00115:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 3.8 \cdot 10^{+241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+280}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (pow im 3.0) -0.16666666666666666))
        (t_1 (* 0.5 (- (exp (- im)) (exp im))))
        (t_2 (- t_0 im))
        (t_3 (* t_2 (+ (* -0.5 (* re re)) 1.0))))
   (if (<= im -2e+238)
     t_0
     (if (<= im -2e+167)
       t_3
       (if (<= im -0.00098)
         t_1
         (if (<= im 0.00115)
           (* (cos re) (- im))
           (if (<= im 3.8e+241) t_1 (if (<= im 7.2e+280) t_3 t_2))))))))
double code(double re, double im) {
	double t_0 = pow(im, 3.0) * -0.16666666666666666;
	double t_1 = 0.5 * (exp(-im) - exp(im));
	double t_2 = t_0 - im;
	double t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	double tmp;
	if (im <= -2e+238) {
		tmp = t_0;
	} else if (im <= -2e+167) {
		tmp = t_3;
	} else if (im <= -0.00098) {
		tmp = t_1;
	} else if (im <= 0.00115) {
		tmp = cos(re) * -im;
	} else if (im <= 3.8e+241) {
		tmp = t_1;
	} else if (im <= 7.2e+280) {
		tmp = t_3;
	} else {
		tmp = t_2;
	}
	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) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (im ** 3.0d0) * (-0.16666666666666666d0)
    t_1 = 0.5d0 * (exp(-im) - exp(im))
    t_2 = t_0 - im
    t_3 = t_2 * (((-0.5d0) * (re * re)) + 1.0d0)
    if (im <= (-2d+238)) then
        tmp = t_0
    else if (im <= (-2d+167)) then
        tmp = t_3
    else if (im <= (-0.00098d0)) then
        tmp = t_1
    else if (im <= 0.00115d0) then
        tmp = cos(re) * -im
    else if (im <= 3.8d+241) then
        tmp = t_1
    else if (im <= 7.2d+280) then
        tmp = t_3
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.pow(im, 3.0) * -0.16666666666666666;
	double t_1 = 0.5 * (Math.exp(-im) - Math.exp(im));
	double t_2 = t_0 - im;
	double t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	double tmp;
	if (im <= -2e+238) {
		tmp = t_0;
	} else if (im <= -2e+167) {
		tmp = t_3;
	} else if (im <= -0.00098) {
		tmp = t_1;
	} else if (im <= 0.00115) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 3.8e+241) {
		tmp = t_1;
	} else if (im <= 7.2e+280) {
		tmp = t_3;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.pow(im, 3.0) * -0.16666666666666666
	t_1 = 0.5 * (math.exp(-im) - math.exp(im))
	t_2 = t_0 - im
	t_3 = t_2 * ((-0.5 * (re * re)) + 1.0)
	tmp = 0
	if im <= -2e+238:
		tmp = t_0
	elif im <= -2e+167:
		tmp = t_3
	elif im <= -0.00098:
		tmp = t_1
	elif im <= 0.00115:
		tmp = math.cos(re) * -im
	elif im <= 3.8e+241:
		tmp = t_1
	elif im <= 7.2e+280:
		tmp = t_3
	else:
		tmp = t_2
	return tmp
function code(re, im)
	t_0 = Float64((im ^ 3.0) * -0.16666666666666666)
	t_1 = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im)))
	t_2 = Float64(t_0 - im)
	t_3 = Float64(t_2 * Float64(Float64(-0.5 * Float64(re * re)) + 1.0))
	tmp = 0.0
	if (im <= -2e+238)
		tmp = t_0;
	elseif (im <= -2e+167)
		tmp = t_3;
	elseif (im <= -0.00098)
		tmp = t_1;
	elseif (im <= 0.00115)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 3.8e+241)
		tmp = t_1;
	elseif (im <= 7.2e+280)
		tmp = t_3;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (im ^ 3.0) * -0.16666666666666666;
	t_1 = 0.5 * (exp(-im) - exp(im));
	t_2 = t_0 - im;
	t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	tmp = 0.0;
	if (im <= -2e+238)
		tmp = t_0;
	elseif (im <= -2e+167)
		tmp = t_3;
	elseif (im <= -0.00098)
		tmp = t_1;
	elseif (im <= 0.00115)
		tmp = cos(re) * -im;
	elseif (im <= 3.8e+241)
		tmp = t_1;
	elseif (im <= 7.2e+280)
		tmp = t_3;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - im), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2e+238], t$95$0, If[LessEqual[im, -2e+167], t$95$3, If[LessEqual[im, -0.00098], t$95$1, If[LessEqual[im, 0.00115], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 3.8e+241], t$95$1, If[LessEqual[im, 7.2e+280], t$95$3, t$95$2]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666\\
t_1 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\
t_2 := t_0 - im\\
t_3 := t_2 \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\
\mathbf{if}\;im \leq -2 \cdot 10^{+238}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -2 \cdot 10^{+167}:\\
\;\;\;\;t_3\\

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

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

\mathbf{elif}\;im \leq 3.8 \cdot 10^{+241}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+280}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if im < -2.0000000000000001e238

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
    8. Taylor expanded in im around inf 92.3%

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

    if -2.0000000000000001e238 < im < -2.0000000000000001e167 or 3.79999999999999972e241 < im < 7.1999999999999999e280

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.0000000000000001e167 < im < -9.7999999999999997e-4 or 0.00115 < im < 3.79999999999999972e241

    1. Initial program 99.8%

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

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

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

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

    if -9.7999999999999997e-4 < im < 0.00115

    1. Initial program 7.7%

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

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

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

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

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

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

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

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

    if 7.1999999999999999e280 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2 \cdot 10^{+238}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666\\ \mathbf{elif}\;im \leq -2 \cdot 10^{+167}:\\ \;\;\;\;\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{elif}\;im \leq -0.00098:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 0.00115:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 3.8 \cdot 10^{+241}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+280}:\\ \;\;\;\;\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \end{array} \]

Alternative 5: 74.5% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;re \leq 12:\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984 - im\\

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


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

    1. Initial program 51.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{3} \cdot -0.16666666666666666 + {im}^{7} \cdot -0.0001984126984126984\right)\right)} \]
    7. Taylor expanded in re around 0 72.1%

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im} \]
    8. Taylor expanded in im around inf 71.5%

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

    if 12 < re

    1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 12:\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984 - im\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 6: 81.7% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{3} \cdot -0.16666666666666666\\ t_1 := {im}^{7} \cdot -0.0001984126984126984 - im\\ t_2 := t_0 - im\\ t_3 := t_2 \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{if}\;im \leq -5 \cdot 10^{+237}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -6 \cdot 10^{+165}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;im \leq -1.1 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 15000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 3.5 \cdot 10^{+241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+280}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (pow im 3.0) -0.16666666666666666))
        (t_1 (- (* (pow im 7.0) -0.0001984126984126984) im))
        (t_2 (- t_0 im))
        (t_3 (* t_2 (+ (* -0.5 (* re re)) 1.0))))
   (if (<= im -5e+237)
     t_0
     (if (<= im -6e+165)
       t_3
       (if (<= im -1.1e+37)
         t_1
         (if (<= im 15000.0)
           (* (cos re) (- im))
           (if (<= im 3.5e+241) t_1 (if (<= im 8.2e+280) t_3 t_2))))))))
double code(double re, double im) {
	double t_0 = pow(im, 3.0) * -0.16666666666666666;
	double t_1 = (pow(im, 7.0) * -0.0001984126984126984) - im;
	double t_2 = t_0 - im;
	double t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	double tmp;
	if (im <= -5e+237) {
		tmp = t_0;
	} else if (im <= -6e+165) {
		tmp = t_3;
	} else if (im <= -1.1e+37) {
		tmp = t_1;
	} else if (im <= 15000.0) {
		tmp = cos(re) * -im;
	} else if (im <= 3.5e+241) {
		tmp = t_1;
	} else if (im <= 8.2e+280) {
		tmp = t_3;
	} else {
		tmp = t_2;
	}
	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) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (im ** 3.0d0) * (-0.16666666666666666d0)
    t_1 = ((im ** 7.0d0) * (-0.0001984126984126984d0)) - im
    t_2 = t_0 - im
    t_3 = t_2 * (((-0.5d0) * (re * re)) + 1.0d0)
    if (im <= (-5d+237)) then
        tmp = t_0
    else if (im <= (-6d+165)) then
        tmp = t_3
    else if (im <= (-1.1d+37)) then
        tmp = t_1
    else if (im <= 15000.0d0) then
        tmp = cos(re) * -im
    else if (im <= 3.5d+241) then
        tmp = t_1
    else if (im <= 8.2d+280) then
        tmp = t_3
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.pow(im, 3.0) * -0.16666666666666666;
	double t_1 = (Math.pow(im, 7.0) * -0.0001984126984126984) - im;
	double t_2 = t_0 - im;
	double t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	double tmp;
	if (im <= -5e+237) {
		tmp = t_0;
	} else if (im <= -6e+165) {
		tmp = t_3;
	} else if (im <= -1.1e+37) {
		tmp = t_1;
	} else if (im <= 15000.0) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 3.5e+241) {
		tmp = t_1;
	} else if (im <= 8.2e+280) {
		tmp = t_3;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.pow(im, 3.0) * -0.16666666666666666
	t_1 = (math.pow(im, 7.0) * -0.0001984126984126984) - im
	t_2 = t_0 - im
	t_3 = t_2 * ((-0.5 * (re * re)) + 1.0)
	tmp = 0
	if im <= -5e+237:
		tmp = t_0
	elif im <= -6e+165:
		tmp = t_3
	elif im <= -1.1e+37:
		tmp = t_1
	elif im <= 15000.0:
		tmp = math.cos(re) * -im
	elif im <= 3.5e+241:
		tmp = t_1
	elif im <= 8.2e+280:
		tmp = t_3
	else:
		tmp = t_2
	return tmp
function code(re, im)
	t_0 = Float64((im ^ 3.0) * -0.16666666666666666)
	t_1 = Float64(Float64((im ^ 7.0) * -0.0001984126984126984) - im)
	t_2 = Float64(t_0 - im)
	t_3 = Float64(t_2 * Float64(Float64(-0.5 * Float64(re * re)) + 1.0))
	tmp = 0.0
	if (im <= -5e+237)
		tmp = t_0;
	elseif (im <= -6e+165)
		tmp = t_3;
	elseif (im <= -1.1e+37)
		tmp = t_1;
	elseif (im <= 15000.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 3.5e+241)
		tmp = t_1;
	elseif (im <= 8.2e+280)
		tmp = t_3;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (im ^ 3.0) * -0.16666666666666666;
	t_1 = ((im ^ 7.0) * -0.0001984126984126984) - im;
	t_2 = t_0 - im;
	t_3 = t_2 * ((-0.5 * (re * re)) + 1.0);
	tmp = 0.0;
	if (im <= -5e+237)
		tmp = t_0;
	elseif (im <= -6e+165)
		tmp = t_3;
	elseif (im <= -1.1e+37)
		tmp = t_1;
	elseif (im <= 15000.0)
		tmp = cos(re) * -im;
	elseif (im <= 3.5e+241)
		tmp = t_1;
	elseif (im <= 8.2e+280)
		tmp = t_3;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision] - im), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - im), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5e+237], t$95$0, If[LessEqual[im, -6e+165], t$95$3, If[LessEqual[im, -1.1e+37], t$95$1, If[LessEqual[im, 15000.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 3.5e+241], t$95$1, If[LessEqual[im, 8.2e+280], t$95$3, t$95$2]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666\\
t_1 := {im}^{7} \cdot -0.0001984126984126984 - im\\
t_2 := t_0 - im\\
t_3 := t_2 \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\
\mathbf{if}\;im \leq -5 \cdot 10^{+237}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq -6 \cdot 10^{+165}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;im \leq -1.1 \cdot 10^{+37}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;im \leq 3.5 \cdot 10^{+241}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 8.2 \cdot 10^{+280}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if im < -5.0000000000000002e237

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
    8. Taylor expanded in im around inf 92.3%

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

    if -5.0000000000000002e237 < im < -5.99999999999999981e165 or 3.5e241 < im < 8.19999999999999995e280

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.99999999999999981e165 < im < -1.1e37 or 15000 < im < 3.5e241

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{3} \cdot -0.16666666666666666 + {im}^{7} \cdot -0.0001984126984126984\right)\right)} \]
    7. Taylor expanded in re around 0 76.2%

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im} \]
    8. Taylor expanded in im around inf 76.2%

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

    if -1.1e37 < im < 15000

    1. Initial program 12.0%

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

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

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

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

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

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

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

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

    if 8.19999999999999995e280 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification88.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5 \cdot 10^{+237}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666\\ \mathbf{elif}\;im \leq -6 \cdot 10^{+165}:\\ \;\;\;\;\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{elif}\;im \leq -1.1 \cdot 10^{+37}:\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984 - im\\ \mathbf{elif}\;im \leq 15000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 3.5 \cdot 10^{+241}:\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984 - im\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+280}:\\ \;\;\;\;\left({im}^{3} \cdot -0.16666666666666666 - im\right) \cdot \left(-0.5 \cdot \left(re \cdot re\right) + 1\right)\\ \mathbf{else}:\\ \;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\ \end{array} \]

Alternative 7: 75.2% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.00044 \lor \neg \left(im \leq 0.00062\right):\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666 - im\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -4.40000000000000016e-4 or 6.2e-4 < im

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

    if -4.40000000000000016e-4 < im < 6.2e-4

    1. Initial program 7.7%

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

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

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

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

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

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

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

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

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

Alternative 8: 81.9% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.1e37 or 7.0999999999999996 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(\mathsf{fma}\left({im}^{5}, -0.008333333333333333, -im\right) + \left({im}^{3} \cdot -0.16666666666666666 + {im}^{7} \cdot -0.0001984126984126984\right)\right)} \]
    7. Taylor expanded in re around 0 70.2%

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im} \]
    8. Taylor expanded in im around inf 70.2%

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

    if -1.1e37 < im < 7.0999999999999996

    1. Initial program 12.0%

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

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

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

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

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

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

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

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

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

Alternative 9: 53.4% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -2.5 \lor \neg \left(im \leq 2.5\right):\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\

\mathbf{else}:\\
\;\;\;\;-im\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
    8. Taylor expanded in im around inf 59.6%

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

    if -2.5 < im < 2.5

    1. Initial program 8.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-im} \]
    12. Simplified55.6%

      \[\leadsto \color{blue}{-im} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification57.4%

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

Alternative 10: 75.2% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.15 \cdot 10^{+37} \lor \neg \left(im \leq 15000\right):\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.15000000000000001e37 or 15000 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {im}^{3} - im} \]
    8. Taylor expanded in im around inf 62.2%

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

    if -1.15000000000000001e37 < im < 15000

    1. Initial program 12.0%

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

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

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

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

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

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

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

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

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

Alternative 11: 35.6% accurate, 20.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 + re \cdot \left(re \cdot -0.25\right)\\ \mathbf{if}\;re \leq 1.95 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{elif}\;re \leq 5.5 \cdot 10^{+257} \lor \neg \left(re \leq 4.3 \cdot 10^{+287}\right):\\ \;\;\;\;-3 \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot 27\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (+ 0.5 (* re (* re -0.25)))))
   (if (<= re 1.95e+154)
     (- (* im (* 0.5 (* re re))) im)
     (if (or (<= re 5.5e+257) (not (<= re 4.3e+287)))
       (* -3.0 t_0)
       (* t_0 27.0)))))
double code(double re, double im) {
	double t_0 = 0.5 + (re * (re * -0.25));
	double tmp;
	if (re <= 1.95e+154) {
		tmp = (im * (0.5 * (re * re))) - im;
	} else if ((re <= 5.5e+257) || !(re <= 4.3e+287)) {
		tmp = -3.0 * t_0;
	} else {
		tmp = t_0 * 27.0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 0.5d0 + (re * (re * (-0.25d0)))
    if (re <= 1.95d+154) then
        tmp = (im * (0.5d0 * (re * re))) - im
    else if ((re <= 5.5d+257) .or. (.not. (re <= 4.3d+287))) then
        tmp = (-3.0d0) * t_0
    else
        tmp = t_0 * 27.0d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = 0.5 + (re * (re * -0.25));
	double tmp;
	if (re <= 1.95e+154) {
		tmp = (im * (0.5 * (re * re))) - im;
	} else if ((re <= 5.5e+257) || !(re <= 4.3e+287)) {
		tmp = -3.0 * t_0;
	} else {
		tmp = t_0 * 27.0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 + (re * (re * -0.25))
	tmp = 0
	if re <= 1.95e+154:
		tmp = (im * (0.5 * (re * re))) - im
	elif (re <= 5.5e+257) or not (re <= 4.3e+287):
		tmp = -3.0 * t_0
	else:
		tmp = t_0 * 27.0
	return tmp
function code(re, im)
	t_0 = Float64(0.5 + Float64(re * Float64(re * -0.25)))
	tmp = 0.0
	if (re <= 1.95e+154)
		tmp = Float64(Float64(im * Float64(0.5 * Float64(re * re))) - im);
	elseif ((re <= 5.5e+257) || !(re <= 4.3e+287))
		tmp = Float64(-3.0 * t_0);
	else
		tmp = Float64(t_0 * 27.0);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 + (re * (re * -0.25));
	tmp = 0.0;
	if (re <= 1.95e+154)
		tmp = (im * (0.5 * (re * re))) - im;
	elseif ((re <= 5.5e+257) || ~((re <= 4.3e+287)))
		tmp = -3.0 * t_0;
	else
		tmp = t_0 * 27.0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, 1.95e+154], N[(N[(im * N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision], If[Or[LessEqual[re, 5.5e+257], N[Not[LessEqual[re, 4.3e+287]], $MachinePrecision]], N[(-3.0 * t$95$0), $MachinePrecision], N[(t$95$0 * 27.0), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 + re \cdot \left(re \cdot -0.25\right)\\
\mathbf{if}\;re \leq 1.95 \cdot 10^{+154}:\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\

\mathbf{elif}\;re \leq 5.5 \cdot 10^{+257} \lor \neg \left(re \leq 4.3 \cdot 10^{+287}\right):\\
\;\;\;\;-3 \cdot t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if re < 1.9500000000000001e154

    1. Initial program 49.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9500000000000001e154 < re < 5.49999999999999957e257 or 4.3e287 < re

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.49999999999999957e257 < re < 4.3e287

    1. Initial program 54.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 1.95 \cdot 10^{+154}:\\ \;\;\;\;im \cdot \left(0.5 \cdot \left(re \cdot re\right)\right) - im\\ \mathbf{elif}\;re \leq 5.5 \cdot 10^{+257} \lor \neg \left(re \leq 4.3 \cdot 10^{+287}\right):\\ \;\;\;\;-3 \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot 27\\ \end{array} \]

Alternative 12: 32.4% accurate, 23.5× speedup?

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

\\
\begin{array}{l}
t_0 := 0.5 + re \cdot \left(re \cdot -0.25\right)\\
\mathbf{if}\;im \leq -1.02 \cdot 10^{+42}:\\
\;\;\;\;-3 \cdot t_0\\

\mathbf{elif}\;im \leq 4.9 \cdot 10^{+179}:\\
\;\;\;\;-im\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.01999999999999996e42 < im < 4.8999999999999999e179

    1. Initial program 23.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-im} \]
    12. Simplified47.2%

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

    if 4.8999999999999999e179 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.02 \cdot 10^{+42}:\\ \;\;\;\;-3 \cdot \left(0.5 + re \cdot \left(re \cdot -0.25\right)\right)\\ \mathbf{elif}\;im \leq 4.9 \cdot 10^{+179}:\\ \;\;\;\;-im\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 + re \cdot \left(re \cdot -0.25\right)\right) \cdot 27\\ \end{array} \]

Alternative 13: 31.8% accurate, 27.9× speedup?

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

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

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


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

    1. Initial program 49.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-im} \]
    12. Simplified35.3%

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

    if 1.89999999999999983e153 < re

    1. Initial program 45.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 29.3% accurate, 154.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-im} \]
  12. Simplified32.8%

    \[\leadsto \color{blue}{-im} \]
  13. Final simplification32.8%

    \[\leadsto -im \]

Developer target: 99.8% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

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

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