math.sin on complex, imaginary part

Percentage Accurate: 54.6% → 99.0%
Time: 10.7s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 54.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* 0.5 (log1p (expm1 (* (cos re) (* im -2.0))))))
double code(double re, double im) {
	return 0.5 * log1p(expm1((cos(re) * (im * -2.0))));
}
public static double code(double re, double im) {
	return 0.5 * Math.log1p(Math.expm1((Math.cos(re) * (im * -2.0))));
}
def code(re, im):
	return 0.5 * math.log1p(math.expm1((math.cos(re) * (im * -2.0))))
function code(re, im)
	return Float64(0.5 * log1p(expm1(Float64(cos(re) * Float64(im * -2.0)))))
end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)
\end{array}
Derivation
  1. Initial program 57.6%

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

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

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

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

      \[\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*57.6%

      \[\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/57.6%

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

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

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

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

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

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

    \[\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 49.2%

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

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
    2. *-commutative98.5%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
    3. *-commutative98.5%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
  7. Applied egg-rr98.5%

    \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
  8. Add Preprocessing

Alternative 2: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(-im\right)\right)\right) \end{array} \]
(FPCore (re im) :precision binary64 (log1p (expm1 (* (cos re) (- im)))))
double code(double re, double im) {
	return log1p(expm1((cos(re) * -im)));
}
public static double code(double re, double im) {
	return Math.log1p(Math.expm1((Math.cos(re) * -im)));
}
def code(re, im):
	return math.log1p(math.expm1((math.cos(re) * -im)))
function code(re, im)
	return log1p(expm1(Float64(cos(re) * Float64(-im))))
end
code[re_, im_] := N[Log[1 + N[(Exp[N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

      \[\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*57.6%

      \[\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/57.6%

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

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

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

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

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

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

    \[\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 49.2%

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)\right)} \]
    2. associate-*r*98.5%

      \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\left(0.5 \cdot \left(-2 \cdot im\right)\right) \cdot \cos re}\right)\right) \]
    3. *-commutative98.5%

      \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(0.5 \cdot \left(-2 \cdot im\right)\right)}\right)\right) \]
    4. associate-*r*98.5%

      \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(\left(0.5 \cdot -2\right) \cdot im\right)}\right)\right) \]
    5. metadata-eval98.5%

      \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(\color{blue}{-1} \cdot im\right)\right)\right) \]
  7. Applied egg-rr98.5%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(-1 \cdot im\right)\right)\right)} \]
  8. Final simplification98.5%

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(-im\right)\right)\right) \]
  9. Add Preprocessing

Alternative 3: 90.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 490:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 490.0)
   (* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
   (if (<= im 2.6e+78)
     (* 0.5 (log1p (expm1 (* im -2.0))))
     (*
      0.5
      (* (cos re) (* im (- (* -0.0003968253968253968 (pow im 6.0)) 2.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 490.0) {
		tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (cos(re) * (im * ((-0.0003968253968253968 * pow(im, 6.0)) - 2.0)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= 490.0) {
		tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (Math.cos(re) * (im * ((-0.0003968253968253968 * Math.pow(im, 6.0)) - 2.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 490.0:
		tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0)))
	elif im <= 2.6e+78:
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	else:
		tmp = 0.5 * (math.cos(re) * (im * ((-0.0003968253968253968 * math.pow(im, 6.0)) - 2.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 490.0)
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0))));
	elseif (im <= 2.6e+78)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.0003968253968253968 * (im ^ 6.0)) - 2.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 490.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.6e+78], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.0003968253968253968 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 490:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\

\mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\

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


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

    1. Initial program 38.6%

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

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

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

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

        \[\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*38.6%

        \[\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/38.6%

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

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

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

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

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

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

      \[\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 87.5%

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

    if 490 < im < 2.6e78

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 84.6%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{e^{-2 \cdot im} - 1}\right) \]
    9. Step-by-step derivation
      1. expm1-define84.6%

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

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

    if 2.6e78 < 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(\color{blue}{\left(im \cdot \left({im}^{2} \cdot \left({im}^{2} \cdot \left(-0.0003968253968253968 \cdot {im}^{2} - 0.016666666666666666\right) - 0.3333333333333333\right) - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in im around inf 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 490:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 68.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 480:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 480.0)
   (* (cos re) (- im))
   (if (or (<= im 7.2e+202) (not (<= im 8.2e+215)))
     (* 0.5 (log1p (expm1 (* im -2.0))))
     (* im (+ -1.0 (* 0.5 (pow re 2.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 480.0) {
		tmp = cos(re) * -im;
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else {
		tmp = im * (-1.0 + (0.5 * pow(re, 2.0)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= 480.0) {
		tmp = Math.cos(re) * -im;
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else {
		tmp = im * (-1.0 + (0.5 * Math.pow(re, 2.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 480.0:
		tmp = math.cos(re) * -im
	elif (im <= 7.2e+202) or not (im <= 8.2e+215):
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	else:
		tmp = im * (-1.0 + (0.5 * math.pow(re, 2.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 480.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif ((im <= 7.2e+202) || !(im <= 8.2e+215))
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	else
		tmp = Float64(im * Float64(-1.0 + Float64(0.5 * (re ^ 2.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 480.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[Or[LessEqual[im, 7.2e+202], N[Not[LessEqual[im, 8.2e+215]], $MachinePrecision]], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(-1.0 + N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\


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

    1. Initial program 38.6%

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

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

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

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

        \[\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*38.6%

        \[\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/38.6%

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

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

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

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

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

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

      \[\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 68.4%

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.4%

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

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

    if 480 < im < 7.20000000000000016e202 or 8.2000000000000007e215 < 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 6.1%

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 78.7%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{e^{-2 \cdot im} - 1}\right) \]
    9. Step-by-step derivation
      1. expm1-define78.7%

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

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

    if 7.20000000000000016e202 < im < 8.2000000000000007e215

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 480:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 90.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 430:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 430.0)
   (* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
   (if (<= im 2.6e+78)
     (* 0.5 (log1p (expm1 (* im -2.0))))
     (* 0.5 (* (cos re) (* -0.0003968253968253968 (pow im 7.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 430.0) {
		tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (cos(re) * (-0.0003968253968253968 * pow(im, 7.0)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= 430.0) {
		tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (Math.cos(re) * (-0.0003968253968253968 * Math.pow(im, 7.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 430.0:
		tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0)))
	elif im <= 2.6e+78:
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	else:
		tmp = 0.5 * (math.cos(re) * (-0.0003968253968253968 * math.pow(im, 7.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 430.0)
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0))));
	elseif (im <= 2.6e+78)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(-0.0003968253968253968 * (im ^ 7.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 430.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.6e+78], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-0.0003968253968253968 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 430:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\

\mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\

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


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

    1. Initial program 38.6%

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

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

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

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

        \[\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*38.6%

        \[\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/38.6%

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

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

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

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

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

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

      \[\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 87.5%

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

    if 430 < im < 2.6e78

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 84.6%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{e^{-2 \cdot im} - 1}\right) \]
    9. Step-by-step derivation
      1. expm1-define84.6%

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

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

    if 2.6e78 < 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(\color{blue}{\left(im \cdot \left({im}^{2} \cdot \left({im}^{2} \cdot \left(-0.0003968253968253968 \cdot {im}^{2} - 0.016666666666666666\right) - 0.3333333333333333\right) - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in im around inf 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 430:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 73.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 450:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 450.0)
   (* (cos re) (- im))
   (if (<= im 2.6e+78)
     (* 0.5 (log1p (expm1 (* im -2.0))))
     (* 0.5 (* (cos re) (* -0.0003968253968253968 (pow im 7.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 450.0) {
		tmp = cos(re) * -im;
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (cos(re) * (-0.0003968253968253968 * pow(im, 7.0)));
	}
	return tmp;
}
public static double code(double re, double im) {
	double tmp;
	if (im <= 450.0) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 2.6e+78) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else {
		tmp = 0.5 * (Math.cos(re) * (-0.0003968253968253968 * Math.pow(im, 7.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 450.0:
		tmp = math.cos(re) * -im
	elif im <= 2.6e+78:
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	else:
		tmp = 0.5 * (math.cos(re) * (-0.0003968253968253968 * math.pow(im, 7.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 450.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 2.6e+78)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	else
		tmp = Float64(0.5 * Float64(cos(re) * Float64(-0.0003968253968253968 * (im ^ 7.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 450.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 2.6e+78], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-0.0003968253968253968 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 2.6 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\

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


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

    1. Initial program 38.6%

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

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

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

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

        \[\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*38.6%

        \[\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/38.6%

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

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

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

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

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

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

      \[\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 68.4%

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.4%

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

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

    if 450 < im < 2.6e78

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 84.6%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{e^{-2 \cdot im} - 1}\right) \]
    9. Step-by-step derivation
      1. expm1-define84.6%

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

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

    if 2.6e78 < 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(\color{blue}{\left(im \cdot \left({im}^{2} \cdot \left({im}^{2} \cdot \left(-0.0003968253968253968 \cdot {im}^{2} - 0.016666666666666666\right) - 0.3333333333333333\right) - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in im around inf 100.0%

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

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

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

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

Alternative 7: 66.6% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+24}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 42000.0)
   (* (cos re) (- im))
   (if (<= im 7.2e+24)
     (* 0.5 (* im (* -0.08333333333333333 (pow re 4.0))))
     (if (or (<= im 7.2e+202) (not (<= im 8.2e+215)))
       (* 0.5 (* im (- (* -0.0003968253968253968 (pow im 6.0)) 2.0)))
       (* im (+ -1.0 (* 0.5 (pow re 2.0))))))))
double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = cos(re) * -im;
	} else if (im <= 7.2e+24) {
		tmp = 0.5 * (im * (-0.08333333333333333 * pow(re, 4.0)));
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * (im * ((-0.0003968253968253968 * pow(im, 6.0)) - 2.0));
	} else {
		tmp = im * (-1.0 + (0.5 * pow(re, 2.0)));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 42000.0d0) then
        tmp = cos(re) * -im
    else if (im <= 7.2d+24) then
        tmp = 0.5d0 * (im * ((-0.08333333333333333d0) * (re ** 4.0d0)))
    else if ((im <= 7.2d+202) .or. (.not. (im <= 8.2d+215))) then
        tmp = 0.5d0 * (im * (((-0.0003968253968253968d0) * (im ** 6.0d0)) - 2.0d0))
    else
        tmp = im * ((-1.0d0) + (0.5d0 * (re ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 7.2e+24) {
		tmp = 0.5 * (im * (-0.08333333333333333 * Math.pow(re, 4.0)));
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * (im * ((-0.0003968253968253968 * Math.pow(im, 6.0)) - 2.0));
	} else {
		tmp = im * (-1.0 + (0.5 * Math.pow(re, 2.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 42000.0:
		tmp = math.cos(re) * -im
	elif im <= 7.2e+24:
		tmp = 0.5 * (im * (-0.08333333333333333 * math.pow(re, 4.0)))
	elif (im <= 7.2e+202) or not (im <= 8.2e+215):
		tmp = 0.5 * (im * ((-0.0003968253968253968 * math.pow(im, 6.0)) - 2.0))
	else:
		tmp = im * (-1.0 + (0.5 * math.pow(re, 2.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 42000.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 7.2e+24)
		tmp = Float64(0.5 * Float64(im * Float64(-0.08333333333333333 * (re ^ 4.0))));
	elseif ((im <= 7.2e+202) || !(im <= 8.2e+215))
		tmp = Float64(0.5 * Float64(im * Float64(Float64(-0.0003968253968253968 * (im ^ 6.0)) - 2.0)));
	else
		tmp = Float64(im * Float64(-1.0 + Float64(0.5 * (re ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 42000.0)
		tmp = cos(re) * -im;
	elseif (im <= 7.2e+24)
		tmp = 0.5 * (im * (-0.08333333333333333 * (re ^ 4.0)));
	elseif ((im <= 7.2e+202) || ~((im <= 8.2e+215)))
		tmp = 0.5 * (im * ((-0.0003968253968253968 * (im ^ 6.0)) - 2.0));
	else
		tmp = im * (-1.0 + (0.5 * (re ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 42000.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 7.2e+24], N[(0.5 * N[(im * N[(-0.08333333333333333 * N[Power[re, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 7.2e+202], N[Not[LessEqual[im, 8.2e+215]], $MachinePrecision]], N[(0.5 * N[(im * N[(N[(-0.0003968253968253968 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(-1.0 + N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+24}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\


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

    1. Initial program 39.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg39.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*39.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/39.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.0%

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

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

    if 42000 < im < 7.19999999999999966e24

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(im \cdot -2 + im \cdot {re}^{2}\right) + \left(-0.08333333333333333 \cdot \left(im \cdot {re}^{2}\right)\right) \cdot {re}^{2}\right)} \]
      4. distribute-lft-out23.3%

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 + {re}^{2}\right) + \left(im \cdot -0.08333333333333333\right) \cdot \color{blue}{{re}^{\left(2 \cdot 2\right)}}\right) \]
      9. metadata-eval23.3%

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 + {re}^{2}\right) + \left(im \cdot -0.08333333333333333\right) \cdot {re}^{4}\right)} \]
    9. Taylor expanded in re around inf 45.0%

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

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

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

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

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

    if 7.19999999999999966e24 < im < 7.20000000000000016e202 or 8.2000000000000007e215 < 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 89.8%

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

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

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

    if 7.20000000000000016e202 < im < 8.2000000000000007e215

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+24}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 63.9% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 42000.0)
   (* (cos re) (- im))
   (if (<= im 8.6e+106)
     (* 0.5 (* im (* -0.08333333333333333 (pow re 4.0))))
     (if (or (<= im 7.2e+202) (not (<= im 8.2e+215)))
       (* 0.5 (* -0.3333333333333333 (pow im 3.0)))
       (* im (+ -1.0 (* 0.5 (pow re 2.0))))))))
double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = cos(re) * -im;
	} else if (im <= 8.6e+106) {
		tmp = 0.5 * (im * (-0.08333333333333333 * pow(re, 4.0)));
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
	} else {
		tmp = im * (-1.0 + (0.5 * pow(re, 2.0)));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 42000.0d0) then
        tmp = cos(re) * -im
    else if (im <= 8.6d+106) then
        tmp = 0.5d0 * (im * ((-0.08333333333333333d0) * (re ** 4.0d0)))
    else if ((im <= 7.2d+202) .or. (.not. (im <= 8.2d+215))) then
        tmp = 0.5d0 * ((-0.3333333333333333d0) * (im ** 3.0d0))
    else
        tmp = im * ((-1.0d0) + (0.5d0 * (re ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 8.6e+106) {
		tmp = 0.5 * (im * (-0.08333333333333333 * Math.pow(re, 4.0)));
	} else if ((im <= 7.2e+202) || !(im <= 8.2e+215)) {
		tmp = 0.5 * (-0.3333333333333333 * Math.pow(im, 3.0));
	} else {
		tmp = im * (-1.0 + (0.5 * Math.pow(re, 2.0)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 42000.0:
		tmp = math.cos(re) * -im
	elif im <= 8.6e+106:
		tmp = 0.5 * (im * (-0.08333333333333333 * math.pow(re, 4.0)))
	elif (im <= 7.2e+202) or not (im <= 8.2e+215):
		tmp = 0.5 * (-0.3333333333333333 * math.pow(im, 3.0))
	else:
		tmp = im * (-1.0 + (0.5 * math.pow(re, 2.0)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 42000.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 8.6e+106)
		tmp = Float64(0.5 * Float64(im * Float64(-0.08333333333333333 * (re ^ 4.0))));
	elseif ((im <= 7.2e+202) || !(im <= 8.2e+215))
		tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0)));
	else
		tmp = Float64(im * Float64(-1.0 + Float64(0.5 * (re ^ 2.0))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 42000.0)
		tmp = cos(re) * -im;
	elseif (im <= 8.6e+106)
		tmp = 0.5 * (im * (-0.08333333333333333 * (re ^ 4.0)));
	elseif ((im <= 7.2e+202) || ~((im <= 8.2e+215)))
		tmp = 0.5 * (-0.3333333333333333 * (im ^ 3.0));
	else
		tmp = im * (-1.0 + (0.5 * (re ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 42000.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 8.6e+106], N[(0.5 * N[(im * N[(-0.08333333333333333 * N[Power[re, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 7.2e+202], N[Not[LessEqual[im, 8.2e+215]], $MachinePrecision]], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(-1.0 + N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\
\;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\


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

    1. Initial program 39.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg39.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*39.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/39.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.0%

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

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

    if 42000 < im < 8.5999999999999999e106

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(im \cdot -2 + im \cdot {re}^{2}\right) + \left(-0.08333333333333333 \cdot \left(im \cdot {re}^{2}\right)\right) \cdot {re}^{2}\right)} \]
      4. distribute-lft-out8.8%

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 + {re}^{2}\right) + \left(im \cdot -0.08333333333333333\right) \cdot {re}^{4}\right)} \]
    9. Taylor expanded in re around inf 20.8%

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

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

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

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

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

    if 8.5999999999999999e106 < im < 7.20000000000000016e202 or 8.2000000000000007e215 < 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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 76.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 76.7%

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

    if 7.20000000000000016e202 < im < 8.2000000000000007e215

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 8.2 \cdot 10^{+215}\right):\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 63.9% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+202}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 42000.0)
   (* (cos re) (- im))
   (if (<= im 8.6e+106)
     (* 0.5 (* im (* -0.08333333333333333 (pow re 4.0))))
     (if (<= im 1.1e+202)
       (* 0.5 (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0)))
       (if (<= im 8.2e+215)
         (* im (+ -1.0 (* 0.5 (pow re 2.0))))
         (* 0.5 (* -0.3333333333333333 (pow im 3.0))))))))
double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = cos(re) * -im;
	} else if (im <= 8.6e+106) {
		tmp = 0.5 * (im * (-0.08333333333333333 * pow(re, 4.0)));
	} else if (im <= 1.1e+202) {
		tmp = 0.5 * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0));
	} else if (im <= 8.2e+215) {
		tmp = im * (-1.0 + (0.5 * pow(re, 2.0)));
	} else {
		tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 42000.0d0) then
        tmp = cos(re) * -im
    else if (im <= 8.6d+106) then
        tmp = 0.5d0 * (im * ((-0.08333333333333333d0) * (re ** 4.0d0)))
    else if (im <= 1.1d+202) then
        tmp = 0.5d0 * (im * (((-0.3333333333333333d0) * (im ** 2.0d0)) - 2.0d0))
    else if (im <= 8.2d+215) then
        tmp = im * ((-1.0d0) + (0.5d0 * (re ** 2.0d0)))
    else
        tmp = 0.5d0 * ((-0.3333333333333333d0) * (im ** 3.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = Math.cos(re) * -im;
	} else if (im <= 8.6e+106) {
		tmp = 0.5 * (im * (-0.08333333333333333 * Math.pow(re, 4.0)));
	} else if (im <= 1.1e+202) {
		tmp = 0.5 * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0));
	} else if (im <= 8.2e+215) {
		tmp = im * (-1.0 + (0.5 * Math.pow(re, 2.0)));
	} else {
		tmp = 0.5 * (-0.3333333333333333 * Math.pow(im, 3.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 42000.0:
		tmp = math.cos(re) * -im
	elif im <= 8.6e+106:
		tmp = 0.5 * (im * (-0.08333333333333333 * math.pow(re, 4.0)))
	elif im <= 1.1e+202:
		tmp = 0.5 * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))
	elif im <= 8.2e+215:
		tmp = im * (-1.0 + (0.5 * math.pow(re, 2.0)))
	else:
		tmp = 0.5 * (-0.3333333333333333 * math.pow(im, 3.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 42000.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 8.6e+106)
		tmp = Float64(0.5 * Float64(im * Float64(-0.08333333333333333 * (re ^ 4.0))));
	elseif (im <= 1.1e+202)
		tmp = Float64(0.5 * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)));
	elseif (im <= 8.2e+215)
		tmp = Float64(im * Float64(-1.0 + Float64(0.5 * (re ^ 2.0))));
	else
		tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 42000.0)
		tmp = cos(re) * -im;
	elseif (im <= 8.6e+106)
		tmp = 0.5 * (im * (-0.08333333333333333 * (re ^ 4.0)));
	elseif (im <= 1.1e+202)
		tmp = 0.5 * (im * ((-0.3333333333333333 * (im ^ 2.0)) - 2.0));
	elseif (im <= 8.2e+215)
		tmp = im * (-1.0 + (0.5 * (re ^ 2.0)));
	else
		tmp = 0.5 * (-0.3333333333333333 * (im ^ 3.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 42000.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 8.6e+106], N[(0.5 * N[(im * N[(-0.08333333333333333 * N[Power[re, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.1e+202], N[(0.5 * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.2e+215], N[(im * N[(-1.0 + N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\

\mathbf{elif}\;im \leq 1.1 \cdot 10^{+202}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\\

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

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


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

    1. Initial program 39.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg39.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*39.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/39.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.0%

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

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

    if 42000 < im < 8.5999999999999999e106

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(im \cdot -2 + im \cdot {re}^{2}\right) + \left(-0.08333333333333333 \cdot \left(im \cdot {re}^{2}\right)\right) \cdot {re}^{2}\right)} \]
      4. distribute-lft-out8.8%

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 + {re}^{2}\right) + \left(im \cdot -0.08333333333333333\right) \cdot {re}^{4}\right)} \]
    9. Taylor expanded in re around inf 20.8%

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

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

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

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

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

    if 8.5999999999999999e106 < im < 1.09999999999999989e202

    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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 75.0%

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

    if 1.09999999999999989e202 < im < 8.2000000000000007e215

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

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

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

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

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

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

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

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

    if 8.2000000000000007e215 < 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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 78.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 78.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+202}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\\ \mathbf{elif}\;im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;im \cdot \left(-1 + 0.5 \cdot {re}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 63.9% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 1.25 \cdot 10^{+216}\right):\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 42000.0)
   (* (cos re) (- im))
   (if (<= im 8.6e+106)
     (* 0.5 (* im (* -0.08333333333333333 (pow re 4.0))))
     (if (or (<= im 7.2e+202) (not (<= im 1.25e+216)))
       (* 0.5 (* -0.3333333333333333 (pow im 3.0)))
       (* 0.5 (* im (fma re re -2.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 42000.0) {
		tmp = cos(re) * -im;
	} else if (im <= 8.6e+106) {
		tmp = 0.5 * (im * (-0.08333333333333333 * pow(re, 4.0)));
	} else if ((im <= 7.2e+202) || !(im <= 1.25e+216)) {
		tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
	} else {
		tmp = 0.5 * (im * fma(re, re, -2.0));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 42000.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif (im <= 8.6e+106)
		tmp = Float64(0.5 * Float64(im * Float64(-0.08333333333333333 * (re ^ 4.0))));
	elseif ((im <= 7.2e+202) || !(im <= 1.25e+216))
		tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0)));
	else
		tmp = Float64(0.5 * Float64(im * fma(re, re, -2.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 42000.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[LessEqual[im, 8.6e+106], N[(0.5 * N[(im * N[(-0.08333333333333333 * N[Power[re, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 7.2e+202], N[Not[LessEqual[im, 1.25e+216]], $MachinePrecision]], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(re * re + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\

\mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 1.25 \cdot 10^{+216}\right):\\
\;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\


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

    1. Initial program 39.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg39.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*39.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/39.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.0%

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

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

    if 42000 < im < 8.5999999999999999e106

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

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

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(im \cdot -2 + im \cdot {re}^{2}\right) + \left(-0.08333333333333333 \cdot \left(im \cdot {re}^{2}\right)\right) \cdot {re}^{2}\right)} \]
      4. distribute-lft-out8.8%

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 + {re}^{2}\right) + \left(im \cdot -0.08333333333333333\right) \cdot {re}^{4}\right)} \]
    9. Taylor expanded in re around inf 20.8%

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

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

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

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

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

    if 8.5999999999999999e106 < im < 7.20000000000000016e202 or 1.24999999999999995e216 < 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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 76.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 76.7%

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

    if 7.20000000000000016e202 < im < 1.24999999999999995e216

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 53.0%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(re, re, -2\right)}\right) \]
    10. Simplified53.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 42000:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 8.6 \cdot 10^{+106}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(-0.08333333333333333 \cdot {re}^{4}\right)\right)\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{+202} \lor \neg \left(im \leq 1.25 \cdot 10^{+216}\right):\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 63.2% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 390:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 390.0)
   (* (cos re) (- im))
   (if (or (<= im 9e+97) (and (not (<= im 7.2e+202)) (<= im 8.2e+215)))
     (* 0.5 (* im (fma re re -2.0)))
     (* 0.5 (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 390.0) {
		tmp = cos(re) * -im;
	} else if ((im <= 9e+97) || (!(im <= 7.2e+202) && (im <= 8.2e+215))) {
		tmp = 0.5 * (im * fma(re, re, -2.0));
	} else {
		tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 390.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif ((im <= 9e+97) || (!(im <= 7.2e+202) && (im <= 8.2e+215)))
		tmp = Float64(0.5 * Float64(im * fma(re, re, -2.0)));
	else
		tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 390.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[Or[LessEqual[im, 9e+97], And[N[Not[LessEqual[im, 7.2e+202]], $MachinePrecision], LessEqual[im, 8.2e+215]]], N[(0.5 * N[(im * N[(re * re + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\

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


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

    1. Initial program 38.3%

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

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

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

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

        \[\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*38.3%

        \[\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/38.3%

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

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

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

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

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

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

      \[\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 68.7%

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.7%

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

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

    if 390 < im < 8.99999999999999952e97 or 7.20000000000000016e202 < im < 8.2000000000000007e215

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative97.4%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative97.4%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr97.4%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 18.8%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(re, re, -2\right)}\right) \]
    10. Simplified18.8%

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

    if 8.99999999999999952e97 < im < 7.20000000000000016e202 or 8.2000000000000007e215 < 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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 76.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 76.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 390:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 63.1% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2350:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2350.0)
   (* (cos re) (- im))
   (if (or (<= im 9e+97) (and (not (<= im 7.2e+202)) (<= im 8.2e+215)))
     (* 0.5 (* im (pow re 2.0)))
     (* 0.5 (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 2350.0) {
		tmp = cos(re) * -im;
	} else if ((im <= 9e+97) || (!(im <= 7.2e+202) && (im <= 8.2e+215))) {
		tmp = 0.5 * (im * pow(re, 2.0));
	} else {
		tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 2350.0d0) then
        tmp = cos(re) * -im
    else if ((im <= 9d+97) .or. (.not. (im <= 7.2d+202)) .and. (im <= 8.2d+215)) then
        tmp = 0.5d0 * (im * (re ** 2.0d0))
    else
        tmp = 0.5d0 * ((-0.3333333333333333d0) * (im ** 3.0d0))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 2350.0) {
		tmp = Math.cos(re) * -im;
	} else if ((im <= 9e+97) || (!(im <= 7.2e+202) && (im <= 8.2e+215))) {
		tmp = 0.5 * (im * Math.pow(re, 2.0));
	} else {
		tmp = 0.5 * (-0.3333333333333333 * Math.pow(im, 3.0));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 2350.0:
		tmp = math.cos(re) * -im
	elif (im <= 9e+97) or (not (im <= 7.2e+202) and (im <= 8.2e+215)):
		tmp = 0.5 * (im * math.pow(re, 2.0))
	else:
		tmp = 0.5 * (-0.3333333333333333 * math.pow(im, 3.0))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 2350.0)
		tmp = Float64(cos(re) * Float64(-im));
	elseif ((im <= 9e+97) || (!(im <= 7.2e+202) && (im <= 8.2e+215)))
		tmp = Float64(0.5 * Float64(im * (re ^ 2.0)));
	else
		tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 2350.0)
		tmp = cos(re) * -im;
	elseif ((im <= 9e+97) || (~((im <= 7.2e+202)) && (im <= 8.2e+215)))
		tmp = 0.5 * (im * (re ^ 2.0));
	else
		tmp = 0.5 * (-0.3333333333333333 * (im ^ 3.0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 2350.0], N[(N[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision], If[Or[LessEqual[im, 9e+97], And[N[Not[LessEqual[im, 7.2e+202]], $MachinePrecision], LessEqual[im, 8.2e+215]]], N[(0.5 * N[(im * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\

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


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

    1. Initial program 39.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg39.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*39.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/39.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg68.0%

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

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

    if 2350 < im < 8.99999999999999952e97 or 7.20000000000000016e202 < im < 8.2000000000000007e215

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

      \[\leadsto 0.5 \cdot \left(\color{blue}{\left(-2 \cdot im\right)} \cdot \cos re\right) \]
    6. Step-by-step derivation
      1. log1p-expm1-u100.0%

        \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\left(-2 \cdot im\right) \cdot \cos re\right)\right)} \]
      2. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\cos re \cdot \left(-2 \cdot im\right)}\right)\right) \]
      3. *-commutative100.0%

        \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \color{blue}{\left(im \cdot -2\right)}\right)\right) \]
    7. Applied egg-rr100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)} \]
    8. Taylor expanded in re around 0 19.6%

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(re, re, -2\right)}\right) \]
    10. Simplified19.6%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(re, re, -2\right)\right)} \]
    11. Taylor expanded in re around inf 18.3%

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

    if 8.99999999999999952e97 < im < 7.20000000000000016e202 or 8.2000000000000007e215 < 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(\color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \cdot \cos re\right) \]
    6. Taylor expanded in re around 0 76.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 76.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2350:\\ \;\;\;\;\cos re \cdot \left(-im\right)\\ \mathbf{elif}\;im \leq 9 \cdot 10^{+97} \lor \neg \left(im \leq 7.2 \cdot 10^{+202}\right) \land im \leq 8.2 \cdot 10^{+215}:\\ \;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 63.0% accurate, 2.8× speedup?

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

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

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


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

    1. Initial program 44.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg44.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*44.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/44.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      3. mul-1-neg62.7%

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

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

    if 3.1000000000000002e37 < 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 77.4%

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
    7. Taylor expanded in im around inf 56.2%

      \[\leadsto 0.5 \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{3}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 32.5% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos re \leq -2 \cdot 10^{-311}:\\ \;\;\;\;im\\ \mathbf{else}:\\ \;\;\;\;-im\\ \end{array} \end{array} \]
(FPCore (re im) :precision binary64 (if (<= (cos re) -2e-311) im (- im)))
double code(double re, double im) {
	double tmp;
	if (cos(re) <= -2e-311) {
		tmp = im;
	} else {
		tmp = -im;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (cos(re) <= (-2d-311)) then
        tmp = im
    else
        tmp = -im
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (Math.cos(re) <= -2e-311) {
		tmp = im;
	} else {
		tmp = -im;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.cos(re) <= -2e-311:
		tmp = im
	else:
		tmp = -im
	return tmp
function code(re, im)
	tmp = 0.0
	if (cos(re) <= -2e-311)
		tmp = im;
	else
		tmp = Float64(-im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (cos(re) <= -2e-311)
		tmp = im;
	else
		tmp = -im;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -2e-311], im, (-im)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -2 \cdot 10^{-311}:\\
\;\;\;\;im\\

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


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

    1. Initial program 55.2%

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

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

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

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

        \[\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.2%

        \[\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.2%

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

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

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

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

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

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

      \[\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 52.7%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
      2. add-sqr-sqrt27.0%

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

        \[\leadsto \cos re \cdot \color{blue}{\sqrt{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}} \]
      4. mul-1-neg30.1%

        \[\leadsto \cos re \cdot \sqrt{\color{blue}{\left(-im\right)} \cdot \left(-1 \cdot im\right)} \]
      5. mul-1-neg30.1%

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

        \[\leadsto \cos re \cdot \sqrt{\color{blue}{im \cdot im}} \]
      7. sqrt-unprod0.8%

        \[\leadsto \cos re \cdot \color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \]
      8. add-sqr-sqrt1.9%

        \[\leadsto \cos re \cdot \color{blue}{im} \]
    9. Applied egg-rr1.9%

      \[\leadsto \color{blue}{\cos re \cdot im} \]
    10. Taylor expanded in re around 0 13.9%

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

    if -1.9999999999999e-311 < (cos.f64 re)

    1. Initial program 58.4%

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

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

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

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)}{e^{0}}} \]
      4. cos-neg58.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*58.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/58.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot im} \]
    7. Step-by-step derivation
      1. mul-1-neg36.3%

        \[\leadsto \color{blue}{-im} \]
    8. Simplified36.3%

      \[\leadsto \color{blue}{-im} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 51.8% accurate, 3.0× speedup?

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

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

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

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

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

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

      \[\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*57.6%

      \[\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/57.6%

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

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

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

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

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

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

    \[\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 49.2%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]
    2. *-commutative48.9%

      \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
    3. mul-1-neg48.9%

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

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

Alternative 16: 5.0% accurate, 309.0× speedup?

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

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

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

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

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

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

      \[\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*57.6%

      \[\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/57.6%

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

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

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

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

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

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

    \[\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 49.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} \]
    2. add-sqr-sqrt28.3%

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

      \[\leadsto \cos re \cdot \color{blue}{\sqrt{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}} \]
    4. mul-1-neg26.1%

      \[\leadsto \cos re \cdot \sqrt{\color{blue}{\left(-im\right)} \cdot \left(-1 \cdot im\right)} \]
    5. mul-1-neg26.1%

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

      \[\leadsto \cos re \cdot \sqrt{\color{blue}{im \cdot im}} \]
    7. sqrt-unprod0.8%

      \[\leadsto \cos re \cdot \color{blue}{\left(\sqrt{im} \cdot \sqrt{im}\right)} \]
    8. add-sqr-sqrt1.9%

      \[\leadsto \cos re \cdot \color{blue}{im} \]
  9. Applied egg-rr1.9%

    \[\leadsto \color{blue}{\cos re \cdot im} \]
  10. Taylor expanded in re around 0 5.0%

    \[\leadsto \color{blue}{im} \]
  11. 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 2024103 
(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))))