Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 17.0s
Alternatives: 18
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\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 18 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: 94.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\end{array}

Alternative 1: 99.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (hypot (sin ky) (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
}
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 40.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\ \mathbf{elif}\;\sin ky \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.005)
   (* (sin th) (/ (sin ky) (log (+ ky 1.0))))
   (if (<= (sin ky) 1e-7) (* (sin th) (fabs (/ (sin ky) (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.005) {
		tmp = sin(th) * (sin(ky) / log((ky + 1.0)));
	} else if (sin(ky) <= 1e-7) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.005d0)) then
        tmp = sin(th) * (sin(ky) / log((ky + 1.0d0)))
    else if (sin(ky) <= 1d-7) then
        tmp = sin(th) * abs((sin(ky) / sin(kx)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.005) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.log((ky + 1.0)));
	} else if (Math.sin(ky) <= 1e-7) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.005:
		tmp = math.sin(th) * (math.sin(ky) / math.log((ky + 1.0)))
	elif math.sin(ky) <= 1e-7:
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.005)
		tmp = Float64(sin(th) * Float64(sin(ky) / log(Float64(ky + 1.0))));
	elseif (sin(ky) <= 1e-7)
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.005)
		tmp = sin(th) * (sin(ky) / log((ky + 1.0)));
	elseif (sin(ky) <= 1e-7)
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.005], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Log[N[(ky + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\

\mathbf{elif}\;\sin ky \leq 10^{-7}:\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


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

Alternative 3: 44.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.07:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-68}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.07)
   (* (sin th) (fabs (/ ky (sin kx))))
   (if (<= (sin kx) 5e-68) (sin th) (* (sin ky) (/ (sin th) (sin kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.07) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else if (sin(kx) <= 5e-68) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) * (sin(th) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.07d0)) then
        tmp = sin(th) * abs((ky / sin(kx)))
    else if (sin(kx) <= 5d-68) then
        tmp = sin(th)
    else
        tmp = sin(ky) * (sin(th) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.07) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else if (Math.sin(kx) <= 5e-68) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.07:
		tmp = math.sin(th) * math.fabs((ky / math.sin(kx)))
	elif math.sin(kx) <= 5e-68:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.07)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	elseif (sin(kx) <= 5e-68)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.07)
		tmp = sin(th) * abs((ky / sin(kx)));
	elseif (sin(kx) <= 5e-68)
		tmp = sin(th);
	else
		tmp = sin(ky) * (sin(th) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.07], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-68], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.07:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-68}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\


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

Alternative 4: 44.2% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.07:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-68}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.07)
   (* (sin th) (fabs (/ ky (sin kx))))
   (if (<= (sin kx) 5e-68) (sin th) (/ (sin ky) (/ (sin kx) (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.07) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else if (sin(kx) <= 5e-68) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) / (sin(kx) / sin(th));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.07d0)) then
        tmp = sin(th) * abs((ky / sin(kx)))
    else if (sin(kx) <= 5d-68) then
        tmp = sin(th)
    else
        tmp = sin(ky) / (sin(kx) / sin(th))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.07) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else if (Math.sin(kx) <= 5e-68) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) / (Math.sin(kx) / Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.07:
		tmp = math.sin(th) * math.fabs((ky / math.sin(kx)))
	elif math.sin(kx) <= 5e-68:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) / (math.sin(kx) / math.sin(th))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.07)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	elseif (sin(kx) <= 5e-68)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) / Float64(sin(kx) / sin(th)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.07)
		tmp = sin(th) * abs((ky / sin(kx)));
	elseif (sin(kx) <= 5e-68)
		tmp = sin(th);
	else
		tmp = sin(ky) / (sin(kx) / sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.07], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 5e-68], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.07:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-68}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\


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

Alternative 5: 40.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\frac{\sin ky \cdot th}{\left|\sin kx\right|}\\ \mathbf{elif}\;\sin ky \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.005)
   (/ (* (sin ky) th) (fabs (sin kx)))
   (if (<= (sin ky) 1e-7) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.005) {
		tmp = (sin(ky) * th) / fabs(sin(kx));
	} else if (sin(ky) <= 1e-7) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.005d0)) then
        tmp = (sin(ky) * th) / abs(sin(kx))
    else if (sin(ky) <= 1d-7) then
        tmp = sin(th) * abs((ky / sin(kx)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.005) {
		tmp = (Math.sin(ky) * th) / Math.abs(Math.sin(kx));
	} else if (Math.sin(ky) <= 1e-7) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.005:
		tmp = (math.sin(ky) * th) / math.fabs(math.sin(kx))
	elif math.sin(ky) <= 1e-7:
		tmp = math.sin(th) * math.fabs((ky / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.005)
		tmp = Float64(Float64(sin(ky) * th) / abs(sin(kx)));
	elseif (sin(ky) <= 1e-7)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.005)
		tmp = (sin(ky) * th) / abs(sin(kx));
	elseif (sin(ky) <= 1e-7)
		tmp = sin(th) * abs((ky / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.005], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.005:\\
\;\;\;\;\frac{\sin ky \cdot th}{\left|\sin kx\right|}\\

\mathbf{elif}\;\sin ky \leq 10^{-7}:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

Alternative 6: 40.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\ \mathbf{elif}\;\sin ky \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.005)
   (* (sin th) (/ (sin ky) (log (+ ky 1.0))))
   (if (<= (sin ky) 1e-7) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.005) {
		tmp = sin(th) * (sin(ky) / log((ky + 1.0)));
	} else if (sin(ky) <= 1e-7) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.005d0)) then
        tmp = sin(th) * (sin(ky) / log((ky + 1.0d0)))
    else if (sin(ky) <= 1d-7) then
        tmp = sin(th) * abs((ky / sin(kx)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.005) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.log((ky + 1.0)));
	} else if (Math.sin(ky) <= 1e-7) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.005:
		tmp = math.sin(th) * (math.sin(ky) / math.log((ky + 1.0)))
	elif math.sin(ky) <= 1e-7:
		tmp = math.sin(th) * math.fabs((ky / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.005)
		tmp = Float64(sin(th) * Float64(sin(ky) / log(Float64(ky + 1.0))));
	elseif (sin(ky) <= 1e-7)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.005)
		tmp = sin(th) * (sin(ky) / log((ky + 1.0)));
	elseif (sin(ky) <= 1e-7)
		tmp = sin(th) * abs((ky / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.005], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Log[N[(ky + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\

\mathbf{elif}\;\sin ky \leq 10^{-7}:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

Alternative 7: 99.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (sin ky) (/ (sin th) (hypot (sin ky) (sin kx)))))
double code(double kx, double ky, double th) {
	return sin(ky) * (sin(th) / hypot(sin(ky), sin(kx)));
}
public static double code(double kx, double ky, double th) {
	return Math.sin(ky) * (Math.sin(th) / Math.hypot(Math.sin(ky), Math.sin(kx)));
}
def code(kx, ky, th):
	return math.sin(ky) * (math.sin(th) / math.hypot(math.sin(ky), math.sin(kx)))
function code(kx, ky, th)
	return Float64(sin(ky) * Float64(sin(th) / hypot(sin(ky), sin(kx))))
end
function tmp = code(kx, ky, th)
	tmp = sin(ky) * (sin(th) / hypot(sin(ky), sin(kx)));
end
code[kx_, ky_, th_] := N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 62.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ \mathbf{if}\;th \leq 1250:\\ \;\;\;\;\frac{\sin ky}{t_1 \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;th \leq 2.65 \cdot 10^{+199}:\\ \;\;\;\;\frac{ky \cdot \sin th}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin kx) (sin ky))))
   (if (<= th 1250.0)
     (/ (sin ky) (* t_1 (+ (/ 1.0 th) (* th 0.16666666666666666))))
     (if (<= th 2.65e+199)
       (/ (* ky (sin th)) t_1)
       (* (sin th) (/ (sin ky) (fabs (sin ky))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(kx), sin(ky));
	double tmp;
	if (th <= 1250.0) {
		tmp = sin(ky) / (t_1 * ((1.0 / th) + (th * 0.16666666666666666)));
	} else if (th <= 2.65e+199) {
		tmp = (ky * sin(th)) / t_1;
	} else {
		tmp = sin(th) * (sin(ky) / fabs(sin(ky)));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(kx), Math.sin(ky));
	double tmp;
	if (th <= 1250.0) {
		tmp = Math.sin(ky) / (t_1 * ((1.0 / th) + (th * 0.16666666666666666)));
	} else if (th <= 2.65e+199) {
		tmp = (ky * Math.sin(th)) / t_1;
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.abs(Math.sin(ky)));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(kx), math.sin(ky))
	tmp = 0
	if th <= 1250.0:
		tmp = math.sin(ky) / (t_1 * ((1.0 / th) + (th * 0.16666666666666666)))
	elif th <= 2.65e+199:
		tmp = (ky * math.sin(th)) / t_1
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.fabs(math.sin(ky)))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky))
	tmp = 0.0
	if (th <= 1250.0)
		tmp = Float64(sin(ky) / Float64(t_1 * Float64(Float64(1.0 / th) + Float64(th * 0.16666666666666666))));
	elseif (th <= 2.65e+199)
		tmp = Float64(Float64(ky * sin(th)) / t_1);
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / abs(sin(ky))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky));
	tmp = 0.0;
	if (th <= 1250.0)
		tmp = sin(ky) / (t_1 * ((1.0 / th) + (th * 0.16666666666666666)));
	elseif (th <= 2.65e+199)
		tmp = (ky * sin(th)) / t_1;
	else
		tmp = sin(th) * (sin(ky) / abs(sin(ky)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[th, 1250.0], N[(N[Sin[ky], $MachinePrecision] / N[(t$95$1 * N[(N[(1.0 / th), $MachinePrecision] + N[(th * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[th, 2.65e+199], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[Sin[ky], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
\mathbf{if}\;th \leq 1250:\\
\;\;\;\;\frac{\sin ky}{t_1 \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\

\mathbf{elif}\;th \leq 2.65 \cdot 10^{+199}:\\
\;\;\;\;\frac{ky \cdot \sin th}{t_1}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\


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

Alternative 9: 61.9% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ \mathbf{if}\;th \leq 1250:\\ \;\;\;\;\frac{\sin ky}{\frac{t_1}{th}}\\ \mathbf{elif}\;th \leq 1.06 \cdot 10^{+200}:\\ \;\;\;\;\frac{ky \cdot \sin th}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin kx) (sin ky))))
   (if (<= th 1250.0)
     (/ (sin ky) (/ t_1 th))
     (if (<= th 1.06e+200)
       (/ (* ky (sin th)) t_1)
       (* (sin th) (/ (sin ky) (fabs (sin ky))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(kx), sin(ky));
	double tmp;
	if (th <= 1250.0) {
		tmp = sin(ky) / (t_1 / th);
	} else if (th <= 1.06e+200) {
		tmp = (ky * sin(th)) / t_1;
	} else {
		tmp = sin(th) * (sin(ky) / fabs(sin(ky)));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(kx), Math.sin(ky));
	double tmp;
	if (th <= 1250.0) {
		tmp = Math.sin(ky) / (t_1 / th);
	} else if (th <= 1.06e+200) {
		tmp = (ky * Math.sin(th)) / t_1;
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.abs(Math.sin(ky)));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(kx), math.sin(ky))
	tmp = 0
	if th <= 1250.0:
		tmp = math.sin(ky) / (t_1 / th)
	elif th <= 1.06e+200:
		tmp = (ky * math.sin(th)) / t_1
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.fabs(math.sin(ky)))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky))
	tmp = 0.0
	if (th <= 1250.0)
		tmp = Float64(sin(ky) / Float64(t_1 / th));
	elseif (th <= 1.06e+200)
		tmp = Float64(Float64(ky * sin(th)) / t_1);
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / abs(sin(ky))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky));
	tmp = 0.0;
	if (th <= 1250.0)
		tmp = sin(ky) / (t_1 / th);
	elseif (th <= 1.06e+200)
		tmp = (ky * sin(th)) / t_1;
	else
		tmp = sin(th) * (sin(ky) / abs(sin(ky)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[th, 1250.0], N[(N[Sin[ky], $MachinePrecision] / N[(t$95$1 / th), $MachinePrecision]), $MachinePrecision], If[LessEqual[th, 1.06e+200], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[Sin[ky], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
\mathbf{if}\;th \leq 1250:\\
\;\;\;\;\frac{\sin ky}{\frac{t_1}{th}}\\

\mathbf{elif}\;th \leq 1.06 \cdot 10^{+200}:\\
\;\;\;\;\frac{ky \cdot \sin th}{t_1}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\


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

Alternative 10: 61.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 2.9 \cdot 10^{-6}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= th 2.9e-6)
   (/ (sin ky) (/ (hypot (sin kx) (sin ky)) th))
   (* (sin th) (/ (sin ky) (fabs (sin ky))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 2.9e-6) {
		tmp = sin(ky) / (hypot(sin(kx), sin(ky)) / th);
	} else {
		tmp = sin(th) * (sin(ky) / fabs(sin(ky)));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 2.9e-6) {
		tmp = Math.sin(ky) / (Math.hypot(Math.sin(kx), Math.sin(ky)) / th);
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.abs(Math.sin(ky)));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if th <= 2.9e-6:
		tmp = math.sin(ky) / (math.hypot(math.sin(kx), math.sin(ky)) / th)
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.fabs(math.sin(ky)))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (th <= 2.9e-6)
		tmp = Float64(sin(ky) / Float64(hypot(sin(kx), sin(ky)) / th));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / abs(sin(ky))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (th <= 2.9e-6)
		tmp = sin(ky) / (hypot(sin(kx), sin(ky)) / th);
	else
		tmp = sin(th) * (sin(ky) / abs(sin(ky)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[th, 2.9e-6], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[Sin[ky], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 2.9 \cdot 10^{-6}:\\
\;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\


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

Alternative 11: 49.6% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 10^{-53}:\\ \;\;\;\;\sin th \cdot \mathsf{expm1}\left(\frac{ky}{\sin kx}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) 1e-53) (* (sin th) (expm1 (/ ky (sin kx)))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= 1e-53) {
		tmp = sin(th) * expm1((ky / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= 1e-53) {
		tmp = Math.sin(th) * Math.expm1((ky / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= 1e-53:
		tmp = math.sin(th) * math.expm1((ky / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= 1e-53)
		tmp = Float64(sin(th) * expm1(Float64(ky / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-53], N[(N[Sin[th], $MachinePrecision] * N[(Exp[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 10^{-53}:\\
\;\;\;\;\sin th \cdot \mathsf{expm1}\left(\frac{ky}{\sin kx}\right)\\

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


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

Alternative 12: 39.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 9 \cdot 10^{-8}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 9e-8)
   (* (sin th) (fabs (/ (sin ky) (sin kx))))
   (* (sin th) (/ (sin ky) (fabs (sin ky))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 9e-8) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th) * (sin(ky) / fabs(sin(ky)));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 9d-8) then
        tmp = sin(th) * abs((sin(ky) / sin(kx)))
    else
        tmp = sin(th) * (sin(ky) / abs(sin(ky)))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 9e-8) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.abs(Math.sin(ky)));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 9e-8:
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.fabs(math.sin(ky)))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 9e-8)
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / abs(sin(ky))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 9e-8)
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th) * (sin(ky) / abs(sin(ky)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 9e-8], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[Sin[ky], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 9 \cdot 10^{-8}:\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin ky\right|}\\


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

Alternative 13: 31.9% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8.4 \cdot 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 8.4e-7) (* (sin th) (fabs (/ ky (sin kx)))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8.4e-7) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 8.4d-7) then
        tmp = sin(th) * abs((ky / sin(kx)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8.4e-7) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 8.4e-7:
		tmp = math.sin(th) * math.fabs((ky / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 8.4e-7)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 8.4e-7)
		tmp = sin(th) * abs((ky / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 8.4e-7], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 8.4 \cdot 10^{-7}:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

Alternative 14: 33.1% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 3 \cdot 10^{-51}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 3e-51) (* (sin th) (/ ky (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 3e-51) {
		tmp = sin(th) * (ky / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 3d-51) then
        tmp = sin(th) * (ky / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 3e-51) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 3e-51:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 3e-51)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 3e-51)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 3e-51], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 3 \cdot 10^{-51}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

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


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

Alternative 15: 26.8% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.25 \cdot 10^{-149}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.25e-149) (* (sin th) (/ ky kx)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.25e-149) {
		tmp = sin(th) * (ky / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.25d-149) then
        tmp = sin(th) * (ky / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.25e-149) {
		tmp = Math.sin(th) * (ky / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.25e-149:
		tmp = math.sin(th) * (ky / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.25e-149)
		tmp = Float64(sin(th) * Float64(ky / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.25e-149)
		tmp = sin(th) * (ky / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.25e-149], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.25 \cdot 10^{-149}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

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


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

Alternative 16: 26.9% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 2.6 \cdot 10^{-150}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 2.6e-150) (/ (sin th) (/ kx ky)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-150) {
		tmp = sin(th) / (kx / ky);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 2.6d-150) then
        tmp = sin(th) / (kx / ky)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-150) {
		tmp = Math.sin(th) / (kx / ky);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 2.6e-150:
		tmp = math.sin(th) / (kx / ky)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 2.6e-150)
		tmp = Float64(sin(th) / Float64(kx / ky));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 2.6e-150)
		tmp = sin(th) / (kx / ky);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 2.6e-150], N[(N[Sin[th], $MachinePrecision] / N[(kx / ky), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 2.6 \cdot 10^{-150}:\\
\;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\

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


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

Alternative 17: 24.1% accurate, 6.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 4.2 \cdot 10^{-160}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 4.2e-160) (/ ky (/ kx th)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 4.2e-160) {
		tmp = ky / (kx / th);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 4.2d-160) then
        tmp = ky / (kx / th)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 4.2e-160) {
		tmp = ky / (kx / th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 4.2e-160:
		tmp = ky / (kx / th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 4.2e-160)
		tmp = Float64(ky / Float64(kx / th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 4.2e-160)
		tmp = ky / (kx / th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 4.2e-160], N[(ky / N[(kx / th), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 4.2 \cdot 10^{-160}:\\
\;\;\;\;\frac{ky}{\frac{kx}{th}}\\

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


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

Alternative 18: 13.5% accurate, 141.8× speedup?

\[\begin{array}{l} \\ \frac{ky}{\frac{kx}{th}} \end{array} \]
(FPCore (kx ky th) :precision binary64 (/ ky (/ kx th)))
double code(double kx, double ky, double th) {
	return ky / (kx / th);
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = ky / (kx / th)
end function
public static double code(double kx, double ky, double th) {
	return ky / (kx / th);
}
def code(kx, ky, th):
	return ky / (kx / th)
function code(kx, ky, th)
	return Float64(ky / Float64(kx / th))
end
function tmp = code(kx, ky, th)
	tmp = ky / (kx / th);
end
code[kx_, ky_, th_] := N[(ky / N[(kx / th), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Reproduce

?
herbie shell --seed 2024010 
(FPCore (kx ky th)
  :name "Toniolo and Linder, Equation (3b), real"
  :precision binary64
  (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))