math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 6.2s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * sin(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 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Sin[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 \sin 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 9 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * sin(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 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Sin[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 \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}

Alternative 1: 100.0% 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}
Derivation
  1. Initial program 100.0%

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

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

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

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

Alternative 2: 88.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+154} \lor \neg \left(im \leq -2.6 \lor \neg \left(im \leq 1.95\right) \land im \leq 1.2 \cdot 10^{+247}\right):\\ \;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -1.35e+154)
         (not (or (<= im -2.6) (and (not (<= im 1.95)) (<= im 1.2e+247)))))
   (+ (sin re) (* 0.5 (* im (* (sin re) im))))
   (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -1.35e+154) || !((im <= -2.6) || (!(im <= 1.95) && (im <= 1.2e+247)))) {
		tmp = sin(re) + (0.5 * (im * (sin(re) * im)));
	} else {
		tmp = (0.5 * 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 ((im <= (-1.35d+154)) .or. (.not. (im <= (-2.6d0)) .or. (.not. (im <= 1.95d0)) .and. (im <= 1.2d+247))) then
        tmp = sin(re) + (0.5d0 * (im * (sin(re) * im)))
    else
        tmp = (0.5d0 * re) * (exp(-im) + exp(im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -1.35e+154) || !((im <= -2.6) || (!(im <= 1.95) && (im <= 1.2e+247)))) {
		tmp = Math.sin(re) + (0.5 * (im * (Math.sin(re) * im)));
	} else {
		tmp = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -1.35e+154) or not ((im <= -2.6) or (not (im <= 1.95) and (im <= 1.2e+247))):
		tmp = math.sin(re) + (0.5 * (im * (math.sin(re) * im)))
	else:
		tmp = (0.5 * re) * (math.exp(-im) + math.exp(im))
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -1.35e+154) || !((im <= -2.6) || (!(im <= 1.95) && (im <= 1.2e+247))))
		tmp = Float64(sin(re) + Float64(0.5 * Float64(im * Float64(sin(re) * im))));
	else
		tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -1.35e+154) || ~(((im <= -2.6) || (~((im <= 1.95)) && (im <= 1.2e+247)))))
		tmp = sin(re) + (0.5 * (im * (sin(re) * im)));
	else
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -1.35e+154], N[Not[Or[LessEqual[im, -2.6], And[N[Not[LessEqual[im, 1.95]], $MachinePrecision], LessEqual[im, 1.2e+247]]]], $MachinePrecision]], N[(N[Sin[re], $MachinePrecision] + N[(0.5 * N[(im * N[(N[Sin[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.35 \cdot 10^{+154} \lor \neg \left(im \leq -2.6 \lor \neg \left(im \leq 1.95\right) \land im \leq 1.2 \cdot 10^{+247}\right):\\
\;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -1.35000000000000003e154 or -2.60000000000000009 < im < 1.94999999999999996 or 1.2e247 < im

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)} \]
    6. Taylor expanded in re around inf 99.1%

      \[\leadsto \sin re + \color{blue}{0.5 \cdot \left(\sin re \cdot {im}^{2}\right)} \]
    7. Simplified95.8%

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

    if -1.35000000000000003e154 < im < -2.60000000000000009 or 1.94999999999999996 < im < 1.2e247

    1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+154} \lor \neg \left(im \leq -2.6 \lor \neg \left(im \leq 1.95\right) \land im \leq 1.2 \cdot 10^{+247}\right):\\ \;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \]

Alternative 3: 93.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ t_1 := \sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -2.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.95:\\ \;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 re) (+ (exp (- im)) (exp im))))
        (t_1 (+ (sin re) (* (* 0.5 (sin re)) (* im im)))))
   (if (<= im -1.35e+154)
     t_1
     (if (<= im -2.6)
       t_0
       (if (<= im 1.95)
         (+ (sin re) (* 0.5 (* im (* (sin re) im))))
         (if (<= im 1.4e+154) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = (0.5 * re) * (exp(-im) + exp(im));
	double t_1 = sin(re) + ((0.5 * sin(re)) * (im * im));
	double tmp;
	if (im <= -1.35e+154) {
		tmp = t_1;
	} else if (im <= -2.6) {
		tmp = t_0;
	} else if (im <= 1.95) {
		tmp = sin(re) + (0.5 * (im * (sin(re) * im)));
	} else if (im <= 1.4e+154) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (0.5d0 * re) * (exp(-im) + exp(im))
    t_1 = sin(re) + ((0.5d0 * sin(re)) * (im * im))
    if (im <= (-1.35d+154)) then
        tmp = t_1
    else if (im <= (-2.6d0)) then
        tmp = t_0
    else if (im <= 1.95d0) then
        tmp = sin(re) + (0.5d0 * (im * (sin(re) * im)))
    else if (im <= 1.4d+154) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
	double t_1 = Math.sin(re) + ((0.5 * Math.sin(re)) * (im * im));
	double tmp;
	if (im <= -1.35e+154) {
		tmp = t_1;
	} else if (im <= -2.6) {
		tmp = t_0;
	} else if (im <= 1.95) {
		tmp = Math.sin(re) + (0.5 * (im * (Math.sin(re) * im)));
	} else if (im <= 1.4e+154) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * re) * (math.exp(-im) + math.exp(im))
	t_1 = math.sin(re) + ((0.5 * math.sin(re)) * (im * im))
	tmp = 0
	if im <= -1.35e+154:
		tmp = t_1
	elif im <= -2.6:
		tmp = t_0
	elif im <= 1.95:
		tmp = math.sin(re) + (0.5 * (im * (math.sin(re) * im)))
	elif im <= 1.4e+154:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(re, im)
	t_0 = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)))
	t_1 = Float64(sin(re) + Float64(Float64(0.5 * sin(re)) * Float64(im * im)))
	tmp = 0.0
	if (im <= -1.35e+154)
		tmp = t_1;
	elseif (im <= -2.6)
		tmp = t_0;
	elseif (im <= 1.95)
		tmp = Float64(sin(re) + Float64(0.5 * Float64(im * Float64(sin(re) * im))));
	elseif (im <= 1.4e+154)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (0.5 * re) * (exp(-im) + exp(im));
	t_1 = sin(re) + ((0.5 * sin(re)) * (im * im));
	tmp = 0.0;
	if (im <= -1.35e+154)
		tmp = t_1;
	elseif (im <= -2.6)
		tmp = t_0;
	elseif (im <= 1.95)
		tmp = sin(re) + (0.5 * (im * (sin(re) * im)));
	elseif (im <= 1.4e+154)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[re], $MachinePrecision] + N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.35e+154], t$95$1, If[LessEqual[im, -2.6], t$95$0, If[LessEqual[im, 1.95], N[(N[Sin[re], $MachinePrecision] + N[(0.5 * N[(im * N[(N[Sin[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.4e+154], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -2.6:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 1.95:\\
\;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\

\mathbf{elif}\;im \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.35000000000000003e154 or 1.4e154 < im

    1. Initial program 100.0%

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

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

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

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

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

    if -1.35000000000000003e154 < im < -2.60000000000000009 or 1.94999999999999996 < im < 1.4e154

    1. Initial program 100.0%

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

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

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

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

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

    if -2.60000000000000009 < im < 1.94999999999999996

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re + 0.5 \cdot \left(\sin re \cdot {im}^{2}\right)} \]
    5. Simplified98.8%

      \[\leadsto \color{blue}{\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)} \]
    6. Taylor expanded in re around inf 98.8%

      \[\leadsto \sin re + \color{blue}{0.5 \cdot \left(\sin re \cdot {im}^{2}\right)} \]
    7. Simplified98.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq -2.6:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{elif}\;im \leq 1.95:\\ \;\;\;\;\sin re + 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+154}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \end{array} \]

Alternative 4: 87.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.000195 \lor \neg \left(im \leq 6.2 \cdot 10^{-6}\right):\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -0.000195) (not (<= im 6.2e-6)))
   (* (* 0.5 re) (+ (exp (- im)) (exp im)))
   (sin re)))
double code(double re, double im) {
	double tmp;
	if ((im <= -0.000195) || !(im <= 6.2e-6)) {
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	} else {
		tmp = 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 <= (-0.000195d0)) .or. (.not. (im <= 6.2d-6))) then
        tmp = (0.5d0 * re) * (exp(-im) + exp(im))
    else
        tmp = sin(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -0.000195) || !(im <= 6.2e-6)) {
		tmp = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
	} else {
		tmp = Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -0.000195) or not (im <= 6.2e-6):
		tmp = (0.5 * re) * (math.exp(-im) + math.exp(im))
	else:
		tmp = math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -0.000195) || !(im <= 6.2e-6))
		tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)));
	else
		tmp = sin(re);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -0.000195) || ~((im <= 6.2e-6)))
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	else
		tmp = sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -0.000195], N[Not[LessEqual[im, 6.2e-6]], $MachinePrecision]], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[re], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.000195 \lor \neg \left(im \leq 6.2 \cdot 10^{-6}\right):\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\

\mathbf{else}:\\
\;\;\;\;\sin re\\


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

    1. Initial program 100.0%

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

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

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

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

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

    if -1.94999999999999996e-4 < im < 6.1999999999999999e-6

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.9%

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

Alternative 5: 74.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := re + 0.5 \cdot \left(re \cdot {im}^{2}\right)\\ \mathbf{if}\;im \leq -5.9 \cdot 10^{+125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\ \mathbf{elif}\;im \leq 4 \cdot 10^{+18}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 9.5 \cdot 10^{+94}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (+ re (* 0.5 (* re (pow im 2.0))))))
   (if (<= im -5.9e+125)
     t_0
     (if (<= im -2300000000000.0)
       (log1p (expm1 re))
       (if (<= im 4e+18) (sin re) (if (<= im 9.5e+94) (pow re -512.0) t_0))))))
double code(double re, double im) {
	double t_0 = re + (0.5 * (re * pow(im, 2.0)));
	double tmp;
	if (im <= -5.9e+125) {
		tmp = t_0;
	} else if (im <= -2300000000000.0) {
		tmp = log1p(expm1(re));
	} else if (im <= 4e+18) {
		tmp = sin(re);
	} else if (im <= 9.5e+94) {
		tmp = pow(re, -512.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = re + (0.5 * (re * Math.pow(im, 2.0)));
	double tmp;
	if (im <= -5.9e+125) {
		tmp = t_0;
	} else if (im <= -2300000000000.0) {
		tmp = Math.log1p(Math.expm1(re));
	} else if (im <= 4e+18) {
		tmp = Math.sin(re);
	} else if (im <= 9.5e+94) {
		tmp = Math.pow(re, -512.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(re, im):
	t_0 = re + (0.5 * (re * math.pow(im, 2.0)))
	tmp = 0
	if im <= -5.9e+125:
		tmp = t_0
	elif im <= -2300000000000.0:
		tmp = math.log1p(math.expm1(re))
	elif im <= 4e+18:
		tmp = math.sin(re)
	elif im <= 9.5e+94:
		tmp = math.pow(re, -512.0)
	else:
		tmp = t_0
	return tmp
function code(re, im)
	t_0 = Float64(re + Float64(0.5 * Float64(re * (im ^ 2.0))))
	tmp = 0.0
	if (im <= -5.9e+125)
		tmp = t_0;
	elseif (im <= -2300000000000.0)
		tmp = log1p(expm1(re));
	elseif (im <= 4e+18)
		tmp = sin(re);
	elseif (im <= 9.5e+94)
		tmp = re ^ -512.0;
	else
		tmp = t_0;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(re + N[(0.5 * N[(re * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5.9e+125], t$95$0, If[LessEqual[im, -2300000000000.0], N[Log[1 + N[(Exp[re] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[im, 4e+18], N[Sin[re], $MachinePrecision], If[LessEqual[im, 9.5e+94], N[Power[re, -512.0], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

\mathbf{elif}\;im \leq -2300000000000:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\

\mathbf{elif}\;im \leq 4 \cdot 10^{+18}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 9.5 \cdot 10^{+94}:\\
\;\;\;\;{re}^{-512}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < -5.9000000000000001e125 or 9.4999999999999998e94 < im

    1. Initial program 100.0%

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

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

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

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

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

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

    if -5.9000000000000001e125 < im < -2.3e12

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)} \]

    if -2.3e12 < im < 4e18

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re} \]

    if 4e18 < im < 9.4999999999999998e94

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    6. Applied egg-rr50.5%

      \[\leadsto \color{blue}{{re}^{-512}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification72.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -5.9 \cdot 10^{+125}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot {im}^{2}\right)\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\ \mathbf{elif}\;im \leq 4 \cdot 10^{+18}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 9.5 \cdot 10^{+94}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot {im}^{2}\right)\\ \end{array} \]

Alternative 6: 73.0% accurate, 2.7× speedup?

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

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

\mathbf{elif}\;im \leq 3.9 \cdot 10^{+18}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 1.8 \cdot 10^{+95}:\\
\;\;\;\;{re}^{-512}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < -1.9000000000000001e-4 or 1.79999999999999989e95 < im

    1. Initial program 100.0%

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

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

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

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

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

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

    if -1.9000000000000001e-4 < im < 3.9e18

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re} \]

    if 3.9e18 < im < 1.79999999999999989e95

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    6. Applied egg-rr50.5%

      \[\leadsto \color{blue}{{re}^{-512}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification70.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -0.00019:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot {im}^{2}\right)\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+18}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+95}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot {im}^{2}\right)\\ \end{array} \]

Alternative 7: 62.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -1.6 \cdot 10^{+18}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+18}:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{re}^{-512}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -1.6e+18)
   (pow re -512.0)
   (if (<= im 3.9e+18) (sin re) (pow re -512.0))))
double code(double re, double im) {
	double tmp;
	if (im <= -1.6e+18) {
		tmp = pow(re, -512.0);
	} else if (im <= 3.9e+18) {
		tmp = sin(re);
	} else {
		tmp = pow(re, -512.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= (-1.6d+18)) then
        tmp = re ** (-512.0d0)
    else if (im <= 3.9d+18) then
        tmp = sin(re)
    else
        tmp = re ** (-512.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -1.6e+18) {
		tmp = Math.pow(re, -512.0);
	} else if (im <= 3.9e+18) {
		tmp = Math.sin(re);
	} else {
		tmp = Math.pow(re, -512.0);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -1.6e+18:
		tmp = math.pow(re, -512.0)
	elif im <= 3.9e+18:
		tmp = math.sin(re)
	else:
		tmp = math.pow(re, -512.0)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -1.6e+18)
		tmp = re ^ -512.0;
	elseif (im <= 3.9e+18)
		tmp = sin(re);
	else
		tmp = re ^ -512.0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -1.6e+18)
		tmp = re ^ -512.0;
	elseif (im <= 3.9e+18)
		tmp = sin(re);
	else
		tmp = re ^ -512.0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -1.6e+18], N[Power[re, -512.0], $MachinePrecision], If[LessEqual[im, 3.9e+18], N[Sin[re], $MachinePrecision], N[Power[re, -512.0], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.6 \cdot 10^{+18}:\\
\;\;\;\;{re}^{-512}\\

\mathbf{elif}\;im \leq 3.9 \cdot 10^{+18}:\\
\;\;\;\;\sin re\\

\mathbf{else}:\\
\;\;\;\;{re}^{-512}\\


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

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    6. Applied egg-rr21.5%

      \[\leadsto \color{blue}{{re}^{-512}} \]

    if -1.6e18 < im < 3.9e18

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{\sin re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification59.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -1.6 \cdot 10^{+18}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+18}:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{re}^{-512}\\ \end{array} \]

Alternative 8: 51.0% accurate, 3.1× speedup?

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

\\
\sin re
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto \color{blue}{\sin re} \]
  5. Final simplification50.3%

    \[\leadsto \sin re \]

Alternative 9: 26.5% accurate, 309.0× speedup?

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

\\
re
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

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

    \[\leadsto \color{blue}{re} \]
  7. Final simplification27.5%

    \[\leadsto re \]

Reproduce

?
herbie shell --seed 2023174 
(FPCore (re im)
  :name "math.sin on complex, real part"
  :precision binary64
  (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))