math.sin on complex, imaginary part

Percentage Accurate: 54.2% → 99.1%
Time: 8.3s
Alternatives: 13
Speedup: 2.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 54.2% 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.1% accurate, 0.7× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;e^{-im\_m} - e^{im\_m} \leq -2 \cdot 10^{+64}:\\ \;\;\;\;0.5 \cdot \left(\left(\left(1 - im\_m\right) - e^{im\_m}\right) \cdot \cos re\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= (- (exp (- im_m)) (exp im_m)) -2e+64)
    (* 0.5 (* (- (- 1.0 im_m) (exp im_m)) (cos re)))
    (* (cos re) (- im_m)))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if ((exp(-im_m) - exp(im_m)) <= -2e+64) {
		tmp = 0.5 * (((1.0 - im_m) - exp(im_m)) * cos(re));
	} else {
		tmp = cos(re) * -im_m;
	}
	return im_s * tmp;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if ((exp(-im_m) - exp(im_m)) <= (-2d+64)) then
        tmp = 0.5d0 * (((1.0d0 - im_m) - exp(im_m)) * cos(re))
    else
        tmp = cos(re) * -im_m
    end if
    code = im_s * tmp
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if ((Math.exp(-im_m) - Math.exp(im_m)) <= -2e+64) {
		tmp = 0.5 * (((1.0 - im_m) - Math.exp(im_m)) * Math.cos(re));
	} else {
		tmp = Math.cos(re) * -im_m;
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if (math.exp(-im_m) - math.exp(im_m)) <= -2e+64:
		tmp = 0.5 * (((1.0 - im_m) - math.exp(im_m)) * math.cos(re))
	else:
		tmp = math.cos(re) * -im_m
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (Float64(exp(Float64(-im_m)) - exp(im_m)) <= -2e+64)
		tmp = Float64(0.5 * Float64(Float64(Float64(1.0 - im_m) - exp(im_m)) * cos(re)));
	else
		tmp = Float64(cos(re) * Float64(-im_m));
	end
	return Float64(im_s * tmp)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp_2 = code(im_s, re, im_m)
	tmp = 0.0;
	if ((exp(-im_m) - exp(im_m)) <= -2e+64)
		tmp = 0.5 * (((1.0 - im_m) - exp(im_m)) * cos(re));
	else
		tmp = cos(re) * -im_m;
	end
	tmp_2 = im_s * tmp;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[N[(N[Exp[(-im$95$m)], $MachinePrecision] - N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision], -2e+64], N[(0.5 * N[(N[(N[(1.0 - im$95$m), $MachinePrecision] - N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;e^{-im\_m} - e^{im\_m} \leq -2 \cdot 10^{+64}:\\
\;\;\;\;0.5 \cdot \left(\left(\left(1 - im\_m\right) - e^{im\_m}\right) \cdot \cos re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)) < -2.00000000000000004e64

    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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

    if -2.00000000000000004e64 < (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))

    1. Initial program 39.4%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-039.4%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/39.4%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*39.4%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/39.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-039.4%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity39.4%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt65.5%

        \[\leadsto \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}} \]
      2. pow365.5%

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval65.5%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-165.5%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr65.5%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos re \cdot \left(-im\right)}\right)}^{3}} \]
    8. Step-by-step derivation
      1. rem-cube-cbrt66.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-im\right)} \]
      2. distribute-rgt-neg-out66.8%

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -2 \cdot 10^{+64}:\\ \;\;\;\;0.5 \cdot \left(\left(\left(1 - im\right) - e^{im}\right) \cdot \cos re\right)\\ \mathbf{else}:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 95.5% accurate, 2.5× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 2.7:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \mathbf{elif}\;im\_m \leq 3.1 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.16666666666666666 - 0.5\right) - 2\right)\right)\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= im_m 2.7)
    (* (cos re) (- im_m))
    (if (<= im_m 3.1e+102)
      (* 0.5 (- (- (expm1 im_m)) im_m))
      (*
       0.5
       (*
        (cos re)
        (* im_m (- (* im_m (- (* im_m -0.16666666666666666) 0.5)) 2.0))))))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 2.7) {
		tmp = cos(re) * -im_m;
	} else if (im_m <= 3.1e+102) {
		tmp = 0.5 * (-expm1(im_m) - im_m);
	} else {
		tmp = 0.5 * (cos(re) * (im_m * ((im_m * ((im_m * -0.16666666666666666) - 0.5)) - 2.0)));
	}
	return im_s * tmp;
}
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 2.7) {
		tmp = Math.cos(re) * -im_m;
	} else if (im_m <= 3.1e+102) {
		tmp = 0.5 * (-Math.expm1(im_m) - im_m);
	} else {
		tmp = 0.5 * (Math.cos(re) * (im_m * ((im_m * ((im_m * -0.16666666666666666) - 0.5)) - 2.0)));
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if im_m <= 2.7:
		tmp = math.cos(re) * -im_m
	elif im_m <= 3.1e+102:
		tmp = 0.5 * (-math.expm1(im_m) - im_m)
	else:
		tmp = 0.5 * (math.cos(re) * (im_m * ((im_m * ((im_m * -0.16666666666666666) - 0.5)) - 2.0)))
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (im_m <= 2.7)
		tmp = Float64(cos(re) * Float64(-im_m));
	elseif (im_m <= 3.1e+102)
		tmp = Float64(0.5 * Float64(Float64(-expm1(im_m)) - im_m));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * -0.16666666666666666) - 0.5)) - 2.0))));
	end
	return Float64(im_s * tmp)
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[im$95$m, 2.7], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision], If[LessEqual[im$95$m, 3.1e+102], N[(0.5 * N[((-N[(Exp[im$95$m] - 1), $MachinePrecision]) - im$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * -0.16666666666666666), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 2.7:\\
\;\;\;\;\cos re \cdot \left(-im\_m\right)\\

\mathbf{elif}\;im\_m \leq 3.1 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\

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


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

    1. Initial program 39.4%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-039.4%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/39.4%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*39.4%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/39.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-039.4%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity39.4%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt65.5%

        \[\leadsto \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}} \]
      2. pow365.5%

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval65.5%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-165.5%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr65.5%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos re \cdot \left(-im\right)}\right)}^{3}} \]
    8. Step-by-step derivation
      1. rem-cube-cbrt66.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-im\right)} \]
      2. distribute-rgt-neg-out66.8%

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.8%

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

    if 2.7000000000000002 < im < 3.09999999999999987e102

    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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+88.2%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-88.2%

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

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-88.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg88.2%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define88.2%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified88.2%

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

    if 3.09999999999999987e102 < 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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.7:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 3.1 \cdot 10^{+102}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot \left(im \cdot -0.16666666666666666 - 0.5\right) - 2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.1% accurate, 2.6× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 3.4:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \mathbf{elif}\;im\_m \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im\_m \cdot \left(im\_m \cdot -0.5 - 2\right)\right)\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= im_m 3.4)
    (* (cos re) (- im_m))
    (if (<= im_m 1.9e+154)
      (* 0.5 (- (- (expm1 im_m)) im_m))
      (* 0.5 (* (cos re) (* im_m (- (* im_m -0.5) 2.0))))))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 3.4) {
		tmp = cos(re) * -im_m;
	} else if (im_m <= 1.9e+154) {
		tmp = 0.5 * (-expm1(im_m) - im_m);
	} else {
		tmp = 0.5 * (cos(re) * (im_m * ((im_m * -0.5) - 2.0)));
	}
	return im_s * tmp;
}
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 3.4) {
		tmp = Math.cos(re) * -im_m;
	} else if (im_m <= 1.9e+154) {
		tmp = 0.5 * (-Math.expm1(im_m) - im_m);
	} else {
		tmp = 0.5 * (Math.cos(re) * (im_m * ((im_m * -0.5) - 2.0)));
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if im_m <= 3.4:
		tmp = math.cos(re) * -im_m
	elif im_m <= 1.9e+154:
		tmp = 0.5 * (-math.expm1(im_m) - im_m)
	else:
		tmp = 0.5 * (math.cos(re) * (im_m * ((im_m * -0.5) - 2.0)))
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (im_m <= 3.4)
		tmp = Float64(cos(re) * Float64(-im_m));
	elseif (im_m <= 1.9e+154)
		tmp = Float64(0.5 * Float64(Float64(-expm1(im_m)) - im_m));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im_m * Float64(Float64(im_m * -0.5) - 2.0))));
	end
	return Float64(im_s * tmp)
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[im$95$m, 3.4], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision], If[LessEqual[im$95$m, 1.9e+154], N[(0.5 * N[((-N[(Exp[im$95$m] - 1), $MachinePrecision]) - im$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im$95$m * N[(N[(im$95$m * -0.5), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 3.4:\\
\;\;\;\;\cos re \cdot \left(-im\_m\right)\\

\mathbf{elif}\;im\_m \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\

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


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

    1. Initial program 39.4%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-039.4%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/39.4%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*39.4%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/39.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-039.4%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity39.4%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt65.5%

        \[\leadsto \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}} \]
      2. pow365.5%

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval65.5%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-165.5%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr65.5%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos re \cdot \left(-im\right)}\right)}^{3}} \]
    8. Step-by-step derivation
      1. rem-cube-cbrt66.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-im\right)} \]
      2. distribute-rgt-neg-out66.8%

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.8%

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

    if 3.39999999999999991 < im < 1.8999999999999999e154

    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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+79.3%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-79.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub079.3%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-79.3%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg79.3%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define79.3%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified79.3%

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

    if 1.8999999999999999e154 < 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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 3.4:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(im \cdot -0.5 - 2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 59.0% accurate, 2.6× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;\cos re \leq -4 \cdot 10^{-310}:\\ \;\;\;\;im\_m\\ \mathbf{else}:\\ \;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= (cos re) -4e-310)
    im_m
    (*
     im_m
     (+
      (*
       im_m
       (-
        (* im_m (- (* im_m -0.020833333333333332) 0.08333333333333333))
        0.25))
      -1.0)))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (cos(re) <= -4e-310) {
		tmp = im_m;
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (cos(re) <= (-4d-310)) then
        tmp = im_m
    else
        tmp = im_m * ((im_m * ((im_m * ((im_m * (-0.020833333333333332d0)) - 0.08333333333333333d0)) - 0.25d0)) + (-1.0d0))
    end if
    code = im_s * tmp
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (Math.cos(re) <= -4e-310) {
		tmp = im_m;
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if math.cos(re) <= -4e-310:
		tmp = im_m
	else:
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0)
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (cos(re) <= -4e-310)
		tmp = im_m;
	else
		tmp = Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0));
	end
	return Float64(im_s * tmp)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp_2 = code(im_s, re, im_m)
	tmp = 0.0;
	if (cos(re) <= -4e-310)
		tmp = im_m;
	else
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	end
	tmp_2 = im_s * tmp;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[N[Cos[re], $MachinePrecision], -4e-310], im$95$m, N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * -0.020833333333333332), $MachinePrecision] - 0.08333333333333333), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;\cos re \leq -4 \cdot 10^{-310}:\\
\;\;\;\;im\_m\\

\mathbf{else}:\\
\;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 re) < -3.999999999999988e-310

    1. Initial program 53.8%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-053.8%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/53.8%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*53.8%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/53.8%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-053.8%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity53.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
      9. *-commutative53.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
      10. neg-sub053.8%

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

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot 1\right) \]
    7. Step-by-step derivation
      1. *-rgt-identity2.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(-2 \cdot im\right)} \]
      2. associate-*r*2.5%

        \[\leadsto \color{blue}{\left(0.5 \cdot -2\right) \cdot im} \]
      3. metadata-eval2.5%

        \[\leadsto \color{blue}{-1} \cdot im \]
      4. neg-mul-12.5%

        \[\leadsto \color{blue}{-im} \]
      5. neg-sub02.5%

        \[\leadsto \color{blue}{0 - im} \]
      6. sub-neg2.5%

        \[\leadsto \color{blue}{0 + \left(-im\right)} \]
      7. add-sqr-sqrt0.9%

        \[\leadsto 0 + \color{blue}{\sqrt{-im} \cdot \sqrt{-im}} \]
      8. sqrt-unprod20.9%

        \[\leadsto 0 + \color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \]
      9. sqr-neg20.9%

        \[\leadsto 0 + \sqrt{\color{blue}{im \cdot im}} \]
      10. sqrt-unprod6.9%

        \[\leadsto 0 + \color{blue}{\sqrt{im} \cdot \sqrt{im}} \]
      11. add-sqr-sqrt13.0%

        \[\leadsto 0 + \color{blue}{im} \]
    8. Applied egg-rr13.0%

      \[\leadsto \color{blue}{0 + im} \]
    9. Step-by-step derivation
      1. +-lft-identity13.0%

        \[\leadsto \color{blue}{im} \]
    10. Simplified13.0%

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

    if -3.999999999999988e-310 < (cos.f64 re)

    1. Initial program 56.4%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-056.4%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/56.4%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*56.4%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/56.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-056.4%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity56.4%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+31.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
      2. unsub-neg31.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) + \left(-e^{im}\right)\right)} \]
      3. +-commutative31.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-37.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub037.7%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-37.7%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg37.7%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define60.1%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified60.1%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
    11. Taylor expanded in im around 0 53.5%

      \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(im \cdot \left(-0.020833333333333332 \cdot im - 0.08333333333333333\right) - 0.25\right) - 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification43.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos re \leq -4 \cdot 10^{-310}:\\ \;\;\;\;im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(im \cdot \left(im \cdot \left(im \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 80.4% accurate, 2.7× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 82000000:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \mathbf{elif}\;im\_m \leq 2.2 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot \left(im\_m + \mathsf{expm1}\left(im\_m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= im_m 82000000.0)
    (* (cos re) (- im_m))
    (if (<= im_m 2.2e+77)
      (* 0.5 (+ im_m (expm1 im_m)))
      (*
       im_m
       (+
        (*
         im_m
         (-
          (* im_m (- (* im_m -0.020833333333333332) 0.08333333333333333))
          0.25))
        -1.0))))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 82000000.0) {
		tmp = cos(re) * -im_m;
	} else if (im_m <= 2.2e+77) {
		tmp = 0.5 * (im_m + expm1(im_m));
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 82000000.0) {
		tmp = Math.cos(re) * -im_m;
	} else if (im_m <= 2.2e+77) {
		tmp = 0.5 * (im_m + Math.expm1(im_m));
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if im_m <= 82000000.0:
		tmp = math.cos(re) * -im_m
	elif im_m <= 2.2e+77:
		tmp = 0.5 * (im_m + math.expm1(im_m))
	else:
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0)
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (im_m <= 82000000.0)
		tmp = Float64(cos(re) * Float64(-im_m));
	elseif (im_m <= 2.2e+77)
		tmp = Float64(0.5 * Float64(im_m + expm1(im_m)));
	else
		tmp = Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0));
	end
	return Float64(im_s * tmp)
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[im$95$m, 82000000.0], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision], If[LessEqual[im$95$m, 2.2e+77], N[(0.5 * N[(im$95$m + N[(Exp[im$95$m] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * -0.020833333333333332), $MachinePrecision] - 0.08333333333333333), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 82000000:\\
\;\;\;\;\cos re \cdot \left(-im\_m\right)\\

\mathbf{elif}\;im\_m \leq 2.2 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(im\_m + \mathsf{expm1}\left(im\_m\right)\right)\\

\mathbf{else}:\\
\;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 8.2e7

    1. Initial program 39.8%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-039.8%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/39.8%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*39.8%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/39.8%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-039.8%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity39.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
      9. *-commutative39.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
      10. neg-sub039.8%

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt65.2%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval65.2%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-165.2%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr65.2%

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-im\right)} \]
      2. distribute-rgt-neg-out66.5%

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.5%

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

    if 8.2e7 < im < 2.2e77

    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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+83.3%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-83.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub083.3%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-83.3%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg83.3%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define83.3%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified83.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
    11. Step-by-step derivation
      1. sub-neg83.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) + \left(-im\right)\right)} \]
      2. distribute-lft-in83.3%

        \[\leadsto \color{blue}{0.5 \cdot \left(-\mathsf{expm1}\left(im\right)\right) + 0.5 \cdot \left(-im\right)} \]
      3. add-sqr-sqrt0.0%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{-\mathsf{expm1}\left(im\right)} \cdot \sqrt{-\mathsf{expm1}\left(im\right)}\right)} + 0.5 \cdot \left(-im\right) \]
      4. sqrt-unprod16.7%

        \[\leadsto 0.5 \cdot \color{blue}{\sqrt{\left(-\mathsf{expm1}\left(im\right)\right) \cdot \left(-\mathsf{expm1}\left(im\right)\right)}} + 0.5 \cdot \left(-im\right) \]
      5. sqr-neg16.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{\mathsf{expm1}\left(im\right) \cdot \mathsf{expm1}\left(im\right)}} + 0.5 \cdot \left(-im\right) \]
      6. sqrt-unprod16.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{\mathsf{expm1}\left(im\right)} \cdot \sqrt{\mathsf{expm1}\left(im\right)}\right)} + 0.5 \cdot \left(-im\right) \]
      7. add-sqr-sqrt16.7%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{expm1}\left(im\right)} + 0.5 \cdot \left(-im\right) \]
      8. add-sqr-sqrt0.0%

        \[\leadsto 0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot \color{blue}{\left(\sqrt{-im} \cdot \sqrt{-im}\right)} \]
      9. sqrt-unprod16.7%

        \[\leadsto 0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot \color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \]
      10. sqr-neg16.7%

        \[\leadsto 0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot \sqrt{\color{blue}{im \cdot im}} \]
      11. sqrt-unprod16.7%

        \[\leadsto 0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot \color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \]
      12. add-sqr-sqrt16.7%

        \[\leadsto 0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot \color{blue}{im} \]
    12. Applied egg-rr16.7%

      \[\leadsto \color{blue}{0.5 \cdot \mathsf{expm1}\left(im\right) + 0.5 \cdot im} \]
    13. Step-by-step derivation
      1. distribute-lft-out16.7%

        \[\leadsto \color{blue}{0.5 \cdot \left(\mathsf{expm1}\left(im\right) + im\right)} \]
      2. +-commutative16.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(im + \mathsf{expm1}\left(im\right)\right)} \]
    14. Simplified16.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(im + \mathsf{expm1}\left(im\right)\right)} \]

    if 2.2e77 < 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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
      2. unsub-neg75.0%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) + \left(-e^{im}\right)\right)} \]
      3. +-commutative75.0%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-75.0%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub075.0%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-75.0%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg75.0%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define75.0%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified75.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
    11. Taylor expanded in im around 0 75.0%

      \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(im \cdot \left(-0.020833333333333332 \cdot im - 0.08333333333333333\right) - 0.25\right) - 1\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 82000000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 2.2 \cdot 10^{+77}:\\ \;\;\;\;0.5 \cdot \left(im + \mathsf{expm1}\left(im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(im \cdot \left(im \cdot \left(im \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 86.7% accurate, 2.8× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 5.1:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= im_m 5.1) (* (cos re) (- im_m)) (* 0.5 (- (- (expm1 im_m)) im_m)))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 5.1) {
		tmp = cos(re) * -im_m;
	} else {
		tmp = 0.5 * (-expm1(im_m) - im_m);
	}
	return im_s * tmp;
}
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 5.1) {
		tmp = Math.cos(re) * -im_m;
	} else {
		tmp = 0.5 * (-Math.expm1(im_m) - im_m);
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if im_m <= 5.1:
		tmp = math.cos(re) * -im_m
	else:
		tmp = 0.5 * (-math.expm1(im_m) - im_m)
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (im_m <= 5.1)
		tmp = Float64(cos(re) * Float64(-im_m));
	else
		tmp = Float64(0.5 * Float64(Float64(-expm1(im_m)) - im_m));
	end
	return Float64(im_s * tmp)
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[im$95$m, 5.1], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision], N[(0.5 * N[((-N[(Exp[im$95$m] - 1), $MachinePrecision]) - im$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 5.1:\\
\;\;\;\;\cos re \cdot \left(-im\_m\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\_m\right)\right) - im\_m\right)\\


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

    1. Initial program 39.4%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-039.4%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/39.4%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*39.4%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/39.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-039.4%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity39.4%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt65.5%

        \[\leadsto \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}} \]
      2. pow365.5%

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval65.5%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-165.5%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr65.5%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos re \cdot \left(-im\right)}\right)}^{3}} \]
    8. Step-by-step derivation
      1. rem-cube-cbrt66.8%

        \[\leadsto \color{blue}{\cos re \cdot \left(-im\right)} \]
      2. distribute-rgt-neg-out66.8%

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.8%

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

    if 5.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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+76.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
      2. unsub-neg76.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) + \left(-e^{im}\right)\right)} \]
      3. +-commutative76.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-76.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub076.8%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-76.8%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg76.8%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define76.8%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified76.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 5.1:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.3% accurate, 2.8× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 30000000000000:\\ \;\;\;\;\cos re \cdot \left(-im\_m\right)\\ \mathbf{else}:\\ \;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (*
  im_s
  (if (<= im_m 30000000000000.0)
    (* (cos re) (- im_m))
    (*
     im_m
     (+
      (*
       im_m
       (-
        (* im_m (- (* im_m -0.020833333333333332) 0.08333333333333333))
        0.25))
      -1.0)))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 30000000000000.0) {
		tmp = cos(re) * -im_m;
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 30000000000000.0d0) then
        tmp = cos(re) * -im_m
    else
        tmp = im_m * ((im_m * ((im_m * ((im_m * (-0.020833333333333332d0)) - 0.08333333333333333d0)) - 0.25d0)) + (-1.0d0))
    end if
    code = im_s * tmp
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	double tmp;
	if (im_m <= 30000000000000.0) {
		tmp = Math.cos(re) * -im_m;
	} else {
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	}
	return im_s * tmp;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	tmp = 0
	if im_m <= 30000000000000.0:
		tmp = math.cos(re) * -im_m
	else:
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0)
	return im_s * tmp
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	tmp = 0.0
	if (im_m <= 30000000000000.0)
		tmp = Float64(cos(re) * Float64(-im_m));
	else
		tmp = Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0));
	end
	return Float64(im_s * tmp)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp_2 = code(im_s, re, im_m)
	tmp = 0.0;
	if (im_m <= 30000000000000.0)
		tmp = cos(re) * -im_m;
	else
		tmp = im_m * ((im_m * ((im_m * ((im_m * -0.020833333333333332) - 0.08333333333333333)) - 0.25)) + -1.0);
	end
	tmp_2 = im_s * tmp;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * If[LessEqual[im$95$m, 30000000000000.0], N[(N[Cos[re], $MachinePrecision] * (-im$95$m)), $MachinePrecision], N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * -0.020833333333333332), $MachinePrecision] - 0.08333333333333333), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 30000000000000:\\
\;\;\;\;\cos re \cdot \left(-im\_m\right)\\

\mathbf{else}:\\
\;\;\;\;im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\


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

    1. Initial program 40.1%

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

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-040.1%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/40.1%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*40.1%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/40.1%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-040.1%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity40.1%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
      9. *-commutative40.1%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
      10. neg-sub040.1%

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

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

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. add-cube-cbrt64.9%

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

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

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
      5. metadata-eval64.9%

        \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
      6. neg-mul-164.9%

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

        \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
    7. Applied egg-rr64.9%

      \[\leadsto \color{blue}{{\left(\sqrt[3]{\cos re \cdot \left(-im\right)}\right)}^{3}} \]
    8. Step-by-step derivation
      1. rem-cube-cbrt66.1%

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

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

        \[\leadsto \color{blue}{\left(-\cos re\right) \cdot im} \]
    9. Applied egg-rr66.1%

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

    if 3e13 < 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. /-rgt-identity100.0%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      2. exp-0100.0%

        \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
      3. associate-*l/100.0%

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

        \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
      5. associate-*l*100.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
      6. associate-*r/100.0%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      7. exp-0100.0%

        \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
      8. /-rgt-identity100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
    9. Step-by-step derivation
      1. associate--r+77.6%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
      2. unsub-neg77.6%

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
      4. associate-+r-77.6%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
      5. neg-sub077.6%

        \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
      6. associate-+l-77.6%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
      7. sub0-neg77.6%

        \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
      8. expm1-define77.6%

        \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
    10. Simplified77.6%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
    11. Taylor expanded in im around 0 63.4%

      \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(im \cdot \left(-0.020833333333333332 \cdot im - 0.08333333333333333\right) - 0.25\right) - 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 30000000000000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(im \cdot \left(im \cdot \left(im \cdot -0.020833333333333332 - 0.08333333333333333\right) - 0.25\right) + -1\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 53.0% accurate, 28.1× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.08333333333333333 - 0.25\right) + -1\right)\right) \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (* im_s (* im_m (+ (* im_m (- (* im_m -0.08333333333333333) 0.25)) -1.0))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * (im_m * ((im_m * ((im_m * -0.08333333333333333) - 0.25)) + -1.0));
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * (im_m * ((im_m * ((im_m * (-0.08333333333333333d0)) - 0.25d0)) + (-1.0d0)))
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * (im_m * ((im_m * ((im_m * -0.08333333333333333) - 0.25)) + -1.0));
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * (im_m * ((im_m * ((im_m * -0.08333333333333333) - 0.25)) + -1.0))
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * Float64(im_m * Float64(Float64(im_m * Float64(Float64(im_m * -0.08333333333333333) - 0.25)) + -1.0)))
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * (im_m * ((im_m * ((im_m * -0.08333333333333333) - 0.25)) + -1.0));
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * N[(im$95$m * N[(N[(im$95$m * N[(N[(im$95$m * -0.08333333333333333), $MachinePrecision] - 0.25), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \left(im\_m \cdot \left(im\_m \cdot \left(im\_m \cdot -0.08333333333333333 - 0.25\right) + -1\right)\right)
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

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

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

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

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

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

    \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
  9. Step-by-step derivation
    1. associate--r+24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
    2. unsub-neg24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) + \left(-e^{im}\right)\right)} \]
    3. +-commutative24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
    4. associate-+r-29.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
    5. neg-sub029.3%

      \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
    6. associate-+l-29.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
    7. sub0-neg29.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
    8. expm1-define46.3%

      \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
  10. Simplified46.3%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
  11. Taylor expanded in im around 0 50.9%

    \[\leadsto \color{blue}{im \cdot \left(im \cdot \left(-0.08333333333333333 \cdot im - 0.25\right) - 1\right)} \]
  12. Final simplification50.9%

    \[\leadsto im \cdot \left(im \cdot \left(im \cdot -0.08333333333333333 - 0.25\right) + -1\right) \]
  13. Add Preprocessing

Alternative 9: 46.9% accurate, 44.1× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \left(im\_m \cdot \left(im\_m \cdot -0.25 + -1\right)\right) \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m)
 :precision binary64
 (* im_s (* im_m (+ (* im_m -0.25) -1.0))))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * (im_m * ((im_m * -0.25) + -1.0));
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * (im_m * ((im_m * (-0.25d0)) + (-1.0d0)))
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * (im_m * ((im_m * -0.25) + -1.0));
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * (im_m * ((im_m * -0.25) + -1.0))
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * Float64(im_m * Float64(Float64(im_m * -0.25) + -1.0)))
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * (im_m * ((im_m * -0.25) + -1.0));
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * N[(im$95$m * N[(N[(im$95$m * -0.25), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \left(im\_m \cdot \left(im\_m \cdot -0.25 + -1\right)\right)
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

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

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

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

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

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

    \[\leadsto 0.5 \cdot \color{blue}{\left(1 - \left(im + e^{im}\right)\right)} \]
  9. Step-by-step derivation
    1. associate--r+24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) - e^{im}\right)} \]
    2. unsub-neg24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(1 - im\right) + \left(-e^{im}\right)\right)} \]
    3. +-commutative24.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-e^{im}\right) + \left(1 - im\right)\right)} \]
    4. associate-+r-29.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(\left(-e^{im}\right) + 1\right) - im\right)} \]
    5. neg-sub029.3%

      \[\leadsto 0.5 \cdot \left(\left(\color{blue}{\left(0 - e^{im}\right)} + 1\right) - im\right) \]
    6. associate-+l-29.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(0 - \left(e^{im} - 1\right)\right)} - im\right) \]
    7. sub0-neg29.3%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-\left(e^{im} - 1\right)\right)} - im\right) \]
    8. expm1-define46.3%

      \[\leadsto 0.5 \cdot \left(\left(-\color{blue}{\mathsf{expm1}\left(im\right)}\right) - im\right) \]
  10. Simplified46.3%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\left(-\mathsf{expm1}\left(im\right)\right) - im\right)} \]
  11. Taylor expanded in im around 0 39.1%

    \[\leadsto \color{blue}{im \cdot \left(-0.25 \cdot im - 1\right)} \]
  12. Final simplification39.1%

    \[\leadsto im \cdot \left(im \cdot -0.25 + -1\right) \]
  13. Add Preprocessing

Alternative 10: 29.6% accurate, 154.5× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot \left(-im\_m\right) \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m) :precision binary64 (* im_s (- im_m)))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * -im_m;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * -im_m
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * -im_m;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * -im_m
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * Float64(-im_m))
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * -im_m;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * (-im$95$m)), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot \left(-im\_m\right)
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

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

    \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
  6. Step-by-step derivation
    1. add-cube-cbrt49.4%

      \[\leadsto \color{blue}{\left(\sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)} \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}\right) \cdot \sqrt[3]{0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)}} \]
    2. pow349.4%

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

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

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)} \cdot \cos re}\right)}^{3} \]
    5. metadata-eval49.4%

      \[\leadsto {\left(\sqrt[3]{\left(\color{blue}{-1} \cdot im\right) \cdot \cos re}\right)}^{3} \]
    6. neg-mul-149.4%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\left(-im\right)} \cdot \cos re}\right)}^{3} \]
    7. *-commutative49.4%

      \[\leadsto {\left(\sqrt[3]{\color{blue}{\cos re \cdot \left(-im\right)}}\right)}^{3} \]
  7. Applied egg-rr49.4%

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

    \[\leadsto \color{blue}{im \cdot {\left(\sqrt[3]{-1}\right)}^{3}} \]
  9. Step-by-step derivation
    1. rem-cube-cbrt27.1%

      \[\leadsto im \cdot \color{blue}{-1} \]
    2. *-commutative27.1%

      \[\leadsto \color{blue}{-1 \cdot im} \]
    3. neg-mul-127.1%

      \[\leadsto \color{blue}{-im} \]
  10. Simplified27.1%

    \[\leadsto \color{blue}{-im} \]
  11. Add Preprocessing

Alternative 11: 5.0% accurate, 309.0× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot im\_m \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m) :precision binary64 (* im_s im_m))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * im_m;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * im_m
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * im_m;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * im_m
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * im_m)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * im_m;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * im$95$m), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot im\_m
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

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

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

    \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot 1\right) \]
  7. Step-by-step derivation
    1. *-rgt-identity27.1%

      \[\leadsto 0.5 \cdot \color{blue}{\left(-2 \cdot im\right)} \]
    2. associate-*r*27.1%

      \[\leadsto \color{blue}{\left(0.5 \cdot -2\right) \cdot im} \]
    3. metadata-eval27.1%

      \[\leadsto \color{blue}{-1} \cdot im \]
    4. neg-mul-127.1%

      \[\leadsto \color{blue}{-im} \]
    5. neg-sub027.1%

      \[\leadsto \color{blue}{0 - im} \]
    6. sub-neg27.1%

      \[\leadsto \color{blue}{0 + \left(-im\right)} \]
    7. add-sqr-sqrt14.6%

      \[\leadsto 0 + \color{blue}{\sqrt{-im} \cdot \sqrt{-im}} \]
    8. sqrt-unprod20.4%

      \[\leadsto 0 + \color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}} \]
    9. sqr-neg20.4%

      \[\leadsto 0 + \sqrt{\color{blue}{im \cdot im}} \]
    10. sqrt-unprod2.3%

      \[\leadsto 0 + \color{blue}{\sqrt{im} \cdot \sqrt{im}} \]
    11. add-sqr-sqrt4.6%

      \[\leadsto 0 + \color{blue}{im} \]
  8. Applied egg-rr4.6%

    \[\leadsto \color{blue}{0 + im} \]
  9. Step-by-step derivation
    1. +-lft-identity4.6%

      \[\leadsto \color{blue}{im} \]
  10. Simplified4.6%

    \[\leadsto \color{blue}{im} \]
  11. Add Preprocessing

Alternative 12: 3.5% accurate, 309.0× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot 0 \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m) :precision binary64 (* im_s 0.0))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * 0.0;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * 0.0d0
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * 0.0;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * 0.0
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * 0.0)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * 0.0;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * 0.0), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot 0
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

    \[\leadsto \color{blue}{0.5 \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \cos re\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr3.5%

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

    \[\leadsto \color{blue}{0} \]
  7. Add Preprocessing

Alternative 13: 3.6% accurate, 309.0× speedup?

\[\begin{array}{l} im\_m = \left|im\right| \\ im\_s = \mathsf{copysign}\left(1, im\right) \\ im\_s \cdot -1 \end{array} \]
im\_m = (fabs.f64 im)
im\_s = (copysign.f64 #s(literal 1 binary64) im)
(FPCore (im_s re im_m) :precision binary64 (* im_s -1.0))
im\_m = fabs(im);
im\_s = copysign(1.0, im);
double code(double im_s, double re, double im_m) {
	return im_s * -1.0;
}
im\_m = abs(im)
im\_s = copysign(1.0d0, im)
real(8) function code(im_s, re, im_m)
    real(8), intent (in) :: im_s
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = im_s * (-1.0d0)
end function
im\_m = Math.abs(im);
im\_s = Math.copySign(1.0, im);
public static double code(double im_s, double re, double im_m) {
	return im_s * -1.0;
}
im\_m = math.fabs(im)
im\_s = math.copysign(1.0, im)
def code(im_s, re, im_m):
	return im_s * -1.0
im\_m = abs(im)
im\_s = copysign(1.0, im)
function code(im_s, re, im_m)
	return Float64(im_s * -1.0)
end
im\_m = abs(im);
im\_s = sign(im) * abs(1.0);
function tmp = code(im_s, re, im_m)
	tmp = im_s * -1.0;
end
im\_m = N[Abs[im], $MachinePrecision]
im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[im$95$s_, re_, im$95$m_] := N[(im$95$s * -1.0), $MachinePrecision]
\begin{array}{l}
im\_m = \left|im\right|
\\
im\_s = \mathsf{copysign}\left(1, im\right)

\\
im\_s \cdot -1
\end{array}
Derivation
  1. Initial program 55.8%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \cos re}{1}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    2. exp-055.8%

      \[\leadsto \frac{0.5 \cdot \cos re}{\color{blue}{e^{0}}} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. associate-*l/55.8%

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

      \[\leadsto \frac{\left(0.5 \cdot \color{blue}{\cos \left(-re\right)}\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}} \]
    5. associate-*l*55.8%

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)}}{e^{0}} \]
    6. associate-*r/55.8%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
    7. exp-055.8%

      \[\leadsto 0.5 \cdot \frac{\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{\color{blue}{1}} \]
    8. /-rgt-identity55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos \left(-re\right) \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]
    9. *-commutative55.8%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\left(e^{0 - im} - e^{im}\right) \cdot \cos \left(-re\right)\right)} \]
    10. neg-sub055.8%

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

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

    \[\leadsto \color{blue}{0.5 \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \cos re\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr2.8%

    \[\leadsto 0.5 \cdot \left(\color{blue}{-2} \cdot \cos re\right) \]
  6. Taylor expanded in re around 0 2.8%

    \[\leadsto \color{blue}{-1} \]
  7. Add Preprocessing

Developer target: 99.8% accurate, 0.7× 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 2024111 
(FPCore (re im)
  :name "math.sin on complex, imaginary part"
  :precision binary64

  :alt
  (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))))