math.cos on complex, imaginary part

Percentage Accurate: 65.6% → 99.8%
Time: 8.5s
Alternatives: 14
Speedup: 2.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 14 alternatives:

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

Initial Program: 65.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -0.20000000000000001 or 1.99999999999999991e-6 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 100.0%

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

    if -0.20000000000000001 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 1.99999999999999991e-6

    1. Initial program 28.2%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 95.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -5 \cdot 10^{+103} \lor \neg \left(im \leq -1000\right) \land \left(im \leq 0.205 \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right)\right):\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -5e+103)
         (and (not (<= im -1000.0)) (or (<= im 0.205) (not (<= im 5.5e+102)))))
   (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))
   (* (- (exp (- im)) (exp im)) (* 0.5 re))))
double code(double re, double im) {
	double tmp;
	if ((im <= -5e+103) || (!(im <= -1000.0) && ((im <= 0.205) || !(im <= 5.5e+102)))) {
		tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	} else {
		tmp = (exp(-im) - exp(im)) * (0.5 * re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-5d+103)) .or. (.not. (im <= (-1000.0d0))) .and. (im <= 0.205d0) .or. (.not. (im <= 5.5d+102))) then
        tmp = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    else
        tmp = (exp(-im) - exp(im)) * (0.5d0 * re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -5e+103) || (!(im <= -1000.0) && ((im <= 0.205) || !(im <= 5.5e+102)))) {
		tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	} else {
		tmp = (Math.exp(-im) - Math.exp(im)) * (0.5 * re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -5e+103) or (not (im <= -1000.0) and ((im <= 0.205) or not (im <= 5.5e+102))):
		tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	else:
		tmp = (math.exp(-im) - math.exp(im)) * (0.5 * re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -5e+103) || (!(im <= -1000.0) && ((im <= 0.205) || !(im <= 5.5e+102))))
		tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	else
		tmp = Float64(Float64(exp(Float64(-im)) - exp(im)) * Float64(0.5 * re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -5e+103) || (~((im <= -1000.0)) && ((im <= 0.205) || ~((im <= 5.5e+102)))))
		tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	else
		tmp = (exp(-im) - exp(im)) * (0.5 * re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -5e+103], And[N[Not[LessEqual[im, -1000.0]], $MachinePrecision], Or[LessEqual[im, 0.205], N[Not[LessEqual[im, 5.5e+102]], $MachinePrecision]]]], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -5 \cdot 10^{+103} \lor \neg \left(im \leq -1000\right) \land \left(im \leq 0.205 \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right)\right):\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -5e103 or -1e3 < im < 0.204999999999999988 or 5.49999999999999981e102 < im

    1. Initial program 55.4%

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

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

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

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

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

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

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

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

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

    if -5e103 < im < -1e3 or 0.204999999999999988 < im < 5.49999999999999981e102

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5 \cdot 10^{+103} \lor \neg \left(im \leq -1000\right) \land \left(im \leq 0.205 \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right)\right):\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \]

Alternative 3: 87.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{if}\;im \leq -5 \cdot 10^{+103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -68000000000000:\\ \;\;\;\;re \cdot \sqrt{0.027777777777777776 \cdot {im}^{6}}\\ \mathbf{elif}\;im \leq 5.4 \cdot 10^{+20} \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-0.16666666666666666 \cdot {re}^{3} - re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))))
   (if (<= im -5e+103)
     t_0
     (if (<= im -68000000000000.0)
       (* re (sqrt (* 0.027777777777777776 (pow im 6.0))))
       (if (or (<= im 5.4e+20) (not (<= im 5.5e+102)))
         t_0
         (* im (- (* -0.16666666666666666 (pow re 3.0)) re)))))))
double code(double re, double im) {
	double t_0 = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	double tmp;
	if (im <= -5e+103) {
		tmp = t_0;
	} else if (im <= -68000000000000.0) {
		tmp = re * sqrt((0.027777777777777776 * pow(im, 6.0)));
	} else if ((im <= 5.4e+20) || !(im <= 5.5e+102)) {
		tmp = t_0;
	} else {
		tmp = im * ((-0.16666666666666666 * pow(re, 3.0)) - re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    if (im <= (-5d+103)) then
        tmp = t_0
    else if (im <= (-68000000000000.0d0)) then
        tmp = re * sqrt((0.027777777777777776d0 * (im ** 6.0d0)))
    else if ((im <= 5.4d+20) .or. (.not. (im <= 5.5d+102))) then
        tmp = t_0
    else
        tmp = im * (((-0.16666666666666666d0) * (re ** 3.0d0)) - re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	double tmp;
	if (im <= -5e+103) {
		tmp = t_0;
	} else if (im <= -68000000000000.0) {
		tmp = re * Math.sqrt((0.027777777777777776 * Math.pow(im, 6.0)));
	} else if ((im <= 5.4e+20) || !(im <= 5.5e+102)) {
		tmp = t_0;
	} else {
		tmp = im * ((-0.16666666666666666 * Math.pow(re, 3.0)) - re);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	tmp = 0
	if im <= -5e+103:
		tmp = t_0
	elif im <= -68000000000000.0:
		tmp = re * math.sqrt((0.027777777777777776 * math.pow(im, 6.0)))
	elif (im <= 5.4e+20) or not (im <= 5.5e+102):
		tmp = t_0
	else:
		tmp = im * ((-0.16666666666666666 * math.pow(re, 3.0)) - re)
	return tmp
function code(re, im)
	t_0 = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im))
	tmp = 0.0
	if (im <= -5e+103)
		tmp = t_0;
	elseif (im <= -68000000000000.0)
		tmp = Float64(re * sqrt(Float64(0.027777777777777776 * (im ^ 6.0))));
	elseif ((im <= 5.4e+20) || !(im <= 5.5e+102))
		tmp = t_0;
	else
		tmp = Float64(im * Float64(Float64(-0.16666666666666666 * (re ^ 3.0)) - re));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	tmp = 0.0;
	if (im <= -5e+103)
		tmp = t_0;
	elseif (im <= -68000000000000.0)
		tmp = re * sqrt((0.027777777777777776 * (im ^ 6.0)));
	elseif ((im <= 5.4e+20) || ~((im <= 5.5e+102)))
		tmp = t_0;
	else
		tmp = im * ((-0.16666666666666666 * (re ^ 3.0)) - re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5e+103], t$95$0, If[LessEqual[im, -68000000000000.0], N[(re * N[Sqrt[N[(0.027777777777777776 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 5.4e+20], N[Not[LessEqual[im, 5.5e+102]], $MachinePrecision]], t$95$0, N[(im * N[(N[(-0.16666666666666666 * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -68000000000000:\\
\;\;\;\;re \cdot \sqrt{0.027777777777777776 \cdot {im}^{6}}\\

\mathbf{elif}\;im \leq 5.4 \cdot 10^{+20} \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -5e103 or -6.8e13 < im < 5.4e20 or 5.49999999999999981e102 < im

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

    if -5e103 < im < -6.8e13

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt38.8%

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

        \[\leadsto re \cdot \color{blue}{\sqrt{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)}} \]
      3. swap-sqr69.0%

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

        \[\leadsto re \cdot \sqrt{\color{blue}{0.027777777777777776} \cdot \left({im}^{3} \cdot {im}^{3}\right)} \]
      5. pow-prod-up69.0%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot \color{blue}{{im}^{\left(3 + 3\right)}}} \]
      6. metadata-eval69.0%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot {im}^{\color{blue}{6}}} \]
    10. Applied egg-rr69.0%

      \[\leadsto re \cdot \color{blue}{\sqrt{0.027777777777777776 \cdot {im}^{6}}} \]

    if 5.4e20 < im < 5.49999999999999981e102

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-13.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)} \]
    8. Step-by-step derivation
      1. add-log-exp28.4%

        \[\leadsto \color{blue}{\log \left(e^{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)}\right)} \]
      2. *-un-lft-identity28.4%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)}\right)} \]
      3. log-prod28.4%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)}\right)} \]
      4. metadata-eval28.4%

        \[\leadsto \color{blue}{0} + \log \left(e^{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)}\right) \]
      5. add-log-exp5.8%

        \[\leadsto 0 + \color{blue}{im \cdot \left(0.16666666666666666 \cdot {re}^{3} - re\right)} \]
      6. add-sqr-sqrt1.4%

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

        \[\leadsto 0 + im \cdot \left(\color{blue}{\sqrt{\left(0.16666666666666666 \cdot {re}^{3}\right) \cdot \left(0.16666666666666666 \cdot {re}^{3}\right)}} - re\right) \]
      8. swap-sqr21.1%

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

        \[\leadsto 0 + im \cdot \left(\sqrt{\color{blue}{0.027777777777777776} \cdot \left({re}^{3} \cdot {re}^{3}\right)} - re\right) \]
      10. metadata-eval21.1%

        \[\leadsto 0 + im \cdot \left(\sqrt{\color{blue}{\left(-0.16666666666666666 \cdot -0.16666666666666666\right)} \cdot \left({re}^{3} \cdot {re}^{3}\right)} - re\right) \]
      11. swap-sqr21.1%

        \[\leadsto 0 + im \cdot \left(\sqrt{\color{blue}{\left(-0.16666666666666666 \cdot {re}^{3}\right) \cdot \left(-0.16666666666666666 \cdot {re}^{3}\right)}} - re\right) \]
      12. *-commutative21.1%

        \[\leadsto 0 + im \cdot \left(\sqrt{\color{blue}{\left({re}^{3} \cdot -0.16666666666666666\right)} \cdot \left(-0.16666666666666666 \cdot {re}^{3}\right)} - re\right) \]
      13. *-commutative21.1%

        \[\leadsto 0 + im \cdot \left(\sqrt{\left({re}^{3} \cdot -0.16666666666666666\right) \cdot \color{blue}{\left({re}^{3} \cdot -0.16666666666666666\right)}} - re\right) \]
      14. sqrt-unprod12.9%

        \[\leadsto 0 + im \cdot \left(\color{blue}{\sqrt{{re}^{3} \cdot -0.16666666666666666} \cdot \sqrt{{re}^{3} \cdot -0.16666666666666666}} - re\right) \]
      15. add-sqr-sqrt33.7%

        \[\leadsto 0 + im \cdot \left(\color{blue}{{re}^{3} \cdot -0.16666666666666666} - re\right) \]
      16. *-commutative33.7%

        \[\leadsto 0 + im \cdot \left(\color{blue}{-0.16666666666666666 \cdot {re}^{3}} - re\right) \]
    9. Applied egg-rr33.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5 \cdot 10^{+103}:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{elif}\;im \leq -68000000000000:\\ \;\;\;\;re \cdot \sqrt{0.027777777777777776 \cdot {im}^{6}}\\ \mathbf{elif}\;im \leq 5.4 \cdot 10^{+20} \lor \neg \left(im \leq 5.5 \cdot 10^{+102}\right):\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-0.16666666666666666 \cdot {re}^{3} - re\right)\\ \end{array} \]

Alternative 4: 79.4% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -3300:\\
\;\;\;\;re \cdot \left(\sqrt{0.027777777777777776 \cdot {im}^{6}} - im\right)\\

\mathbf{elif}\;im \leq 3.3 \cdot 10^{+15}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto re \cdot \sqrt{\color{blue}{0.027777777777777776} \cdot \left({im}^{3} \cdot {im}^{3}\right)} \]
      5. pow-prod-up69.2%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot \color{blue}{{im}^{\left(3 + 3\right)}}} \]
      6. metadata-eval69.2%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot {im}^{\color{blue}{6}}} \]
    7. Applied egg-rr69.2%

      \[\leadsto re \cdot \left(\color{blue}{\sqrt{0.027777777777777776 \cdot {im}^{6}}} - im\right) \]

    if -3300 < im < 3.3e15

    1. Initial program 31.5%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-195.5%

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

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

    if 3.3e15 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -3300:\\ \;\;\;\;re \cdot \left(\sqrt{0.027777777777777776 \cdot {im}^{6}} - im\right)\\ \mathbf{elif}\;im \leq 3.3 \cdot 10^{+15}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 5: 79.4% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -145000:\\
\;\;\;\;re \cdot \sqrt{0.027777777777777776 \cdot {im}^{6}}\\

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

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt58.3%

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

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

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

        \[\leadsto re \cdot \sqrt{\color{blue}{0.027777777777777776} \cdot \left({im}^{3} \cdot {im}^{3}\right)} \]
      5. pow-prod-up69.2%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot \color{blue}{{im}^{\left(3 + 3\right)}}} \]
      6. metadata-eval69.2%

        \[\leadsto re \cdot \sqrt{0.027777777777777776 \cdot {im}^{\color{blue}{6}}} \]
    10. Applied egg-rr69.2%

      \[\leadsto re \cdot \color{blue}{\sqrt{0.027777777777777776 \cdot {im}^{6}}} \]

    if -145000 < im < 1.6e16

    1. Initial program 31.5%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-195.5%

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

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

    if 1.6e16 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -145000:\\ \;\;\;\;re \cdot \sqrt{0.027777777777777776 \cdot {im}^{6}}\\ \mathbf{elif}\;im \leq 1.6 \cdot 10^{+16}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 6: 77.0% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -3000 \lor \neg \left(im \leq 6 \cdot 10^{+14}\right):\\
\;\;\;\;re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -3e3 or 6e14 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

    if -3e3 < im < 6e14

    1. Initial program 31.5%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-195.5%

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

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

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

Alternative 7: 77.0% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -90000 \lor \neg \left(im \leq 7 \cdot 10^{+14}\right):\\
\;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -9e4 or 7e14 < im

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    if -9e4 < im < 7e14

    1. Initial program 31.5%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-195.5%

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

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

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

Alternative 8: 56.9% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.2 \cdot 10^{+14}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(im \cdot -2\right)\\

\mathbf{elif}\;im \leq 6.5 \cdot 10^{+15}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.2e14 < im < 6.5e15

    1. Initial program 32.6%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-194.1%

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

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

    if 6.5e15 < im

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-14.2%

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

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

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

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot re} \]
      2. neg-mul-112.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.2 \cdot 10^{+14}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(im \cdot -2\right)\\ \mathbf{elif}\;im \leq 6.5 \cdot 10^{+15}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-re\right)\\ \end{array} \]

Alternative 9: 32.9% accurate, 44.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(-2 \cdot im\right)} \cdot \left(0.5 \cdot re\right) \]
  6. Final simplification32.8%

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

Alternative 10: 32.9% accurate, 77.0× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-151.0%

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot re} \]
    2. neg-mul-132.4%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot re \]
  7. Simplified32.4%

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

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

Alternative 11: 2.7% accurate, 308.0× speedup?

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

\\
-512
\end{array}
Derivation
  1. Initial program 65.0%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-151.0%

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

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Applied egg-rr2.7%

    \[\leadsto \color{blue}{-512} \]
  6. Final simplification2.7%

    \[\leadsto -512 \]

Alternative 12: 2.7% accurate, 308.0× speedup?

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

\\
-0.16666666666666666
\end{array}
Derivation
  1. Initial program 65.0%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-151.0%

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

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Applied egg-rr2.7%

    \[\leadsto \color{blue}{-0.16666666666666666} \]
  6. Final simplification2.7%

    \[\leadsto -0.16666666666666666 \]

Alternative 13: 2.8% accurate, 308.0× speedup?

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

\\
-9.92290301275212 \cdot 10^{-8}
\end{array}
Derivation
  1. Initial program 65.0%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-151.0%

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

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Applied egg-rr2.7%

    \[\leadsto \color{blue}{-9.92290301275212 \cdot 10^{-8}} \]
  6. Final simplification2.7%

    \[\leadsto -9.92290301275212 \cdot 10^{-8} \]

Alternative 14: 15.2% accurate, 308.0× speedup?

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

\\
0
\end{array}
Derivation
  1. Initial program 65.0%

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-151.0%

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

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

    \[\leadsto \color{blue}{0} \]
  6. Final simplification13.5%

    \[\leadsto 0 \]

Developer target: 99.8% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

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

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))