Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 21.0s
Alternatives: 17
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 17 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.0% 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
  1. Initial program 89.8%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. +-commutative89.8%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    2. unpow289.8%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow289.8%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    4. hypot-def99.7%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
  4. Final simplification99.7%

    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]

Alternative 2: 65.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;\sin th \leq -0.76:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin th \leq -0.64:\\
\;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}\\

\mathbf{elif}\;\sin th \leq -0.001:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin th \leq 10^{-14}:\\
\;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 th) < -0.76000000000000001 or -0.640000000000000013 < (sin.f64 th) < -1e-3

    1. Initial program 84.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/84.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/83.8%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative83.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow283.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow283.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 14.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod35.5%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow235.5%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr35.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative35.5%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/35.6%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses35.6%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity35.6%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow235.6%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square35.6%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified35.6%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.76000000000000001 < (sin.f64 th) < -0.640000000000000013

    1. Initial program 100.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      2. *-commutative99.5%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
      3. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    6. Taylor expanded in kx around 0 84.3%

      \[\leadsto \frac{\sin th}{\color{blue}{1 + 0.5 \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}}} \]
    7. Step-by-step derivation
      1. associate-*r/84.3%

        \[\leadsto \frac{\sin th}{1 + \color{blue}{\frac{0.5 \cdot {kx}^{2}}{{\sin ky}^{2}}}} \]
      2. unpow284.3%

        \[\leadsto \frac{\sin th}{1 + \frac{0.5 \cdot \color{blue}{\left(kx \cdot kx\right)}}{{\sin ky}^{2}}} \]
    8. Simplified84.3%

      \[\leadsto \frac{\sin th}{\color{blue}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}} \]

    if -1e-3 < (sin.f64 th) < 9.99999999999999999e-15

    1. Initial program 93.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/86.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative86.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow286.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow286.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def89.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.8%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 89.8%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u89.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-udef20.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
      3. *-un-lft-identity20.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\color{blue}{1 \cdot \mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      4. times-frac20.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{1} \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      5. /-rgt-identity20.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\sin ky} \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1 \]
    6. Applied egg-rr20.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
    7. Step-by-step derivation
      1. expm1-def99.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-log1p99.8%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    8. Simplified99.8%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]

    if 9.99999999999999999e-15 < (sin.f64 th)

    1. Initial program 86.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/86.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative86.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow286.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow286.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def99.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 26.1%

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt25.0%

        \[\leadsto \frac{\color{blue}{\sqrt{\sin ky \cdot \sin th} \cdot \sqrt{\sin ky \cdot \sin th}}}{\sin ky} \]
      2. sqrt-unprod45.3%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(\sin ky \cdot \sin th\right) \cdot \left(\sin ky \cdot \sin th\right)}}}{\sin ky} \]
      3. pow245.3%

        \[\leadsto \frac{\sqrt{\color{blue}{{\left(\sin ky \cdot \sin th\right)}^{2}}}}{\sin ky} \]
      4. *-commutative45.3%

        \[\leadsto \frac{\sqrt{{\color{blue}{\left(\sin th \cdot \sin ky\right)}}^{2}}}{\sin ky} \]
    6. Applied egg-rr45.3%

      \[\leadsto \frac{\color{blue}{\sqrt{{\left(\sin th \cdot \sin ky\right)}^{2}}}}{\sin ky} \]
    7. Step-by-step derivation
      1. unpow245.3%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \left(\sin th \cdot \sin ky\right)}}}{\sin ky} \]
      2. rem-sqrt-square47.5%

        \[\leadsto \frac{\color{blue}{\left|\sin th \cdot \sin ky\right|}}{\sin ky} \]
      3. *-commutative47.5%

        \[\leadsto \frac{\left|\color{blue}{\sin ky \cdot \sin th}\right|}{\sin ky} \]
    8. Simplified47.5%

      \[\leadsto \frac{\color{blue}{\left|\sin ky \cdot \sin th\right|}}{\sin ky} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification72.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.76:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq -0.64:\\ \;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}\\ \mathbf{elif}\;\sin th \leq -0.001:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq 10^{-14}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left|\sin ky \cdot \sin th\right|}{\sin ky}\\ \end{array} \]

Alternative 3: 65.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;\sin th \leq -0.76:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin th \leq -0.64:\\
\;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}\\

\mathbf{elif}\;\sin th \leq -0.001:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin th \leq 10^{-14}:\\
\;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 th) < -0.76000000000000001 or -0.640000000000000013 < (sin.f64 th) < -1e-3

    1. Initial program 84.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/84.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/83.8%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative83.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow283.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow283.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 14.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod35.5%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow235.5%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr35.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative35.5%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/35.6%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses35.6%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity35.6%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow235.6%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square35.6%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified35.6%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.76000000000000001 < (sin.f64 th) < -0.640000000000000013

    1. Initial program 100.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      2. *-commutative99.5%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
      3. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    6. Taylor expanded in kx around 0 84.3%

      \[\leadsto \frac{\sin th}{\color{blue}{1 + 0.5 \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}}} \]
    7. Step-by-step derivation
      1. associate-*r/84.3%

        \[\leadsto \frac{\sin th}{1 + \color{blue}{\frac{0.5 \cdot {kx}^{2}}{{\sin ky}^{2}}}} \]
      2. unpow284.3%

        \[\leadsto \frac{\sin th}{1 + \frac{0.5 \cdot \color{blue}{\left(kx \cdot kx\right)}}{{\sin ky}^{2}}} \]
    8. Simplified84.3%

      \[\leadsto \frac{\sin th}{\color{blue}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}} \]

    if -1e-3 < (sin.f64 th) < 9.99999999999999999e-15

    1. Initial program 93.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/86.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative86.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow286.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow286.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def89.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.8%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 89.8%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}} \]
      2. associate-/r/99.8%

        \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th} \]
    6. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th} \]

    if 9.99999999999999999e-15 < (sin.f64 th)

    1. Initial program 86.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/86.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative86.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow286.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow286.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def99.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 26.1%

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt25.0%

        \[\leadsto \frac{\color{blue}{\sqrt{\sin ky \cdot \sin th} \cdot \sqrt{\sin ky \cdot \sin th}}}{\sin ky} \]
      2. sqrt-unprod45.3%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(\sin ky \cdot \sin th\right) \cdot \left(\sin ky \cdot \sin th\right)}}}{\sin ky} \]
      3. pow245.3%

        \[\leadsto \frac{\sqrt{\color{blue}{{\left(\sin ky \cdot \sin th\right)}^{2}}}}{\sin ky} \]
      4. *-commutative45.3%

        \[\leadsto \frac{\sqrt{{\color{blue}{\left(\sin th \cdot \sin ky\right)}}^{2}}}{\sin ky} \]
    6. Applied egg-rr45.3%

      \[\leadsto \frac{\color{blue}{\sqrt{{\left(\sin th \cdot \sin ky\right)}^{2}}}}{\sin ky} \]
    7. Step-by-step derivation
      1. unpow245.3%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \left(\sin th \cdot \sin ky\right)}}}{\sin ky} \]
      2. rem-sqrt-square47.5%

        \[\leadsto \frac{\color{blue}{\left|\sin th \cdot \sin ky\right|}}{\sin ky} \]
      3. *-commutative47.5%

        \[\leadsto \frac{\left|\color{blue}{\sin ky \cdot \sin th}\right|}{\sin ky} \]
    8. Simplified47.5%

      \[\leadsto \frac{\color{blue}{\left|\sin ky \cdot \sin th\right|}}{\sin ky} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification72.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.76:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq -0.64:\\ \;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{{\sin ky}^{2}}}\\ \mathbf{elif}\;\sin th \leq -0.001:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq 10^{-14}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\frac{\left|\sin ky \cdot \sin th\right|}{\sin ky}\\ \end{array} \]

Alternative 4: 47.0% accurate, 1.0× speedup?

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

\mathbf{elif}\;\sin ky \leq -0.71:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -0.02:\\
\;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\
\;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if (sin.f64 ky) < -0.96999999999999997

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 1.7%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod58.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow258.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr58.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses58.7%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity58.7%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow258.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square58.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified58.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -0.70999999999999996

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt2.2%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod18.9%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow218.9%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr18.9%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative18.9%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/18.9%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses18.9%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity18.9%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified18.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 9.0%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow29.0%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified9.0%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 52.1%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-152.1%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified52.1%

      \[\leadsto \color{blue}{-th} \]

    if -0.70999999999999996 < (sin.f64 ky) < -0.0200000000000000004

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.8%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.8%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 2.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.1%

        \[\leadsto \sin ky \cdot \color{blue}{\left(\sqrt{\frac{\sin th}{\sin ky}} \cdot \sqrt{\frac{\sin th}{\sin ky}}\right)} \]
      2. sqrt-unprod36.1%

        \[\leadsto \sin ky \cdot \color{blue}{\sqrt{\frac{\sin th}{\sin ky} \cdot \frac{\sin th}{\sin ky}}} \]
      3. pow236.1%

        \[\leadsto \sin ky \cdot \sqrt{\color{blue}{{\left(\frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr36.1%

      \[\leadsto \sin ky \cdot \color{blue}{\sqrt{{\left(\frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. unpow236.1%

        \[\leadsto \sin ky \cdot \sqrt{\color{blue}{\frac{\sin th}{\sin ky} \cdot \frac{\sin th}{\sin ky}}} \]
      2. rem-sqrt-square39.7%

        \[\leadsto \sin ky \cdot \color{blue}{\left|\frac{\sin th}{\sin ky}\right|} \]
    8. Simplified39.7%

      \[\leadsto \sin ky \cdot \color{blue}{\left|\frac{\sin th}{\sin ky}\right|} \]

    if -0.0200000000000000004 < (sin.f64 ky) < -5.0000000000000001e-181

    1. Initial program 97.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative88.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow288.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow288.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def90.9%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 46.4%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Taylor expanded in ky around 0 46.4%

      \[\leadsto \frac{\color{blue}{th \cdot ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

    if -5.0000000000000001e-181 < (sin.f64 ky) < 5e-206

    1. Initial program 65.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-commutative65.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.7%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Taylor expanded in ky around 0 63.2%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 6 regimes into one program.
  4. Final simplification54.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.71:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -0.02:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 5: 47.0% accurate, 1.0× speedup?

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

\mathbf{elif}\;\sin ky \leq -0.71:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -0.02:\\
\;\;\;\;\frac{\left|\sin ky \cdot \sin th\right|}{\sin ky}\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\
\;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if (sin.f64 ky) < -0.96999999999999997

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 1.7%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod58.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow258.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr58.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses58.7%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity58.7%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow258.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square58.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified58.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -0.70999999999999996

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt2.2%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod18.9%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow218.9%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr18.9%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative18.9%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/18.9%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses18.9%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity18.9%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified18.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 9.0%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow29.0%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified9.0%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 52.1%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-152.1%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified52.1%

      \[\leadsto \color{blue}{-th} \]

    if -0.70999999999999996 < (sin.f64 ky) < -0.0200000000000000004

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative99.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow299.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def99.7%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 2.6%

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.1%

        \[\leadsto \frac{\color{blue}{\sqrt{\sin ky \cdot \sin th} \cdot \sqrt{\sin ky \cdot \sin th}}}{\sin ky} \]
      2. sqrt-unprod36.2%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(\sin ky \cdot \sin th\right) \cdot \left(\sin ky \cdot \sin th\right)}}}{\sin ky} \]
      3. pow236.2%

        \[\leadsto \frac{\sqrt{\color{blue}{{\left(\sin ky \cdot \sin th\right)}^{2}}}}{\sin ky} \]
      4. *-commutative36.2%

        \[\leadsto \frac{\sqrt{{\color{blue}{\left(\sin th \cdot \sin ky\right)}}^{2}}}{\sin ky} \]
    6. Applied egg-rr36.2%

      \[\leadsto \frac{\color{blue}{\sqrt{{\left(\sin th \cdot \sin ky\right)}^{2}}}}{\sin ky} \]
    7. Step-by-step derivation
      1. unpow236.2%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \left(\sin th \cdot \sin ky\right)}}}{\sin ky} \]
      2. rem-sqrt-square39.8%

        \[\leadsto \frac{\color{blue}{\left|\sin th \cdot \sin ky\right|}}{\sin ky} \]
      3. *-commutative39.8%

        \[\leadsto \frac{\left|\color{blue}{\sin ky \cdot \sin th}\right|}{\sin ky} \]
    8. Simplified39.8%

      \[\leadsto \frac{\color{blue}{\left|\sin ky \cdot \sin th\right|}}{\sin ky} \]

    if -0.0200000000000000004 < (sin.f64 ky) < -5.0000000000000001e-181

    1. Initial program 97.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative88.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow288.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow288.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def90.9%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified90.9%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 46.4%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Taylor expanded in ky around 0 46.4%

      \[\leadsto \frac{\color{blue}{th \cdot ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

    if -5.0000000000000001e-181 < (sin.f64 ky) < 5e-206

    1. Initial program 65.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-commutative65.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.7%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Taylor expanded in ky around 0 63.2%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 6 regimes into one program.
  4. Final simplification54.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.71:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -0.02:\\ \;\;\;\;\frac{\left|\sin ky \cdot \sin th\right|}{\sin ky}\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 43.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.97)
   (fabs (sin th))
   (if (<= (sin ky) -5e-30)
     (- th)
     (if (<= (sin ky) -2e-189)
       (sqrt (pow (sin th) 2.0))
       (if (<= (sin ky) 5e-206)
         (/ (sin ky) (/ (sin kx) (sin th)))
         (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.97) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -5e-30) {
		tmp = -th;
	} else if (sin(ky) <= -2e-189) {
		tmp = sqrt(pow(sin(th), 2.0));
	} else if (sin(ky) <= 5e-206) {
		tmp = sin(ky) / (sin(kx) / sin(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 (sin(ky) <= (-0.97d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= (-5d-30)) then
        tmp = -th
    else if (sin(ky) <= (-2d-189)) then
        tmp = sqrt((sin(th) ** 2.0d0))
    else if (sin(ky) <= 5d-206) then
        tmp = sin(ky) / (sin(kx) / sin(th))
    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.97) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -5e-30) {
		tmp = -th;
	} else if (Math.sin(ky) <= -2e-189) {
		tmp = Math.sqrt(Math.pow(Math.sin(th), 2.0));
	} else if (Math.sin(ky) <= 5e-206) {
		tmp = Math.sin(ky) / (Math.sin(kx) / Math.sin(th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.97:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -5e-30:
		tmp = -th
	elif math.sin(ky) <= -2e-189:
		tmp = math.sqrt(math.pow(math.sin(th), 2.0))
	elif math.sin(ky) <= 5e-206:
		tmp = math.sin(ky) / (math.sin(kx) / math.sin(th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.97)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -5e-30)
		tmp = Float64(-th);
	elseif (sin(ky) <= -2e-189)
		tmp = sqrt((sin(th) ^ 2.0));
	elseif (sin(ky) <= 5e-206)
		tmp = Float64(sin(ky) / Float64(sin(kx) / sin(th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.97)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -5e-30)
		tmp = -th;
	elseif (sin(ky) <= -2e-189)
		tmp = sqrt((sin(th) ^ 2.0));
	elseif (sin(ky) <= 5e-206)
		tmp = sin(ky) / (sin(kx) / sin(th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.97], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -5e-30], (-th), If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-189], N[Sqrt[N[Power[N[Sin[th], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-206], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.97:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\
\;\;\;\;\sqrt{{\sin th}^{2}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 ky) < -0.96999999999999997

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 1.7%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod58.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow258.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr58.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses58.7%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity58.7%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow258.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square58.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified58.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -4.99999999999999972e-30

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod21.8%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow221.8%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative21.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/21.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses21.8%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity21.8%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified21.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 11.4%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow211.4%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified11.4%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 39.5%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-139.5%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified39.5%

      \[\leadsto \color{blue}{-th} \]

    if -4.99999999999999972e-30 < (sin.f64 ky) < -2.00000000000000014e-189

    1. Initial program 91.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/81.9%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/91.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative91.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod47.0%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow247.0%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr47.0%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative47.0%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/47.1%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses47.1%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity47.1%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified47.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]

    if -2.00000000000000014e-189 < (sin.f64 ky) < 5e-206

    1. Initial program 66.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-/r/66.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin th}}} \]
      2. +-commutative66.2%

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin th}} \]
      3. unpow266.2%

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin th}} \]
      4. unpow266.2%

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin th}} \]
      5. hypot-def99.6%

        \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\sin th}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    4. Taylor expanded in ky around 0 64.2%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin kx}}{\sin th}} \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification53.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 7: 73.4% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;\sin th \leq 2 \cdot 10^{-22}:\\
\;\;\;\;\frac{\sin ky}{t_1} \cdot th\\

\mathbf{elif}\;\sin th \leq 0.75:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 th) < -0.0200000000000000004 or 2.0000000000000001e-22 < (sin.f64 th) < 0.75

    1. Initial program 81.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/81.8%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative81.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow281.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow281.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def99.6%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in ky around 0 59.8%

      \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

    if -0.0200000000000000004 < (sin.f64 th) < 2.0000000000000001e-22

    1. Initial program 94.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/87.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative87.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow287.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow287.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def89.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.8%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 88.4%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Step-by-step derivation
      1. associate-/l*98.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}} \]
      2. associate-/r/98.3%

        \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th} \]
    6. Applied egg-rr98.3%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th} \]

    if 0.75 < (sin.f64 th)

    1. Initial program 95.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative96.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow296.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow296.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def99.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 32.2%

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt31.2%

        \[\leadsto \frac{\color{blue}{\sqrt{\sin ky \cdot \sin th} \cdot \sqrt{\sin ky \cdot \sin th}}}{\sin ky} \]
      2. sqrt-unprod52.3%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(\sin ky \cdot \sin th\right) \cdot \left(\sin ky \cdot \sin th\right)}}}{\sin ky} \]
      3. pow252.3%

        \[\leadsto \frac{\sqrt{\color{blue}{{\left(\sin ky \cdot \sin th\right)}^{2}}}}{\sin ky} \]
      4. *-commutative52.3%

        \[\leadsto \frac{\sqrt{{\color{blue}{\left(\sin th \cdot \sin ky\right)}}^{2}}}{\sin ky} \]
    6. Applied egg-rr52.3%

      \[\leadsto \frac{\color{blue}{\sqrt{{\left(\sin th \cdot \sin ky\right)}^{2}}}}{\sin ky} \]
    7. Step-by-step derivation
      1. unpow252.3%

        \[\leadsto \frac{\sqrt{\color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \left(\sin th \cdot \sin ky\right)}}}{\sin ky} \]
      2. rem-sqrt-square55.7%

        \[\leadsto \frac{\color{blue}{\left|\sin th \cdot \sin ky\right|}}{\sin ky} \]
      3. *-commutative55.7%

        \[\leadsto \frac{\left|\color{blue}{\sin ky \cdot \sin th}\right|}{\sin ky} \]
    8. Simplified55.7%

      \[\leadsto \frac{\color{blue}{\left|\sin ky \cdot \sin th\right|}}{\sin ky} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification79.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.02:\\ \;\;\;\;\frac{ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin th \leq 2 \cdot 10^{-22}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \mathbf{elif}\;\sin th \leq 0.75:\\ \;\;\;\;\frac{ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left|\sin ky \cdot \sin th\right|}{\sin ky}\\ \end{array} \]

Alternative 8: 43.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq -0.04:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))))
   (if (<= (sin ky) -0.97)
     t_1
     (if (<= (sin ky) -0.04)
       (- th)
       (if (<= (sin ky) -5e-127)
         t_1
         (if (<= (sin ky) 5e-206) (* (sin th) (/ ky (sin kx))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double tmp;
	if (sin(ky) <= -0.97) {
		tmp = t_1;
	} else if (sin(ky) <= -0.04) {
		tmp = -th;
	} else if (sin(ky) <= -5e-127) {
		tmp = t_1;
	} else if (sin(ky) <= 5e-206) {
		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) :: t_1
    real(8) :: tmp
    t_1 = abs(sin(th))
    if (sin(ky) <= (-0.97d0)) then
        tmp = t_1
    else if (sin(ky) <= (-0.04d0)) then
        tmp = -th
    else if (sin(ky) <= (-5d-127)) then
        tmp = t_1
    else if (sin(ky) <= 5d-206) 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 t_1 = Math.abs(Math.sin(th));
	double tmp;
	if (Math.sin(ky) <= -0.97) {
		tmp = t_1;
	} else if (Math.sin(ky) <= -0.04) {
		tmp = -th;
	} else if (Math.sin(ky) <= -5e-127) {
		tmp = t_1;
	} else if (Math.sin(ky) <= 5e-206) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	tmp = 0
	if math.sin(ky) <= -0.97:
		tmp = t_1
	elif math.sin(ky) <= -0.04:
		tmp = -th
	elif math.sin(ky) <= -5e-127:
		tmp = t_1
	elif math.sin(ky) <= 5e-206:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	tmp = 0.0
	if (sin(ky) <= -0.97)
		tmp = t_1;
	elseif (sin(ky) <= -0.04)
		tmp = Float64(-th);
	elseif (sin(ky) <= -5e-127)
		tmp = t_1;
	elseif (sin(ky) <= 5e-206)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	tmp = 0.0;
	if (sin(ky) <= -0.97)
		tmp = t_1;
	elseif (sin(ky) <= -0.04)
		tmp = -th;
	elseif (sin(ky) <= -5e-127)
		tmp = t_1;
	elseif (sin(ky) <= 5e-206)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -0.97], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], -0.04], (-th), If[LessEqual[N[Sin[ky], $MachinePrecision], -5e-127], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-206], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;\sin ky \leq -0.97:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq -0.04:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-127}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -0.96999999999999997 or -0.0400000000000000008 < (sin.f64 ky) < -4.9999999999999997e-127

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 2.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod41.3%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow241.3%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr41.3%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative41.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/41.4%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses41.4%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity41.4%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow241.4%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square43.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified43.8%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -0.0400000000000000008

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod22.3%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow222.3%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr22.3%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative22.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/22.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses22.3%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity22.3%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified22.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 12.2%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow212.2%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified12.2%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 42.5%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-142.5%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified42.5%

      \[\leadsto \color{blue}{-th} \]

    if -4.9999999999999997e-127 < (sin.f64 ky) < 5e-206

    1. Initial program 68.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-commutative68.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow268.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow268.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.8%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Taylor expanded in ky around 0 60.1%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.04:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-127}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 9: 43.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.97)
   (fabs (sin th))
   (if (<= (sin ky) -5e-30)
     (- th)
     (if (<= (sin ky) -2e-189)
       (sqrt (pow (sin th) 2.0))
       (if (<= (sin ky) 5e-206) (* (sin th) (/ ky (sin kx))) (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.97) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -5e-30) {
		tmp = -th;
	} else if (sin(ky) <= -2e-189) {
		tmp = sqrt(pow(sin(th), 2.0));
	} else if (sin(ky) <= 5e-206) {
		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 (sin(ky) <= (-0.97d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= (-5d-30)) then
        tmp = -th
    else if (sin(ky) <= (-2d-189)) then
        tmp = sqrt((sin(th) ** 2.0d0))
    else if (sin(ky) <= 5d-206) 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 (Math.sin(ky) <= -0.97) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -5e-30) {
		tmp = -th;
	} else if (Math.sin(ky) <= -2e-189) {
		tmp = Math.sqrt(Math.pow(Math.sin(th), 2.0));
	} else if (Math.sin(ky) <= 5e-206) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.97:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -5e-30:
		tmp = -th
	elif math.sin(ky) <= -2e-189:
		tmp = math.sqrt(math.pow(math.sin(th), 2.0))
	elif math.sin(ky) <= 5e-206:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.97)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -5e-30)
		tmp = Float64(-th);
	elseif (sin(ky) <= -2e-189)
		tmp = sqrt((sin(th) ^ 2.0));
	elseif (sin(ky) <= 5e-206)
		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 (sin(ky) <= -0.97)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -5e-30)
		tmp = -th;
	elseif (sin(ky) <= -2e-189)
		tmp = sqrt((sin(th) ^ 2.0));
	elseif (sin(ky) <= 5e-206)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.97], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -5e-30], (-th), If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-189], N[Sqrt[N[Power[N[Sin[th], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-206], 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}\;\sin ky \leq -0.97:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\
\;\;\;\;\sqrt{{\sin th}^{2}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 ky) < -0.96999999999999997

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 1.7%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod58.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow258.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr58.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses58.7%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity58.7%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow258.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square58.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified58.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -4.99999999999999972e-30

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod21.8%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow221.8%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative21.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/21.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses21.8%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity21.8%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified21.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 11.4%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow211.4%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified11.4%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 39.5%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-139.5%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified39.5%

      \[\leadsto \color{blue}{-th} \]

    if -4.99999999999999972e-30 < (sin.f64 ky) < -2.00000000000000014e-189

    1. Initial program 91.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/81.9%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/91.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative91.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod47.0%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow247.0%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr47.0%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative47.0%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/47.1%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses47.1%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity47.1%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified47.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]

    if -2.00000000000000014e-189 < (sin.f64 ky) < 5e-206

    1. Initial program 66.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-commutative66.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow266.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow266.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.7%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Taylor expanded in ky around 0 64.1%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification53.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-30}:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-189}:\\ \;\;\;\;\sqrt{{\sin th}^{2}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 10: 46.2% accurate, 1.2× speedup?

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

\mathbf{elif}\;\sin ky \leq -0.04:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\
\;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 ky) < -0.96999999999999997

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 1.7%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt0.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod58.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow258.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr58.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/58.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses58.7%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity58.7%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow258.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square58.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified58.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.96999999999999997 < (sin.f64 ky) < -0.0400000000000000008

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.0%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod22.3%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow222.3%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr22.3%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative22.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/22.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses22.3%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity22.3%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified22.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 12.2%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow212.2%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified12.2%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 42.5%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-142.5%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified42.5%

      \[\leadsto \color{blue}{-th} \]

    if -0.0400000000000000008 < (sin.f64 ky) < -5.0000000000000001e-181

    1. Initial program 97.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.8%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative88.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow288.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow288.8%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def91.4%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified91.4%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 44.0%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Taylor expanded in ky around 0 44.2%

      \[\leadsto \frac{\color{blue}{th \cdot ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

    if -5.0000000000000001e-181 < (sin.f64 ky) < 5e-206

    1. Initial program 65.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-commutative65.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow265.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.7%

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Taylor expanded in ky around 0 63.2%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

    if 5e-206 < (sin.f64 ky)

    1. Initial program 94.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/94.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative94.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 57.3%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification53.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.97:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.04:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-181}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-206}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 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
  1. Initial program 89.8%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. associate-*l/86.1%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    2. associate-*r/89.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    3. +-commutative89.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
    4. unpow289.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
    5. unpow289.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
    6. hypot-def99.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  3. Simplified99.6%

    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  4. Final simplification99.6%

    \[\leadsto \sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

Alternative 12: 31.0% accurate, 3.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -2.3 \cdot 10^{-189}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq 1.2 \cdot 10^{-236}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -2.3e-189)
   (fabs (sin th))
   (if (<= ky 1.2e-236) (/ ky (/ (sin kx) th)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -2.3e-189) {
		tmp = fabs(sin(th));
	} else if (ky <= 1.2e-236) {
		tmp = ky / (sin(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 <= (-2.3d-189)) then
        tmp = abs(sin(th))
    else if (ky <= 1.2d-236) then
        tmp = ky / (sin(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 <= -2.3e-189) {
		tmp = Math.abs(Math.sin(th));
	} else if (ky <= 1.2e-236) {
		tmp = ky / (Math.sin(kx) / th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -2.3e-189:
		tmp = math.fabs(math.sin(th))
	elif ky <= 1.2e-236:
		tmp = ky / (math.sin(kx) / th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -2.3e-189)
		tmp = abs(sin(th));
	elseif (ky <= 1.2e-236)
		tmp = Float64(ky / Float64(sin(kx) / th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -2.3e-189)
		tmp = abs(sin(th));
	elseif (ky <= 1.2e-236)
		tmp = ky / (sin(kx) / th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -2.3e-189], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[ky, 1.2e-236], N[(ky / N[(N[Sin[kx], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -2.3 \cdot 10^{-189}:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;ky \leq 1.2 \cdot 10^{-236}:\\
\;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -2.2999999999999998e-189

    1. Initial program 97.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/94.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/96.9%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative96.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow296.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow296.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 21.9%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt11.9%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod37.1%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow237.1%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr37.1%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative37.1%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/37.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses37.2%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity37.2%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
      5. unpow237.2%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      6. rem-sqrt-square37.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified37.8%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -2.2999999999999998e-189 < ky < 1.2000000000000001e-236

    1. Initial program 66.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/60.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative60.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow260.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow260.3%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def89.2%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.2%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 35.8%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Taylor expanded in ky around 0 35.4%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    6. Step-by-step derivation
      1. associate-/l*43.6%

        \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    7. Simplified43.6%

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]

    if 1.2000000000000001e-236 < ky

    1. Initial program 92.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.9%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/92.2%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative92.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow292.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow292.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 37.0%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification38.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.3 \cdot 10^{-189}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq 1.2 \cdot 10^{-236}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 13: 31.3% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.4 \cdot 10^{-114}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 7 \cdot 10^{-237}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -1.9e+33)
   (sin th)
   (if (<= ky -1.4e-114)
     (- th)
     (if (<= ky 7e-237) (/ ky (/ (sin kx) th)) (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -1.9e+33) {
		tmp = sin(th);
	} else if (ky <= -1.4e-114) {
		tmp = -th;
	} else if (ky <= 7e-237) {
		tmp = ky / (sin(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 <= (-1.9d+33)) then
        tmp = sin(th)
    else if (ky <= (-1.4d-114)) then
        tmp = -th
    else if (ky <= 7d-237) then
        tmp = ky / (sin(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 <= -1.9e+33) {
		tmp = Math.sin(th);
	} else if (ky <= -1.4e-114) {
		tmp = -th;
	} else if (ky <= 7e-237) {
		tmp = ky / (Math.sin(kx) / th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -1.9e+33:
		tmp = math.sin(th)
	elif ky <= -1.4e-114:
		tmp = -th
	elif ky <= 7e-237:
		tmp = ky / (math.sin(kx) / th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -1.9e+33)
		tmp = sin(th);
	elseif (ky <= -1.4e-114)
		tmp = Float64(-th);
	elseif (ky <= 7e-237)
		tmp = Float64(ky / Float64(sin(kx) / th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -1.9e+33)
		tmp = sin(th);
	elseif (ky <= -1.4e-114)
		tmp = -th;
	elseif (ky <= 7e-237)
		tmp = ky / (sin(kx) / th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -1.9e+33], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -1.4e-114], (-th), If[LessEqual[ky, 7e-237], N[(ky / N[(N[Sin[kx], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -1.4 \cdot 10^{-114}:\\
\;\;\;\;-th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -1.90000000000000001e33 or 6.99999999999999966e-237 < ky

    1. Initial program 95.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/93.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/95.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 35.9%

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

    if -1.90000000000000001e33 < ky < -1.4000000000000001e-114

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/94.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.2%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.9%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod32.2%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow232.2%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr32.2%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative32.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/32.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses32.3%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity32.3%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified32.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 20.2%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow220.2%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified20.2%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 32.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-132.6%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified32.6%

      \[\leadsto \color{blue}{-th} \]

    if -1.4000000000000001e-114 < ky < 6.99999999999999966e-237

    1. Initial program 71.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/63.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. +-commutative63.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      3. unpow263.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow263.5%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def89.1%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.1%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in th around 0 36.6%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]
    5. Taylor expanded in ky around 0 33.0%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    6. Step-by-step derivation
      1. associate-/l*38.8%

        \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    7. Simplified38.8%

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification36.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.4 \cdot 10^{-114}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 7 \cdot 10^{-237}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 14: 29.5% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.85 \cdot 10^{-115}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 3 \cdot 10^{-251}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -1.9e+33)
   (sin th)
   (if (<= ky -1.85e-115) (- th) (if (<= ky 3e-251) 0.0 (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -1.9e+33) {
		tmp = sin(th);
	} else if (ky <= -1.85e-115) {
		tmp = -th;
	} else if (ky <= 3e-251) {
		tmp = 0.0;
	} 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.9d+33)) then
        tmp = sin(th)
    else if (ky <= (-1.85d-115)) then
        tmp = -th
    else if (ky <= 3d-251) then
        tmp = 0.0d0
    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.9e+33) {
		tmp = Math.sin(th);
	} else if (ky <= -1.85e-115) {
		tmp = -th;
	} else if (ky <= 3e-251) {
		tmp = 0.0;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -1.9e+33:
		tmp = math.sin(th)
	elif ky <= -1.85e-115:
		tmp = -th
	elif ky <= 3e-251:
		tmp = 0.0
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -1.9e+33)
		tmp = sin(th);
	elseif (ky <= -1.85e-115)
		tmp = Float64(-th);
	elseif (ky <= 3e-251)
		tmp = 0.0;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -1.9e+33)
		tmp = sin(th);
	elseif (ky <= -1.85e-115)
		tmp = -th;
	elseif (ky <= 3e-251)
		tmp = 0.0;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -1.9e+33], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -1.85e-115], (-th), If[LessEqual[ky, 3e-251], 0.0, N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -1.85 \cdot 10^{-115}:\\
\;\;\;\;-th\\

\mathbf{elif}\;ky \leq 3 \cdot 10^{-251}:\\
\;\;\;\;0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -1.90000000000000001e33 or 2.9999999999999999e-251 < ky

    1. Initial program 93.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/93.4%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative93.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow293.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow293.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 35.4%

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

    if -1.90000000000000001e33 < ky < -1.85e-115

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/94.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.2%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.9%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod32.2%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow232.2%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr32.2%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative32.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/32.3%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses32.3%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity32.3%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified32.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 20.2%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow220.2%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified20.2%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 32.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-132.6%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified32.6%

      \[\leadsto \color{blue}{-th} \]

    if -1.85e-115 < ky < 2.9999999999999999e-251

    1. Initial program 74.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/66.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/74.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative74.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow274.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow274.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 3.9%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt2.2%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod33.2%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow233.2%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr33.2%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative33.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/33.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses33.2%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity33.2%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified33.2%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. sqrt-pow13.9%

        \[\leadsto \color{blue}{{\sin th}^{\left(\frac{2}{2}\right)}} \]
      2. metadata-eval3.9%

        \[\leadsto {\sin th}^{\color{blue}{1}} \]
      3. pow13.9%

        \[\leadsto \color{blue}{\sin th} \]
      4. expm1-log1p-u3.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
      5. expm1-udef28.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
    10. Applied egg-rr28.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
    11. Taylor expanded in th around 0 30.0%

      \[\leadsto \color{blue}{1} - 1 \]
  3. Recombined 3 regimes into one program.
  4. Final simplification33.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.9 \cdot 10^{+33}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.85 \cdot 10^{-115}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 3 \cdot 10^{-251}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 15: 20.4% accurate, 138.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -6.2 \cdot 10^{-114}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 2.6 \cdot 10^{-244}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -6.2e-114) (- th) (if (<= ky 2.6e-244) 0.0 th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -6.2e-114) {
		tmp = -th;
	} else if (ky <= 2.6e-244) {
		tmp = 0.0;
	} else {
		tmp = 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 <= (-6.2d-114)) then
        tmp = -th
    else if (ky <= 2.6d-244) then
        tmp = 0.0d0
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -6.2e-114) {
		tmp = -th;
	} else if (ky <= 2.6e-244) {
		tmp = 0.0;
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -6.2e-114:
		tmp = -th
	elif ky <= 2.6e-244:
		tmp = 0.0
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -6.2e-114)
		tmp = Float64(-th);
	elseif (ky <= 2.6e-244)
		tmp = 0.0;
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -6.2e-114)
		tmp = -th;
	elseif (ky <= 2.6e-244)
		tmp = 0.0;
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -6.2e-114], (-th), If[LessEqual[ky, 2.6e-244], 0.0, th]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -6.2 \cdot 10^{-114}:\\
\;\;\;\;-th\\

\mathbf{elif}\;ky \leq 2.6 \cdot 10^{-244}:\\
\;\;\;\;0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -6.2e-114

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 25.4%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt13.9%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod34.7%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow234.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr34.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative34.7%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/34.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses34.8%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity34.8%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified34.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 14.0%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow214.0%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified14.0%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 25.9%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-125.9%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified25.9%

      \[\leadsto \color{blue}{-th} \]

    if -6.2e-114 < ky < 2.6000000000000001e-244

    1. Initial program 72.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/64.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/72.2%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative72.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow272.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow272.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 4.1%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt2.5%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod32.4%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow232.4%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr32.4%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative32.4%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/32.4%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses32.4%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity32.4%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified32.4%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. sqrt-pow14.1%

        \[\leadsto \color{blue}{{\sin th}^{\left(\frac{2}{2}\right)}} \]
      2. metadata-eval4.1%

        \[\leadsto {\sin th}^{\color{blue}{1}} \]
      3. pow14.1%

        \[\leadsto \color{blue}{\sin th} \]
      4. expm1-log1p-u4.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
      5. expm1-udef28.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
    10. Applied egg-rr28.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
    11. Taylor expanded in th around 0 29.1%

      \[\leadsto \color{blue}{1} - 1 \]

    if 2.6000000000000001e-244 < ky

    1. Initial program 91.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/91.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative91.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow291.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow291.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 36.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Taylor expanded in th around 0 23.4%

      \[\leadsto \color{blue}{th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.2 \cdot 10^{-114}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 2.6 \cdot 10^{-244}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 16: 16.1% accurate, 174.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8 \cdot 10^{-246}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= ky 8e-246) (- th) th))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8e-246) {
		tmp = -th;
	} else {
		tmp = 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 <= 8d-246) then
        tmp = -th
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8e-246) {
		tmp = -th;
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 8e-246:
		tmp = -th
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 8e-246)
		tmp = Float64(-th);
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 8e-246)
		tmp = -th;
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 8e-246], (-th), th]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 8 \cdot 10^{-246}:\\
\;\;\;\;-th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 7.99999999999999965e-246

    1. Initial program 88.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/84.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/88.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative88.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow288.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow288.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 16.9%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt9.3%

        \[\leadsto \color{blue}{\sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}} \cdot \sqrt{\sin ky \cdot \frac{\sin th}{\sin ky}}} \]
      2. sqrt-unprod33.8%

        \[\leadsto \color{blue}{\sqrt{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right) \cdot \left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}} \]
      3. pow233.8%

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    6. Applied egg-rr33.8%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
    7. Step-by-step derivation
      1. *-commutative33.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\sin ky} \cdot \sin ky\right)}}^{2}} \]
      2. associate-/r/33.8%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{\frac{\sin ky}{\sin ky}}\right)}}^{2}} \]
      3. *-inverses33.8%

        \[\leadsto \sqrt{{\left(\frac{\sin th}{\color{blue}{1}}\right)}^{2}} \]
      4. /-rgt-identity33.8%

        \[\leadsto \sqrt{{\color{blue}{\sin th}}^{2}} \]
    8. Simplified33.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Taylor expanded in th around 0 17.0%

      \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow217.0%

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    11. Simplified17.0%

      \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
    12. Taylor expanded in th around -inf 17.9%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    13. Step-by-step derivation
      1. neg-mul-117.9%

        \[\leadsto \color{blue}{-th} \]
    14. Simplified17.9%

      \[\leadsto \color{blue}{-th} \]

    if 7.99999999999999965e-246 < ky

    1. Initial program 91.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/88.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-*r/91.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. +-commutative91.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      4. unpow291.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow291.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Taylor expanded in kx around 0 36.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    5. Taylor expanded in th around 0 23.4%

      \[\leadsto \color{blue}{th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification20.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 8 \cdot 10^{-246}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 17: 13.0% accurate, 709.0× speedup?

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

\\
th
\end{array}
Derivation
  1. Initial program 89.8%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. associate-*l/86.1%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    2. associate-*r/89.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    3. +-commutative89.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
    4. unpow289.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
    5. unpow289.7%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
    6. hypot-def99.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  3. Simplified99.6%

    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  4. Taylor expanded in kx around 0 25.1%

    \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
  5. Taylor expanded in th around 0 15.3%

    \[\leadsto \color{blue}{th} \]
  6. Final simplification15.3%

    \[\leadsto th \]

Reproduce

?
herbie shell --seed 2023175 
(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)))