Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 25.4s
Alternatives: 19
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 19 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: 93.8% 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 92.4%

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

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

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

      \[\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: 66.5% accurate, 0.9× speedup?

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

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

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

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

\mathbf{elif}\;\sin th \leq 0.735:\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

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


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

    1. Initial program 92.9%

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

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

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

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

        \[\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 kx around 0 24.5%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/24.5%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity24.5%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod31.3%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.3%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    7. Step-by-step derivation
      1. unpow231.3%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square31.3%

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

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

    if -0.54000000000000004 < (sin.f64 th) < -0.0050000000000000001

    1. Initial program 96.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow221.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      2. rem-sqrt-square32.4%

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

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

    if -0.0050000000000000001 < (sin.f64 th) < 2.00000000000000012e-9

    1. Initial program 89.2%

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow285.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 89.0%

      \[\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.0%

        \[\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-udef17.0%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(th \cdot \sin ky\right)} \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1 \]
      5. associate-*l*17.0%

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

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

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

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

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

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

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

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

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

    if 2.00000000000000012e-9 < (sin.f64 th) < 0.734999999999999987

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.734999999999999987 < (sin.f64 th)

    1. Initial program 99.5%

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Taylor expanded in ky around inf 34.2%

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{\sin ky}}} \]
      2. associate-/r/34.2%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    7. Simplified34.2%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin th}{\sin kx} \cdot \frac{\sin th}{\sin kx}}} \cdot \sin ky \]
      3. pow247.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin th}{\sin kx} \cdot \frac{\sin th}{\sin kx}}} \cdot \sin ky \]
      2. rem-sqrt-square47.6%

        \[\leadsto \color{blue}{\left|\frac{\sin th}{\sin kx}\right|} \cdot \sin ky \]
    11. Simplified47.6%

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

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

Alternative 3: 66.6% accurate, 0.9× speedup?

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

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

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

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

\mathbf{elif}\;\sin th \leq 0.735:\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

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


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

    1. Initial program 92.9%

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

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

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

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

        \[\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 kx around 0 24.5%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/24.5%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity24.5%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod31.3%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.3%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    7. Step-by-step derivation
      1. unpow231.3%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square31.3%

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

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

    if -0.54000000000000004 < (sin.f64 th) < -0.0050000000000000001

    1. Initial program 96.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow221.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      2. rem-sqrt-square32.4%

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

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

    if -0.0050000000000000001 < (sin.f64 th) < 2.00000000000000012e-9

    1. Initial program 89.2%

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      4. unpow285.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 89.0%

      \[\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.9%

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

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

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

    if 2.00000000000000012e-9 < (sin.f64 th) < 0.734999999999999987

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.734999999999999987 < (sin.f64 th)

    1. Initial program 99.5%

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Taylor expanded in ky around inf 34.2%

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{\sin ky}}} \]
      2. associate-/r/34.2%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    7. Simplified34.2%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin th}{\sin kx} \cdot \frac{\sin th}{\sin kx}}} \cdot \sin ky \]
      3. pow247.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin th}{\sin kx} \cdot \frac{\sin th}{\sin kx}}} \cdot \sin ky \]
      2. rem-sqrt-square47.6%

        \[\leadsto \color{blue}{\left|\frac{\sin th}{\sin kx}\right|} \cdot \sin ky \]
    11. Simplified47.6%

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

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

Alternative 4: 52.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sin kx}\\
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-112}:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\
\;\;\;\;\left|\sin th \cdot t_1\right|\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-35}:\\
\;\;\;\;\sin th \cdot \left|t_1\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -9.9999999999999995e-113

    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-/r/99.5%

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

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

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

        \[\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 kx around 0 2.7%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.7%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.7%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.2%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.2%

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

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square40.4%

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

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

    if -9.9999999999999995e-113 < (sin.f64 ky) < -5.00000000000000013e-301

    1. Initial program 81.7%

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

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

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

        \[\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 58.1%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow218.0%

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Step-by-step derivation
      1. add-sqr-sqrt14.7%

        \[\leadsto \color{blue}{\sqrt{\left|\frac{\sin ky}{\sin kx}\right| \cdot \sin th} \cdot \sqrt{\left|\frac{\sin ky}{\sin kx}\right| \cdot \sin th}} \]
      2. sqrt-unprod31.3%

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

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

        \[\leadsto \sqrt{{\color{blue}{\left(\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\right)}}^{2}} \]
      5. add-sqr-sqrt11.3%

        \[\leadsto \sqrt{{\left(\sin th \cdot \left|\color{blue}{\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}}\right|\right)}^{2}} \]
      6. fabs-sqr11.3%

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\left(\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}\right)}\right)}^{2}} \]
      7. add-sqr-sqrt31.3%

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

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky}}}\right)}^{2}} \]
      9. un-div-inv31.3%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin th}{\frac{\sin kx}{\sin ky}}\right|} \]
      3. associate-/l*52.9%

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot \sin ky}{\sin kx}}\right| \]
      4. associate-*r/64.8%

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

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

    if -5.00000000000000013e-301 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 76.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999964e-35 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-112}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-35}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 5: 76.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -0.02:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \mathbf{elif}\;\sin ky \leq 0.0013:\\ \;\;\;\;\frac{\frac{\sin th}{t_1}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin ky) -0.02)
     (* (/ (sin ky) t_1) th)
     (if (<= (sin ky) 0.0013)
       (/ (/ (sin th) t_1) (+ (* ky 0.16666666666666666) (/ 1.0 ky)))
       (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(ky) <= -0.02) {
		tmp = (sin(ky) / t_1) * th;
	} else if (sin(ky) <= 0.0013) {
		tmp = (sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (Math.sin(ky) <= -0.02) {
		tmp = (Math.sin(ky) / t_1) * th;
	} else if (Math.sin(ky) <= 0.0013) {
		tmp = (Math.sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if math.sin(ky) <= -0.02:
		tmp = (math.sin(ky) / t_1) * th
	elif math.sin(ky) <= 0.0013:
		tmp = (math.sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(ky) <= -0.02)
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	elseif (sin(ky) <= 0.0013)
		tmp = Float64(Float64(sin(th) / t_1) / Float64(Float64(ky * 0.16666666666666666) + Float64(1.0 / ky)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (sin(ky) <= -0.02)
		tmp = (sin(ky) / t_1) * th;
	elseif (sin(ky) <= 0.0013)
		tmp = (sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	else
		tmp = sin(th);
	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]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -0.02], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0013], N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(N[(ky * 0.16666666666666666), $MachinePrecision] + N[(1.0 / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin ky \leq 0.0013:\\
\;\;\;\;\frac{\frac{\sin th}{t_1}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\

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


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

    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. +-commutative99.6%

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

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

        \[\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 th around 0 53.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*53.4%

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

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

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

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

    1. Initial program 84.4%

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

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

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

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

        \[\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. Step-by-step derivation
      1. *-un-lft-identity99.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}} \]
      2. div-inv99.4%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
      2. *-un-lft-identity99.4%

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

        \[\leadsto \color{blue}{\sin ky \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
      4. un-div-inv99.4%

        \[\leadsto \sin ky \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      5. clear-num99.6%

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      8. div-inv99.5%

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

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

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

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

    if 0.0012999999999999999 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.02:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \mathbf{elif}\;\sin ky \leq 0.0013:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 76.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -0.02:\\ \;\;\;\;\frac{1}{t_1} \cdot \frac{\sin ky}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{elif}\;\sin ky \leq 0.0013:\\ \;\;\;\;\frac{\frac{\sin th}{t_1}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin ky) -0.02)
     (* (/ 1.0 t_1) (/ (sin ky) (+ (/ 1.0 th) (* th 0.16666666666666666))))
     (if (<= (sin ky) 0.0013)
       (/ (/ (sin th) t_1) (+ (* ky 0.16666666666666666) (/ 1.0 ky)))
       (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(ky) <= -0.02) {
		tmp = (1.0 / t_1) * (sin(ky) / ((1.0 / th) + (th * 0.16666666666666666)));
	} else if (sin(ky) <= 0.0013) {
		tmp = (sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (Math.sin(ky) <= -0.02) {
		tmp = (1.0 / t_1) * (Math.sin(ky) / ((1.0 / th) + (th * 0.16666666666666666)));
	} else if (Math.sin(ky) <= 0.0013) {
		tmp = (Math.sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if math.sin(ky) <= -0.02:
		tmp = (1.0 / t_1) * (math.sin(ky) / ((1.0 / th) + (th * 0.16666666666666666)))
	elif math.sin(ky) <= 0.0013:
		tmp = (math.sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(ky) <= -0.02)
		tmp = Float64(Float64(1.0 / t_1) * Float64(sin(ky) / Float64(Float64(1.0 / th) + Float64(th * 0.16666666666666666))));
	elseif (sin(ky) <= 0.0013)
		tmp = Float64(Float64(sin(th) / t_1) / Float64(Float64(ky * 0.16666666666666666) + Float64(1.0 / ky)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (sin(ky) <= -0.02)
		tmp = (1.0 / t_1) * (sin(ky) / ((1.0 / th) + (th * 0.16666666666666666)));
	elseif (sin(ky) <= 0.0013)
		tmp = (sin(th) / t_1) / ((ky * 0.16666666666666666) + (1.0 / ky));
	else
		tmp = sin(th);
	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]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -0.02], N[(N[(1.0 / t$95$1), $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[(N[(1.0 / th), $MachinePrecision] + N[(th * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0013], N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(N[(ky * 0.16666666666666666), $MachinePrecision] + N[(1.0 / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin ky \leq 0.0013:\\
\;\;\;\;\frac{\frac{\sin th}{t_1}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\

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


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

    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-/r/99.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity99.5%

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \frac{\sin ky}{\color{blue}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    7. Step-by-step derivation
      1. *-commutative53.6%

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

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

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

    1. Initial program 84.4%

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

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

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

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

        \[\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. Step-by-step derivation
      1. *-un-lft-identity99.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}} \]
      2. div-inv99.4%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
      2. *-un-lft-identity99.4%

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

        \[\leadsto \color{blue}{\sin ky \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
      4. un-div-inv99.4%

        \[\leadsto \sin ky \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      5. clear-num99.6%

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      8. div-inv99.5%

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

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

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

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

    if 0.0012999999999999999 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.02:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \frac{\sin ky}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{elif}\;\sin ky \leq 0.0013:\\ \;\;\;\;\frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{ky \cdot 0.16666666666666666 + \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 7: 76.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-7}:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \mathbf{elif}\;\sin ky \leq 0.0013:\\ \;\;\;\;\frac{\frac{\sin th}{t_1}}{\frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin ky) -2e-7)
     (* (/ (sin ky) t_1) th)
     (if (<= (sin ky) 0.0013) (/ (/ (sin th) t_1) (/ 1.0 ky)) (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(ky) <= -2e-7) {
		tmp = (sin(ky) / t_1) * th;
	} else if (sin(ky) <= 0.0013) {
		tmp = (sin(th) / t_1) / (1.0 / ky);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (Math.sin(ky) <= -2e-7) {
		tmp = (Math.sin(ky) / t_1) * th;
	} else if (Math.sin(ky) <= 0.0013) {
		tmp = (Math.sin(th) / t_1) / (1.0 / ky);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if math.sin(ky) <= -2e-7:
		tmp = (math.sin(ky) / t_1) * th
	elif math.sin(ky) <= 0.0013:
		tmp = (math.sin(th) / t_1) / (1.0 / ky)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(ky) <= -2e-7)
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	elseif (sin(ky) <= 0.0013)
		tmp = Float64(Float64(sin(th) / t_1) / Float64(1.0 / ky));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (sin(ky) <= -2e-7)
		tmp = (sin(ky) / t_1) * th;
	elseif (sin(ky) <= 0.0013)
		tmp = (sin(th) / t_1) / (1.0 / ky);
	else
		tmp = sin(th);
	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]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-7], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0013], N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(1.0 / ky), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin ky \leq 0.0013:\\
\;\;\;\;\frac{\frac{\sin th}{t_1}}{\frac{1}{ky}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -1.9999999999999999e-7

    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. +-commutative99.6%

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

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

        \[\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 th around 0 54.2%

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

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

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

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

    if -1.9999999999999999e-7 < (sin.f64 ky) < 0.0012999999999999999

    1. Initial program 84.3%

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin th}} \]
      4. unpow284.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. Step-by-step derivation
      1. *-un-lft-identity99.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}} \]
      2. div-inv99.4%

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
      2. *-un-lft-identity99.4%

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

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

        \[\leadsto \sin ky \cdot \frac{1}{\color{blue}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      5. clear-num99.6%

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      8. div-inv99.5%

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

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

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

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

    if 0.0012999999999999999 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

Alternative 8: 52.5% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{ky}{\sin kx}\\
\mathbf{if}\;\sin ky \leq -2 \cdot 10^{-104}:\\
\;\;\;\;\left|\sin th\right|\\

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

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-35}:\\
\;\;\;\;\sin th \cdot \left|t_1\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.99999999999999985e-104

    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-/r/99.5%

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

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

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

        \[\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 kx around 0 2.7%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.7%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.7%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.6%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.6%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    7. Step-by-step derivation
      1. unpow231.6%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square40.9%

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

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

    if -1.99999999999999985e-104 < (sin.f64 ky) < -5.00000000000000013e-301

    1. Initial program 82.1%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow282.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 56.9%

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

    if -5.00000000000000013e-301 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 76.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Taylor expanded in ky around 0 77.7%

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

    if 4.99999999999999964e-35 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-104}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-35}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 9: 52.2% accurate, 1.2× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -9.9999999999999995e-113

    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-/r/99.5%

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

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

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

        \[\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 kx around 0 2.7%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.7%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.7%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.2%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.2%

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

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square40.4%

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

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

    if -9.9999999999999995e-113 < (sin.f64 ky) < -5.00000000000000013e-301

    1. Initial program 81.7%

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

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

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

        \[\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 58.1%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow218.0%

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Step-by-step derivation
      1. add-sqr-sqrt14.7%

        \[\leadsto \color{blue}{\sqrt{\left|\frac{\sin ky}{\sin kx}\right| \cdot \sin th} \cdot \sqrt{\left|\frac{\sin ky}{\sin kx}\right| \cdot \sin th}} \]
      2. sqrt-unprod31.3%

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

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

        \[\leadsto \sqrt{{\color{blue}{\left(\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\right)}}^{2}} \]
      5. add-sqr-sqrt11.3%

        \[\leadsto \sqrt{{\left(\sin th \cdot \left|\color{blue}{\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}}\right|\right)}^{2}} \]
      6. fabs-sqr11.3%

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\left(\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}\right)}\right)}^{2}} \]
      7. add-sqr-sqrt31.3%

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

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky}}}\right)}^{2}} \]
      9. un-div-inv31.3%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin th}{\frac{\sin kx}{\sin ky}}\right|} \]
      3. associate-/l*52.9%

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot \sin ky}{\sin kx}}\right| \]
      4. associate-*r/64.8%

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

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

    if -5.00000000000000013e-301 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 76.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Taylor expanded in ky around 0 77.7%

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

    if 4.99999999999999964e-35 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-112}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-35}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 10: 74.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin th \leq -0.005 \lor \neg \left(\sin th \leq 4 \cdot 10^{-9}\right):\\ \;\;\;\;\frac{ky \cdot \sin th}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (or (<= (sin th) -0.005) (not (<= (sin th) 4e-9)))
     (/ (* ky (sin th)) t_1)
     (* (/ (sin ky) t_1) th))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if ((sin(th) <= -0.005) || !(sin(th) <= 4e-9)) {
		tmp = (ky * sin(th)) / t_1;
	} else {
		tmp = (sin(ky) / t_1) * th;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if ((Math.sin(th) <= -0.005) || !(Math.sin(th) <= 4e-9)) {
		tmp = (ky * Math.sin(th)) / t_1;
	} else {
		tmp = (Math.sin(ky) / t_1) * th;
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if (math.sin(th) <= -0.005) or not (math.sin(th) <= 4e-9):
		tmp = (ky * math.sin(th)) / t_1
	else:
		tmp = (math.sin(ky) / t_1) * th
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if ((sin(th) <= -0.005) || !(sin(th) <= 4e-9))
		tmp = Float64(Float64(ky * sin(th)) / t_1);
	else
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if ((sin(th) <= -0.005) || ~((sin(th) <= 4e-9)))
		tmp = (ky * sin(th)) / t_1;
	else
		tmp = (sin(ky) / t_1) * th;
	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]}, If[Or[LessEqual[N[Sin[th], $MachinePrecision], -0.005], N[Not[LessEqual[N[Sin[th], $MachinePrecision], 4e-9]], $MachinePrecision]], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
\mathbf{if}\;\sin th \leq -0.005 \lor \neg \left(\sin th \leq 4 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{ky \cdot \sin th}{t_1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 th) < -0.0050000000000000001 or 4.00000000000000025e-9 < (sin.f64 th)

    1. Initial program 95.2%

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 th) < 4.00000000000000025e-9

    1. Initial program 89.3%

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified89.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 89.1%

      \[\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.9%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification74.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.005 \lor \neg \left(\sin th \leq 4 \cdot 10^{-9}\right):\\ \;\;\;\;\frac{ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot 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 92.4%

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

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

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

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

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
    5. unpow292.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. Final simplification99.6%

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

Alternative 12: 44.9% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-104}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-190}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -2e-104)
   (fabs (sin th))
   (if (<= (sin ky) 4e-190) (* (sin th) (/ ky (sin kx))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -2e-104) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 4e-190) {
		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) <= (-2d-104)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 4d-190) 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) <= -2e-104) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 4e-190) {
		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) <= -2e-104:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 4e-190:
		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) <= -2e-104)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 4e-190)
		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) <= -2e-104)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 4e-190)
		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], -2e-104], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-190], 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 -2 \cdot 10^{-104}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -1.99999999999999985e-104

    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-/r/99.5%

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

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

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

        \[\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 kx around 0 2.7%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.7%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.7%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow231.6%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr31.6%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    7. Step-by-step derivation
      1. unpow231.6%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square40.9%

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

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

    if -1.99999999999999985e-104 < (sin.f64 ky) < 4.0000000000000001e-190

    1. Initial program 78.1%

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

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

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

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

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

      \[\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.0%

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

    if 4.0000000000000001e-190 < (sin.f64 ky)

    1. Initial program 95.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-104}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-190}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 13: 32.6% accurate, 3.5× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

        \[\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 kx around 0 23.4%

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/23.5%

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity23.5%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt12.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod26.9%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow226.9%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr26.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    7. Step-by-step derivation
      1. unpow226.9%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square36.0%

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

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

    if -3.2999999999999999e-109 < ky < 4.5999999999999996e-189

    1. Initial program 78.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Step-by-step derivation
      1. associate-/r/36.7%

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot th} \]
    9. Applied egg-rr36.7%

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

    if 4.5999999999999996e-189 < ky

    1. Initial program 95.3%

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

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

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

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

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

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

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

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

Alternative 14: 31.6% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\
\;\;\;\;\sin th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.5000000000000003e-21 or 5.00000000000000034e-190 < ky

    1. Initial program 97.3%

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

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

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

        \[\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 kx around 0 33.2%

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

    if -3.5000000000000003e-21 < ky < 5.00000000000000034e-190

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Step-by-step derivation
      1. associate-/r/29.2%

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot th} \]
    9. Applied egg-rr29.2%

      \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 5 \cdot 10^{-190}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 15: 30.0% accurate, 6.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1600000000:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 4.5 \cdot 10^{-189}:\\
\;\;\;\;\frac{ky}{\frac{kx}{th}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.6e9 or 4.4999999999999996e-189 < ky

    1. Initial program 97.2%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow297.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 kx around 0 34.5%

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

    if -1.6e9 < ky < 4.4999999999999996e-189

    1. Initial program 84.7%

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified90.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 40.0%

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Taylor expanded in kx around 0 23.4%

      \[\leadsto \frac{ky}{\color{blue}{\frac{kx}{th}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification30.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1600000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.5 \cdot 10^{-189}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 16: 21.1% accurate, 77.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -3.5e-21) th (if (<= ky 4.6e-189) (* th (/ ky kx)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -3.5e-21) {
		tmp = th;
	} else if (ky <= 4.6e-189) {
		tmp = th * (ky / kx);
	} 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 <= (-3.5d-21)) then
        tmp = th
    else if (ky <= 4.6d-189) then
        tmp = th * (ky / kx)
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -3.5e-21) {
		tmp = th;
	} else if (ky <= 4.6e-189) {
		tmp = th * (ky / kx);
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -3.5e-21:
		tmp = th
	elif ky <= 4.6e-189:
		tmp = th * (ky / kx)
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -3.5e-21)
		tmp = th;
	elseif (ky <= 4.6e-189)
		tmp = Float64(th * Float64(ky / kx));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -3.5e-21)
		tmp = th;
	elseif (ky <= 4.6e-189)
		tmp = th * (ky / kx);
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -3.5e-21], th, If[LessEqual[ky, 4.6e-189], N[(th * N[(ky / kx), $MachinePrecision]), $MachinePrecision], th]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\
\;\;\;\;th\\

\mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\
\;\;\;\;th \cdot \frac{ky}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.5000000000000003e-21 or 4.5999999999999996e-189 < ky

    1. Initial program 97.3%

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified97.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 48.9%

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

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

    if -3.5000000000000003e-21 < ky < 4.5999999999999996e-189

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Taylor expanded in kx around 0 25.0%

      \[\leadsto \frac{ky}{\color{blue}{\frac{kx}{th}}} \]
    9. Step-by-step derivation
      1. associate-/r/24.9%

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    10. Applied egg-rr24.9%

      \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 17: 21.1% accurate, 77.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 3.7 \cdot 10^{-189}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -3.5e-21) th (if (<= ky 3.7e-189) (* ky (/ th kx)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -3.5e-21) {
		tmp = th;
	} else if (ky <= 3.7e-189) {
		tmp = ky * (th / kx);
	} 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 <= (-3.5d-21)) then
        tmp = th
    else if (ky <= 3.7d-189) then
        tmp = ky * (th / kx)
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -3.5e-21) {
		tmp = th;
	} else if (ky <= 3.7e-189) {
		tmp = ky * (th / kx);
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -3.5e-21:
		tmp = th
	elif ky <= 3.7e-189:
		tmp = ky * (th / kx)
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -3.5e-21)
		tmp = th;
	elseif (ky <= 3.7e-189)
		tmp = Float64(ky * Float64(th / kx));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -3.5e-21)
		tmp = th;
	elseif (ky <= 3.7e-189)
		tmp = ky * (th / kx);
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -3.5e-21], th, If[LessEqual[ky, 3.7e-189], N[(ky * N[(th / kx), $MachinePrecision]), $MachinePrecision], th]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\
\;\;\;\;th\\

\mathbf{elif}\;ky \leq 3.7 \cdot 10^{-189}:\\
\;\;\;\;ky \cdot \frac{th}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.5000000000000003e-21 or 3.70000000000000019e-189 < ky

    1. Initial program 97.3%

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified97.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 48.9%

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

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

    if -3.5000000000000003e-21 < ky < 3.70000000000000019e-189

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Taylor expanded in kx around 0 25.0%

      \[\leadsto \frac{ky}{\color{blue}{\frac{kx}{th}}} \]
    9. Step-by-step derivation
      1. clear-num24.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{kx}{th}}{ky}}} \]
      2. associate-/r/24.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{kx}{th}} \cdot ky} \]
      3. clear-num24.9%

        \[\leadsto \color{blue}{\frac{th}{kx}} \cdot ky \]
    10. Applied egg-rr24.9%

      \[\leadsto \color{blue}{\frac{th}{kx} \cdot ky} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.5 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 3.7 \cdot 10^{-189}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 18: 21.1% accurate, 77.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -2.7 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -2.7e-21) th (if (<= ky 4.6e-189) (/ ky (/ kx th)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -2.7e-21) {
		tmp = th;
	} else if (ky <= 4.6e-189) {
		tmp = ky / (kx / 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 <= (-2.7d-21)) then
        tmp = th
    else if (ky <= 4.6d-189) then
        tmp = ky / (kx / th)
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -2.7e-21) {
		tmp = th;
	} else if (ky <= 4.6e-189) {
		tmp = ky / (kx / th);
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -2.7e-21:
		tmp = th
	elif ky <= 4.6e-189:
		tmp = ky / (kx / th)
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -2.7e-21)
		tmp = th;
	elseif (ky <= 4.6e-189)
		tmp = Float64(ky / Float64(kx / th));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -2.7e-21)
		tmp = th;
	elseif (ky <= 4.6e-189)
		tmp = ky / (kx / th);
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -2.7e-21], th, If[LessEqual[ky, 4.6e-189], N[(ky / N[(kx / th), $MachinePrecision]), $MachinePrecision], th]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -2.7 \cdot 10^{-21}:\\
\;\;\;\;th\\

\mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\
\;\;\;\;\frac{ky}{\frac{kx}{th}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.7000000000000001e-21 or 4.5999999999999996e-189 < ky

    1. Initial program 97.3%

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    3. Simplified97.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 48.9%

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

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

    if -2.7000000000000001e-21 < ky < 4.5999999999999996e-189

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    8. Taylor expanded in kx around 0 25.0%

      \[\leadsto \frac{ky}{\color{blue}{\frac{kx}{th}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.7 \cdot 10^{-21}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-189}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 19: 13.7% 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 92.4%

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

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

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

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

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

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  3. Simplified94.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 44.9%

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

    \[\leadsto \color{blue}{th} \]
  6. Final simplification13.9%

    \[\leadsto th \]

Reproduce

?
herbie shell --seed 2023257 
(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)))