math.sin on complex, imaginary part

Percentage Accurate: 53.5% → 99.1%
Time: 17.8s
Alternatives: 7
Speedup: 2.6×

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 7 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: 53.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.1% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 91.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 4.1 \cdot 10^{+41}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984\\ \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 4.1e+41)
     (* 0.5 (log1p (expm1 (* im -2.0))))
     (* (* (cos re) (pow im 7.0)) -0.0001984126984126984))))
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 <= 4.1e+41) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else {
		tmp = (cos(re) * pow(im, 7.0)) * -0.0001984126984126984;
	}
	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 <= 4.1e+41) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else {
		tmp = (Math.cos(re) * Math.pow(im, 7.0)) * -0.0001984126984126984;
	}
	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 <= 4.1e+41:
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	else:
		tmp = (math.cos(re) * math.pow(im, 7.0)) * -0.0001984126984126984
	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 <= 4.1e+41)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	else
		tmp = Float64(Float64(cos(re) * (im ^ 7.0)) * -0.0001984126984126984);
	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, 4.1e+41], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision] * -0.0001984126984126984), $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 4.1 \cdot 10^{+41}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\

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


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

    1. Initial program 44.4%

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

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

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

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

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

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

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

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

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

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

      \[\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 < 4.1000000000000004e41

    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-u89.5%

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

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

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

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

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

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

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

    if 4.1000000000000004e41 < 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 96.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\color{blue}{\cos re \cdot \left(-2 + -0.3333333333333333 \cdot {im}^{2}\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      6. +-commutative96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define96.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified96.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. Taylor expanded in im around inf 98.4%

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)} \]
    10. Simplified98.4%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)} \]
    11. Taylor expanded in re around inf 98.4%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot \cos re\right)} \]
    12. Step-by-step derivation
      1. *-commutative98.4%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right)} \cdot -0.0001984126984126984 \]
    13. Simplified98.4%

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

    \[\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 4.1 \cdot 10^{+41}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 73.6% accurate, 1.4× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 2.60000000000000004e-15

    1. Initial program 44.2%

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

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

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

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

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

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

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

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

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

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

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

    if 2.60000000000000004e-15 < im < 8.4e18

    1. Initial program 89.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.4e18 < 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 90.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\color{blue}{\cos re \cdot \left(-2 + -0.3333333333333333 \cdot {im}^{2}\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      6. +-commutative90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define90.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified90.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. Taylor expanded in im around inf 92.2%

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{7}\right)\right)} \]
    11. Taylor expanded in re around inf 92.2%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot \cos re\right)} \]
    12. Step-by-step derivation
      1. *-commutative92.2%

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

        \[\leadsto \color{blue}{\left(\cos re \cdot {im}^{7}\right)} \cdot -0.0001984126984126984 \]
    13. Simplified92.2%

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

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

Alternative 4: 69.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {im}^{7} \cdot 0.0001984126984126984\\ t_1 := {im}^{7} \cdot -0.0001984126984126984\\ \mathbf{if}\;im \leq 0.2:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\ \mathbf{elif}\;im \leq 6.5 \cdot 10^{+93}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+93}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;im \leq 3.6 \cdot 10^{+151}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;im \leq 1.72 \cdot 10^{+162}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(0.26666666666666666 \cdot {im}^{4} - 2\right)\right)\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+178} \lor \neg \left(im \leq 3.3 \cdot 10^{+184}\right):\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (pow im 7.0) 0.0001984126984126984))
        (t_1 (* (pow im 7.0) -0.0001984126984126984)))
   (if (<= im 0.2)
     (* 0.5 (* (cos re) (* im -2.0)))
     (if (<= im 6.5e+93)
       (* 0.5 (log1p (expm1 (* im -2.0))))
       (if (<= im 6.6e+93)
         t_0
         (if (<= im 3.6e+151)
           t_1
           (if (<= im 1.72e+162)
             (* 0.5 (* im (- (* 0.26666666666666666 (pow im 4.0)) 2.0)))
             (if (or (<= im 2.1e+178) (not (<= im 3.3e+184))) t_1 t_0))))))))
double code(double re, double im) {
	double t_0 = pow(im, 7.0) * 0.0001984126984126984;
	double t_1 = pow(im, 7.0) * -0.0001984126984126984;
	double tmp;
	if (im <= 0.2) {
		tmp = 0.5 * (cos(re) * (im * -2.0));
	} else if (im <= 6.5e+93) {
		tmp = 0.5 * log1p(expm1((im * -2.0)));
	} else if (im <= 6.6e+93) {
		tmp = t_0;
	} else if (im <= 3.6e+151) {
		tmp = t_1;
	} else if (im <= 1.72e+162) {
		tmp = 0.5 * (im * ((0.26666666666666666 * pow(im, 4.0)) - 2.0));
	} else if ((im <= 2.1e+178) || !(im <= 3.3e+184)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.pow(im, 7.0) * 0.0001984126984126984;
	double t_1 = Math.pow(im, 7.0) * -0.0001984126984126984;
	double tmp;
	if (im <= 0.2) {
		tmp = 0.5 * (Math.cos(re) * (im * -2.0));
	} else if (im <= 6.5e+93) {
		tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
	} else if (im <= 6.6e+93) {
		tmp = t_0;
	} else if (im <= 3.6e+151) {
		tmp = t_1;
	} else if (im <= 1.72e+162) {
		tmp = 0.5 * (im * ((0.26666666666666666 * Math.pow(im, 4.0)) - 2.0));
	} else if ((im <= 2.1e+178) || !(im <= 3.3e+184)) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = math.pow(im, 7.0) * 0.0001984126984126984
	t_1 = math.pow(im, 7.0) * -0.0001984126984126984
	tmp = 0
	if im <= 0.2:
		tmp = 0.5 * (math.cos(re) * (im * -2.0))
	elif im <= 6.5e+93:
		tmp = 0.5 * math.log1p(math.expm1((im * -2.0)))
	elif im <= 6.6e+93:
		tmp = t_0
	elif im <= 3.6e+151:
		tmp = t_1
	elif im <= 1.72e+162:
		tmp = 0.5 * (im * ((0.26666666666666666 * math.pow(im, 4.0)) - 2.0))
	elif (im <= 2.1e+178) or not (im <= 3.3e+184):
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64((im ^ 7.0) * 0.0001984126984126984)
	t_1 = Float64((im ^ 7.0) * -0.0001984126984126984)
	tmp = 0.0
	if (im <= 0.2)
		tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0)));
	elseif (im <= 6.5e+93)
		tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0))));
	elseif (im <= 6.6e+93)
		tmp = t_0;
	elseif (im <= 3.6e+151)
		tmp = t_1;
	elseif (im <= 1.72e+162)
		tmp = Float64(0.5 * Float64(im * Float64(Float64(0.26666666666666666 * (im ^ 4.0)) - 2.0)));
	elseif ((im <= 2.1e+178) || !(im <= 3.3e+184))
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[Power[im, 7.0], $MachinePrecision] * 0.0001984126984126984), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]}, If[LessEqual[im, 0.2], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 6.5e+93], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 6.6e+93], t$95$0, If[LessEqual[im, 3.6e+151], t$95$1, If[LessEqual[im, 1.72e+162], N[(0.5 * N[(im * N[(N[(0.26666666666666666 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 2.1e+178], N[Not[LessEqual[im, 3.3e+184]], $MachinePrecision]], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {im}^{7} \cdot 0.0001984126984126984\\
t_1 := {im}^{7} \cdot -0.0001984126984126984\\
\mathbf{if}\;im \leq 0.2:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\

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

\mathbf{elif}\;im \leq 6.6 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;im \leq 3.6 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;im \leq 1.72 \cdot 10^{+162}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(0.26666666666666666 \cdot {im}^{4} - 2\right)\right)\\

\mathbf{elif}\;im \leq 2.1 \cdot 10^{+178} \lor \neg \left(im \leq 3.3 \cdot 10^{+184}\right):\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 44.4%

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

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

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

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

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

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

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

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

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

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

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

    if 0.20000000000000001 < im < 6.4999999999999998e93

    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. Step-by-step derivation
      1. log1p-expm1-u94.8%

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

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

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

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

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

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

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

    if 6.4999999999999998e93 < im < 6.60000000000000017e93 or 2.0999999999999999e178 < im < 3.2999999999999998e184

    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 \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\color{blue}{\cos re \cdot \left(-2 + -0.3333333333333333 \cdot {im}^{2}\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      6. +-commutative100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. 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)} \]
    9. 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)} \]
      2. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot {im}^{7}} \]
    12. Step-by-step derivation
      1. *-commutative0.0%

        \[\leadsto \color{blue}{{im}^{7} \cdot -0.0001984126984126984} \]
    13. Simplified0.0%

      \[\leadsto \color{blue}{{im}^{7} \cdot -0.0001984126984126984} \]
    14. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{{im}^{7} \cdot -0.0001984126984126984} \cdot \sqrt{{im}^{7} \cdot -0.0001984126984126984}} \]
      2. sqrt-unprod100.0%

        \[\leadsto \color{blue}{\sqrt{\left({im}^{7} \cdot -0.0001984126984126984\right) \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)}} \]
      3. swap-sqr100.0%

        \[\leadsto \sqrt{\color{blue}{\left({im}^{7} \cdot {im}^{7}\right) \cdot \left(-0.0001984126984126984 \cdot -0.0001984126984126984\right)}} \]
      4. pow-prod-up100.0%

        \[\leadsto \sqrt{\color{blue}{{im}^{\left(7 + 7\right)}} \cdot \left(-0.0001984126984126984 \cdot -0.0001984126984126984\right)} \]
      5. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{\color{blue}{14}} \cdot \left(-0.0001984126984126984 \cdot -0.0001984126984126984\right)} \]
      6. metadata-eval100.0%

        \[\leadsto \sqrt{{im}^{14} \cdot \color{blue}{3.936759889140842 \cdot 10^{-8}}} \]
    15. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\sqrt{{im}^{14} \cdot 3.936759889140842 \cdot 10^{-8}}} \]
    16. Step-by-step derivation
      1. sqrt-prod100.0%

        \[\leadsto \color{blue}{\sqrt{{im}^{14}} \cdot \sqrt{3.936759889140842 \cdot 10^{-8}}} \]
      2. sqrt-pow1100.0%

        \[\leadsto \color{blue}{{im}^{\left(\frac{14}{2}\right)}} \cdot \sqrt{3.936759889140842 \cdot 10^{-8}} \]
      3. metadata-eval100.0%

        \[\leadsto {im}^{\color{blue}{7}} \cdot \sqrt{3.936759889140842 \cdot 10^{-8}} \]
      4. metadata-eval100.0%

        \[\leadsto {im}^{7} \cdot \color{blue}{0.0001984126984126984} \]
    17. Applied egg-rr100.0%

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

    if 6.60000000000000017e93 < im < 3.6e151 or 1.72e162 < im < 2.0999999999999999e178 or 3.2999999999999998e184 < 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 \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\color{blue}{\cos re \cdot \left(-2 + -0.3333333333333333 \cdot {im}^{2}\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      6. +-commutative100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define100.0%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified100.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. 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)} \]
    9. 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)} \]
      2. *-commutative100.0%

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

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

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot {im}^{7}} \]
    12. Step-by-step derivation
      1. *-commutative82.1%

        \[\leadsto \color{blue}{{im}^{7} \cdot -0.0001984126984126984} \]
    13. Simplified82.1%

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

    if 3.6e151 < im < 1.72e162

    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 4.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}{\left(im \cdot -2\right)} \cdot \cos re\right)\right) \]
      3. associate-*l*100.0%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{im \cdot \left(im \cdot \left(2 + im \cdot \left(0.6666666666666666 \cdot im - 1.3333333333333333\right)\right) - 2\right)}\right) \]
    12. Taylor expanded in im around 0 100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.2:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\ \mathbf{elif}\;im \leq 6.5 \cdot 10^{+93}:\\ \;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\ \mathbf{elif}\;im \leq 6.6 \cdot 10^{+93}:\\ \;\;\;\;{im}^{7} \cdot 0.0001984126984126984\\ \mathbf{elif}\;im \leq 3.6 \cdot 10^{+151}:\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\ \mathbf{elif}\;im \leq 1.72 \cdot 10^{+162}:\\ \;\;\;\;0.5 \cdot \left(im \cdot \left(0.26666666666666666 \cdot {im}^{4} - 2\right)\right)\\ \mathbf{elif}\;im \leq 2.1 \cdot 10^{+178} \lor \neg \left(im \leq 3.3 \cdot 10^{+184}\right):\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\ \mathbf{else}:\\ \;\;\;\;{im}^{7} \cdot 0.0001984126984126984\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 67.1% accurate, 2.6× speedup?

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

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

\mathbf{elif}\;im \leq 1.6 \cdot 10^{+215} \lor \neg \left(im \leq 1.6 \cdot 10^{+227}\right):\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(0.4444444444444444 \cdot {im}^{6}\right)\\


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

    1. Initial program 44.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0560000000000000012 < im < 1.5999999999999999e215 or 1.59999999999999994e227 < im

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\color{blue}{\cos re \cdot \left(-2 + -0.3333333333333333 \cdot {im}^{2}\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      6. +-commutative83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define83.9%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified83.9%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. Taylor expanded in im around inf 83.8%

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

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

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

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

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot {im}^{7}} \]
    12. Step-by-step derivation
      1. *-commutative60.0%

        \[\leadsto \color{blue}{{im}^{7} \cdot -0.0001984126984126984} \]
    13. Simplified60.0%

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

    if 1.5999999999999999e215 < im < 1.59999999999999994e227

    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}{\left(im \cdot -2\right)} \cdot \cos re\right)\right) \]
      3. associate-*l*100.0%

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

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

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

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

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

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\color{blue}{im \cdot \left(im \cdot \left(2 + im \cdot \left(0.6666666666666666 \cdot im - 1.3333333333333333\right)\right) - 2\right)}\right) \]
    12. Taylor expanded in im around 0 50.0%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left({im}^{4} \cdot \left(0.26666666666666666 + 0.4444444444444444 \cdot im\right) - 2\right)\right)} \]
    13. Taylor expanded in im around inf 50.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.056:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\ \mathbf{elif}\;im \leq 1.6 \cdot 10^{+215} \lor \neg \left(im \leq 1.6 \cdot 10^{+227}\right):\\ \;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.4444444444444444 \cdot {im}^{6}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 44.8% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00078:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\

\mathbf{else}:\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\


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

    1. Initial program 44.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.79999999999999986e-4 < im

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re + {im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-in84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right)\right) \]
      2. associate-+r+84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\left(\left(-2 \cdot \cos re + {im}^{2} \cdot \left(-0.3333333333333333 \cdot \cos re\right)\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
      3. associate-*r*84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left({im}^{2} \cdot -0.3333333333333333\right) \cdot \cos re}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      4. *-commutative84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\left(-2 \cdot \cos re + \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2}\right)} \cdot \cos re\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      5. distribute-rgt-out84.4%

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

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} + -2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      7. metadata-eval84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} + \color{blue}{\left(-2\right)}\right) + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      8. sub-neg84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \left(\cos re \cdot \color{blue}{\left(-0.3333333333333333 \cdot {im}^{2} - 2\right)} + {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)\right) \]
      9. fma-define84.4%

        \[\leadsto 0.5 \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\cos re, -0.3333333333333333 \cdot {im}^{2} - 2, {im}^{2} \cdot \left({im}^{2} \cdot \left(-0.016666666666666666 \cdot \cos re + -0.0003968253968253968 \cdot \left({im}^{2} \cdot \cos re\right)\right)\right)\right)}\right) \]
    7. Simplified84.4%

      \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot \mathsf{fma}\left(\cos re, \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right), \cos re \cdot \left(\mathsf{fma}\left({im}^{2}, -0.0003968253968253968, -0.016666666666666666\right) \cdot {im}^{4}\right)\right)\right)} \]
    8. Taylor expanded in im around inf 84.3%

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

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

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

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

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot {im}^{7}} \]
    12. Step-by-step derivation
      1. *-commutative59.7%

        \[\leadsto \color{blue}{{im}^{7} \cdot -0.0001984126984126984} \]
    13. Simplified59.7%

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

Alternative 7: 29.8% accurate, 61.8× speedup?

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

\\
0.5 \cdot \left(im \cdot -2\right)
\end{array}
Derivation
  1. Initial program 58.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto 0.5 \cdot \color{blue}{\left(im \cdot -2\right)} \]
  9. 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 2024107 
(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))))