math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 8.0s
Alternatives: 15
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 15 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} \\ 0.5 \cdot \left(\sin re \cdot \left(e^{-im} + e^{im}\right)\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(0.5 * Float64(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[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(\sin re \cdot \left(e^{-im} + e^{im}\right)\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 85.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 6500000000000:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 8.8 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \frac{re \cdot \left(4 - {im}^{12} \cdot 7.71604938271605 \cdot 10^{-6}\right)}{2 + -0.002777777777777778 \cdot {im}^{6}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \left(2 + {im}^{6} \cdot 0.002777777777777778\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 6500000000000.0)
   (* 0.5 (* (sin re) (fma im im 2.0)))
   (if (<= im 8.8e+47)
     (*
      0.5
      (/
       (* re (- 4.0 (* (pow im 12.0) 7.71604938271605e-6)))
       (+ 2.0 (* -0.002777777777777778 (pow im 6.0)))))
     (* 0.5 (* (sin re) (+ 2.0 (* (pow im 6.0) 0.002777777777777778)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 6500000000000.0) {
		tmp = 0.5 * (sin(re) * fma(im, im, 2.0));
	} else if (im <= 8.8e+47) {
		tmp = 0.5 * ((re * (4.0 - (pow(im, 12.0) * 7.71604938271605e-6))) / (2.0 + (-0.002777777777777778 * pow(im, 6.0))));
	} else {
		tmp = 0.5 * (sin(re) * (2.0 + (pow(im, 6.0) * 0.002777777777777778)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 6500000000000.0)
		tmp = Float64(0.5 * Float64(sin(re) * fma(im, im, 2.0)));
	elseif (im <= 8.8e+47)
		tmp = Float64(0.5 * Float64(Float64(re * Float64(4.0 - Float64((im ^ 12.0) * 7.71604938271605e-6))) / Float64(2.0 + Float64(-0.002777777777777778 * (im ^ 6.0)))));
	else
		tmp = Float64(0.5 * Float64(sin(re) * Float64(2.0 + Float64((im ^ 6.0) * 0.002777777777777778))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 6500000000000.0], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.8e+47], N[(0.5 * N[(N[(re * N[(4.0 - N[(N[Power[im, 12.0], $MachinePrecision] * 7.71604938271605e-6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 + N[(-0.002777777777777778 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(2.0 + N[(N[Power[im, 6.0], $MachinePrecision] * 0.002777777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 6500000000000:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

\mathbf{elif}\;im \leq 8.8 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \frac{re \cdot \left(4 - {im}^{12} \cdot 7.71604938271605 \cdot 10^{-6}\right)}{2 + -0.002777777777777778 \cdot {im}^{6}}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \left(2 + {im}^{6} \cdot 0.002777777777777778\right)\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 84.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 5300000000000:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 8.8 \cdot 10^{+47}:\\ \;\;\;\;0.5 \cdot \left(re \cdot \left(2 + \sqrt{{im}^{12} \cdot 7.71604938271605 \cdot 10^{-6}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.002777777777777778 \cdot \left(\sin re \cdot {im}^{6}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 5300000000000.0)
   (* 0.5 (* (sin re) (fma im im 2.0)))
   (if (<= im 8.8e+47)
     (* 0.5 (* re (+ 2.0 (sqrt (* (pow im 12.0) 7.71604938271605e-6)))))
     (* 0.5 (* 0.002777777777777778 (* (sin re) (pow im 6.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 5300000000000.0) {
		tmp = 0.5 * (sin(re) * fma(im, im, 2.0));
	} else if (im <= 8.8e+47) {
		tmp = 0.5 * (re * (2.0 + sqrt((pow(im, 12.0) * 7.71604938271605e-6))));
	} else {
		tmp = 0.5 * (0.002777777777777778 * (sin(re) * pow(im, 6.0)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 5300000000000.0)
		tmp = Float64(0.5 * Float64(sin(re) * fma(im, im, 2.0)));
	elseif (im <= 8.8e+47)
		tmp = Float64(0.5 * Float64(re * Float64(2.0 + sqrt(Float64((im ^ 12.0) * 7.71604938271605e-6)))));
	else
		tmp = Float64(0.5 * Float64(0.002777777777777778 * Float64(sin(re) * (im ^ 6.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 5300000000000.0], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.8e+47], N[(0.5 * N[(re * N[(2.0 + N[Sqrt[N[(N[Power[im, 12.0], $MachinePrecision] * 7.71604938271605e-6), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(0.002777777777777778 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 5300000000000:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

\mathbf{elif}\;im \leq 8.8 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + \sqrt{{im}^{12} \cdot 7.71604938271605 \cdot 10^{-6}}\right)\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 84.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 115000000:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 2.35 \cdot 10^{+51}:\\ \;\;\;\;0.5 \cdot \left(\left({im}^{6} \cdot {re}^{3}\right) \cdot -0.000462962962962963\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.002777777777777778 \cdot \left(\sin re \cdot {im}^{6}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 115000000.0)
   (* 0.5 (* (sin re) (fma im im 2.0)))
   (if (<= im 2.35e+51)
     (* 0.5 (* (* (pow im 6.0) (pow re 3.0)) -0.000462962962962963))
     (* 0.5 (* 0.002777777777777778 (* (sin re) (pow im 6.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 115000000.0) {
		tmp = 0.5 * (sin(re) * fma(im, im, 2.0));
	} else if (im <= 2.35e+51) {
		tmp = 0.5 * ((pow(im, 6.0) * pow(re, 3.0)) * -0.000462962962962963);
	} else {
		tmp = 0.5 * (0.002777777777777778 * (sin(re) * pow(im, 6.0)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 115000000.0)
		tmp = Float64(0.5 * Float64(sin(re) * fma(im, im, 2.0)));
	elseif (im <= 2.35e+51)
		tmp = Float64(0.5 * Float64(Float64((im ^ 6.0) * (re ^ 3.0)) * -0.000462962962962963));
	else
		tmp = Float64(0.5 * Float64(0.002777777777777778 * Float64(sin(re) * (im ^ 6.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 115000000.0], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.35e+51], N[(0.5 * N[(N[(N[Power[im, 6.0], $MachinePrecision] * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision] * -0.000462962962962963), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(0.002777777777777778 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 115000000:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

\mathbf{elif}\;im \leq 2.35 \cdot 10^{+51}:\\
\;\;\;\;0.5 \cdot \left(\left({im}^{6} \cdot {re}^{3}\right) \cdot -0.000462962962962963\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 68.6% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot 2\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(0.002777777777777778 \cdot \left(re \cdot {im}^{6}\right) + re \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 82.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 7500000000000:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{6} \cdot 0.002777777777777778\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot {im}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 7500000000000.0)
   (* 0.5 (* (sin re) (fma im im 2.0)))
   (if (<= im 1.35e+154)
     (* 0.5 (* re (+ 2.0 (* (pow im 6.0) 0.002777777777777778))))
     (* 0.5 (* (sin re) (pow im 2.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 7500000000000.0) {
		tmp = 0.5 * (sin(re) * fma(im, im, 2.0));
	} else if (im <= 1.35e+154) {
		tmp = 0.5 * (re * (2.0 + (pow(im, 6.0) * 0.002777777777777778)));
	} else {
		tmp = 0.5 * (sin(re) * pow(im, 2.0));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 7500000000000.0)
		tmp = Float64(0.5 * Float64(sin(re) * fma(im, im, 2.0)));
	elseif (im <= 1.35e+154)
		tmp = Float64(0.5 * Float64(re * Float64(2.0 + Float64((im ^ 6.0) * 0.002777777777777778))));
	else
		tmp = Float64(0.5 * Float64(sin(re) * (im ^ 2.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 7500000000000.0], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(re * N[(2.0 + N[(N[Power[im, 6.0], $MachinePrecision] * 0.002777777777777778), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 7500000000000:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{6} \cdot 0.002777777777777778\right)\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 83.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 4.5:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(0.002777777777777778 \cdot \left(\sin re \cdot {im}^{6}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 4.5)
   (* 0.5 (* (sin re) (fma im im 2.0)))
   (* 0.5 (* 0.002777777777777778 (* (sin re) (pow im 6.0))))))
double code(double re, double im) {
	double tmp;
	if (im <= 4.5) {
		tmp = 0.5 * (sin(re) * fma(im, im, 2.0));
	} else {
		tmp = 0.5 * (0.002777777777777778 * (sin(re) * pow(im, 6.0)));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 4.5)
		tmp = Float64(0.5 * Float64(sin(re) * fma(im, im, 2.0)));
	else
		tmp = Float64(0.5 * Float64(0.002777777777777778 * Float64(sin(re) * (im ^ 6.0))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 4.5], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(0.002777777777777778 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.5:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 91.4% accurate, 1.5× speedup?

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

\\
0.5 \cdot \left(\sin re \cdot \left(2 + {im}^{6} \cdot 0.002777777777777778\right)\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 65.5% accurate, 2.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 65.5% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 65.7% accurate, 2.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 60.6% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 3.1 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 3.1e-7) (* 0.5 (* (sin re) 2.0)) (* 0.5 (* re (fma im im 2.0)))))
double code(double re, double im) {
	double tmp;
	if (im <= 3.1e-7) {
		tmp = 0.5 * (sin(re) * 2.0);
	} else {
		tmp = 0.5 * (re * fma(im, im, 2.0));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 3.1e-7)
		tmp = Float64(0.5 * Float64(sin(re) * 2.0));
	else
		tmp = Float64(0.5 * Float64(re * fma(im, im, 2.0)));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 3.1e-7], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\sin re \cdot 2\right)\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 60.7% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 14: 50.4% accurate, 2.9× speedup?

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

\\
0.5 \cdot \left(\sin re \cdot 2\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 15: 26.1% accurate, 61.8× speedup?

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

\\
0.5 \cdot \left(re \cdot 2\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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