Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.6%
Time: 21.0s
Alternatives: 20
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 20 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 94.1% 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.6% 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 90.6%

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

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

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

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

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

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

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

Alternative 2: 63.6% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin th \leq -0.38:\\
\;\;\;\;\sin ky \cdot t\_1\\

\mathbf{elif}\;\sin th \leq -0.05:\\
\;\;\;\;\left|\sin th\right|\\

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

\mathbf{elif}\;\sin th \leq 0.82 \lor \neg \left(\sin th \leq 0.993\right):\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

\mathbf{else}:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\


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

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg95.8%

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

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

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

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

    if -0.38 < (sin.f64 th) < -0.050000000000000003

    1. Initial program 84.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg84.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg84.7%

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.3%

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

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

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

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

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

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

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity0.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    11. Simplified17.2%

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

    if -0.050000000000000003 < (sin.f64 th) < 4.9999999999999998e-8

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg89.4%

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{th}} \]
      8. unpow287.1%

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

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

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

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

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

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

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

    if 4.9999999999999998e-8 < (sin.f64 th) < 0.819999999999999951 or 0.992999999999999994 < (sin.f64 th)

    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/89.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg89.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.819999999999999951 < (sin.f64 th) < 0.992999999999999994

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.38:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin th \leq -0.05:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \mathbf{elif}\;\sin th \leq 0.82 \lor \neg \left(\sin th \leq 0.993\right):\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 63.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin th}{\sin kx}\\ \mathbf{if}\;\sin th \leq -0.38:\\ \;\;\;\;\sin ky \cdot t\_1\\ \mathbf{elif}\;\sin th \leq -0.05:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{th}}\\ \mathbf{elif}\;\sin th \leq 0.82 \lor \neg \left(\sin th \leq 0.993\right):\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\left|ky \cdot t\_1\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin th) (sin kx))))
   (if (<= (sin th) -0.38)
     (* (sin ky) t_1)
     (if (<= (sin th) -0.05)
       (fabs (sin th))
       (if (<= (sin th) 5e-8)
         (/ (/ (sin ky) (hypot (sin ky) (sin kx))) (/ 1.0 th))
         (if (or (<= (sin th) 0.82) (not (<= (sin th) 0.993)))
           (/ (sin ky) (fabs (/ (sin ky) (sin th))))
           (fabs (* ky t_1))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(th) / sin(kx);
	double tmp;
	if (sin(th) <= -0.38) {
		tmp = sin(ky) * t_1;
	} else if (sin(th) <= -0.05) {
		tmp = fabs(sin(th));
	} else if (sin(th) <= 5e-8) {
		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) / (1.0 / th);
	} else if ((sin(th) <= 0.82) || !(sin(th) <= 0.993)) {
		tmp = sin(ky) / fabs((sin(ky) / sin(th)));
	} else {
		tmp = fabs((ky * t_1));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(th) / Math.sin(kx);
	double tmp;
	if (Math.sin(th) <= -0.38) {
		tmp = Math.sin(ky) * t_1;
	} else if (Math.sin(th) <= -0.05) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(th) <= 5e-8) {
		tmp = (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) / (1.0 / th);
	} else if ((Math.sin(th) <= 0.82) || !(Math.sin(th) <= 0.993)) {
		tmp = Math.sin(ky) / Math.abs((Math.sin(ky) / Math.sin(th)));
	} else {
		tmp = Math.abs((ky * t_1));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(th) / math.sin(kx)
	tmp = 0
	if math.sin(th) <= -0.38:
		tmp = math.sin(ky) * t_1
	elif math.sin(th) <= -0.05:
		tmp = math.fabs(math.sin(th))
	elif math.sin(th) <= 5e-8:
		tmp = (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) / (1.0 / th)
	elif (math.sin(th) <= 0.82) or not (math.sin(th) <= 0.993):
		tmp = math.sin(ky) / math.fabs((math.sin(ky) / math.sin(th)))
	else:
		tmp = math.fabs((ky * t_1))
	return tmp
function code(kx, ky, th)
	t_1 = Float64(sin(th) / sin(kx))
	tmp = 0.0
	if (sin(th) <= -0.38)
		tmp = Float64(sin(ky) * t_1);
	elseif (sin(th) <= -0.05)
		tmp = abs(sin(th));
	elseif (sin(th) <= 5e-8)
		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) / Float64(1.0 / th));
	elseif ((sin(th) <= 0.82) || !(sin(th) <= 0.993))
		tmp = Float64(sin(ky) / abs(Float64(sin(ky) / sin(th))));
	else
		tmp = abs(Float64(ky * t_1));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(th) / sin(kx);
	tmp = 0.0;
	if (sin(th) <= -0.38)
		tmp = sin(ky) * t_1;
	elseif (sin(th) <= -0.05)
		tmp = abs(sin(th));
	elseif (sin(th) <= 5e-8)
		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) / (1.0 / th);
	elseif ((sin(th) <= 0.82) || ~((sin(th) <= 0.993)))
		tmp = sin(ky) / abs((sin(ky) / sin(th)));
	else
		tmp = abs((ky * t_1));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[th], $MachinePrecision], -0.38], N[(N[Sin[ky], $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], -0.05], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], 5e-8], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[(1.0 / th), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[Sin[th], $MachinePrecision], 0.82], N[Not[LessEqual[N[Sin[th], $MachinePrecision], 0.993]], $MachinePrecision]], N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Abs[N[(ky * t$95$1), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin th \leq -0.38:\\
\;\;\;\;\sin ky \cdot t\_1\\

\mathbf{elif}\;\sin th \leq -0.05:\\
\;\;\;\;\left|\sin th\right|\\

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

\mathbf{elif}\;\sin th \leq 0.82 \lor \neg \left(\sin th \leq 0.993\right):\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

\mathbf{else}:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\


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

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg95.8%

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

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

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

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

    if -0.38 < (sin.f64 th) < -0.050000000000000003

    1. Initial program 84.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg84.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg84.7%

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.3%

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

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

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

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

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

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

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity0.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    11. Simplified17.2%

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

    if -0.050000000000000003 < (sin.f64 th) < 4.9999999999999998e-8

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999998e-8 < (sin.f64 th) < 0.819999999999999951 or 0.992999999999999994 < (sin.f64 th)

    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/89.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg89.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.819999999999999951 < (sin.f64 th) < 0.992999999999999994

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.38:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin th \leq -0.05:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{th}}\\ \mathbf{elif}\;\sin th \leq 0.82 \lor \neg \left(\sin th \leq 0.993\right):\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 46.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-205}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.005)
   (fabs (sin th))
   (if (<= (sin ky) 4e-205)
     (* (sin th) (/ ky (sin kx)))
     (if (or (<= (sin ky) 2e-82)
             (and (not (<= (sin ky) 5e-59)) (<= (sin ky) 2e-44)))
       (fabs (* ky (/ (sin th) (sin kx))))
       (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.005) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 4e-205) {
		tmp = sin(th) * (ky / sin(kx));
	} else if ((sin(ky) <= 2e-82) || (!(sin(ky) <= 5e-59) && (sin(ky) <= 2e-44))) {
		tmp = fabs((ky * (sin(th) / sin(kx))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.005d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 4d-205) then
        tmp = sin(th) * (ky / sin(kx))
    else if ((sin(ky) <= 2d-82) .or. (.not. (sin(ky) <= 5d-59)) .and. (sin(ky) <= 2d-44)) then
        tmp = abs((ky * (sin(th) / sin(kx))))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.005) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 4e-205) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else if ((Math.sin(ky) <= 2e-82) || (!(Math.sin(ky) <= 5e-59) && (Math.sin(ky) <= 2e-44))) {
		tmp = Math.abs((ky * (Math.sin(th) / Math.sin(kx))));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.005:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 4e-205:
		tmp = math.sin(th) * (ky / math.sin(kx))
	elif (math.sin(ky) <= 2e-82) or (not (math.sin(ky) <= 5e-59) and (math.sin(ky) <= 2e-44)):
		tmp = math.fabs((ky * (math.sin(th) / math.sin(kx))))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.005)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 4e-205)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	elseif ((sin(ky) <= 2e-82) || (!(sin(ky) <= 5e-59) && (sin(ky) <= 2e-44)))
		tmp = abs(Float64(ky * Float64(sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.005)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 4e-205)
		tmp = sin(th) * (ky / sin(kx));
	elseif ((sin(ky) <= 2e-82) || (~((sin(ky) <= 5e-59)) && (sin(ky) <= 2e-44)))
		tmp = abs((ky * (sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.005], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-205], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[Sin[ky], $MachinePrecision], 2e-82], And[N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 5e-59]], $MachinePrecision], LessEqual[N[Sin[ky], $MachinePrecision], 2e-44]]], N[Abs[N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\
\;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt1.0%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity1.0%

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 4e-205

    1. Initial program 77.9%

      \[\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. associate-/l*77.9%

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow277.9%

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg77.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg77.9%

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

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

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

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

        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      2. associate-/l*49.0%

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

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

    if 4e-205 < (sin.f64 ky) < 2e-82 or 5.0000000000000001e-59 < (sin.f64 ky) < 1.99999999999999991e-44

    1. Initial program 87.0%

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow287.1%

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg87.1%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg87.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|ky \cdot \frac{\sin th}{\sin kx}\right|} \]
    9. Simplified38.1%

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

    if 2e-82 < (sin.f64 ky) < 5.0000000000000001e-59 or 1.99999999999999991e-44 < (sin.f64 ky)

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-205}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 46.7% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-205}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.05)
   (/ (sin ky) (fabs (/ (sin ky) (sin th))))
   (if (<= (sin ky) 4e-205)
     (* (sin th) (/ (sin ky) (sin kx)))
     (if (or (<= (sin ky) 2e-82)
             (and (not (<= (sin ky) 5e-59)) (<= (sin ky) 2e-44)))
       (fabs (* ky (/ (sin th) (sin kx))))
       (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.05) {
		tmp = sin(ky) / fabs((sin(ky) / sin(th)));
	} else if (sin(ky) <= 4e-205) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if ((sin(ky) <= 2e-82) || (!(sin(ky) <= 5e-59) && (sin(ky) <= 2e-44))) {
		tmp = fabs((ky * (sin(th) / sin(kx))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.05d0)) then
        tmp = sin(ky) / abs((sin(ky) / sin(th)))
    else if (sin(ky) <= 4d-205) then
        tmp = sin(th) * (sin(ky) / sin(kx))
    else if ((sin(ky) <= 2d-82) .or. (.not. (sin(ky) <= 5d-59)) .and. (sin(ky) <= 2d-44)) then
        tmp = abs((ky * (sin(th) / sin(kx))))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.05) {
		tmp = Math.sin(ky) / Math.abs((Math.sin(ky) / Math.sin(th)));
	} else if (Math.sin(ky) <= 4e-205) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	} else if ((Math.sin(ky) <= 2e-82) || (!(Math.sin(ky) <= 5e-59) && (Math.sin(ky) <= 2e-44))) {
		tmp = Math.abs((ky * (Math.sin(th) / Math.sin(kx))));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.05:
		tmp = math.sin(ky) / math.fabs((math.sin(ky) / math.sin(th)))
	elif math.sin(ky) <= 4e-205:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	elif (math.sin(ky) <= 2e-82) or (not (math.sin(ky) <= 5e-59) and (math.sin(ky) <= 2e-44)):
		tmp = math.fabs((ky * (math.sin(th) / math.sin(kx))))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.05)
		tmp = Float64(sin(ky) / abs(Float64(sin(ky) / sin(th))));
	elseif (sin(ky) <= 4e-205)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif ((sin(ky) <= 2e-82) || (!(sin(ky) <= 5e-59) && (sin(ky) <= 2e-44)))
		tmp = abs(Float64(ky * Float64(sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.05)
		tmp = sin(ky) / abs((sin(ky) / sin(th)));
	elseif (sin(ky) <= 4e-205)
		tmp = sin(th) * (sin(ky) / sin(kx));
	elseif ((sin(ky) <= 2e-82) || (~((sin(ky) <= 5e-59)) && (sin(ky) <= 2e-44)))
		tmp = abs((ky * (sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.05], N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-205], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[Sin[ky], $MachinePrecision], 2e-82], And[N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 5e-59]], $MachinePrecision], LessEqual[N[Sin[ky], $MachinePrecision], 2e-44]]], N[Abs[N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\
\;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\frac{\sin ky}{\sin th}\right|}} \]
    11. Simplified28.5%

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

    if -0.050000000000000003 < (sin.f64 ky) < 4e-205

    1. Initial program 78.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. 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-undefine99.8%

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

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

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

    if 4e-205 < (sin.f64 ky) < 2e-82 or 5.0000000000000001e-59 < (sin.f64 ky) < 1.99999999999999991e-44

    1. Initial program 87.0%

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow287.1%

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg87.1%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg87.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|ky \cdot \frac{\sin th}{\sin kx}\right|} \]
    9. Simplified38.1%

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

    if 2e-82 < (sin.f64 ky) < 5.0000000000000001e-59 or 1.99999999999999991e-44 < (sin.f64 ky)

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-205}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-82} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-59}\right) \land \sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 43.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 10^{-51} \lor \neg \left(\sin kx \leq 10^{-22}\right):\\
\;\;\;\;\sin ky \cdot t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 kx) < -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.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 kx) < 2.00000000000000017e-86

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000017e-86 < (sin.f64 kx) < 1e-51 or 1e-22 < (sin.f64 kx)

    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-*l/98.4%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

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

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

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

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

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

    if 1e-51 < (sin.f64 kx) < 1e-22

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.0%

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt0.5%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity0.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification44.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-51} \lor \neg \left(\sin kx \leq 10^{-22}\right):\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 43.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 10^{-51}:\\
\;\;\;\;\sin ky \cdot t\_1\\

\mathbf{elif}\;\sin kx \leq 10^{-22}:\\
\;\;\;\;\left|\sin th\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 kx) < -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.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 kx) < 2.00000000000000017e-86

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000017e-86 < (sin.f64 kx) < 1e-51

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.8%

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

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

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

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

    if 1e-51 < (sin.f64 kx) < 1e-22

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.0%

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt0.5%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity0.5%

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

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

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

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

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

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

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

    if 1e-22 < (sin.f64 kx)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. 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-undefine99.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-51}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 10^{-22}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 43.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 10^{-51}:\\
\;\;\;\;\sin ky \cdot t\_1\\

\mathbf{elif}\;\sin kx \leq 10^{-22}:\\
\;\;\;\;\left|\sin th\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 kx) < -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.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 kx) < 2.00000000000000017e-86

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000017e-86 < (sin.f64 kx) < 1e-51

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.8%

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

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

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

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

    if 1e-51 < (sin.f64 kx) < 1e-22

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.0%

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt0.5%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity0.5%

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

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

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

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

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

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

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

    if 1e-22 < (sin.f64 kx)

    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-*l/98.3%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      9. un-div-inv99.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-86}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-51}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 10^{-22}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{\sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 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 90.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
    11. sqr-neg90.6%

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

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

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

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

Alternative 10: 47.1% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt1.0%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity1.0%

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.99999999999999991e-44

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999991e-44 < (sin.f64 ky)

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 47.0% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt1.0%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity1.0%

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.99999999999999991e-44

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      9. un-div-inv81.5%

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

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

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

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

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

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

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

    if 1.99999999999999991e-44 < (sin.f64 ky)

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 30.6% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;ky \cdot \frac{th}{kx}\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-35}:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -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.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified15.1%

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

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

        \[\leadsto \color{blue}{ky \cdot \frac{th}{kx}} \]
    11. Simplified16.4%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 2.00000000000000002e-35

    1. Initial program 81.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg81.6%

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

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

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

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

    if 2.00000000000000002e-35 < (sin.f64 kx)

    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-*l/98.3%

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 54.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in th around 0 26.8%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    7. Step-by-step derivation
      1. associate-/l*28.1%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified28.1%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification30.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-35}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 26.4% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 3.7 \cdot 10^{-179}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 1.12 \cdot 10^{-82}:\\ \;\;\;\;\left|th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 3.7e-179)
   (* (sin th) (/ ky kx))
   (if (<= ky 1.12e-82)
     (fabs (* th (/ ky (sin kx))))
     (if (<= ky 4.3e+40) (sin th) (fabs (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 3.7e-179) {
		tmp = sin(th) * (ky / kx);
	} else if (ky <= 1.12e-82) {
		tmp = fabs((th * (ky / sin(kx))));
	} else if (ky <= 4.3e+40) {
		tmp = sin(th);
	} else {
		tmp = fabs(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.7d-179) then
        tmp = sin(th) * (ky / kx)
    else if (ky <= 1.12d-82) then
        tmp = abs((th * (ky / sin(kx))))
    else if (ky <= 4.3d+40) then
        tmp = sin(th)
    else
        tmp = abs(sin(th))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 3.7e-179) {
		tmp = Math.sin(th) * (ky / kx);
	} else if (ky <= 1.12e-82) {
		tmp = Math.abs((th * (ky / Math.sin(kx))));
	} else if (ky <= 4.3e+40) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 3.7e-179:
		tmp = math.sin(th) * (ky / kx)
	elif ky <= 1.12e-82:
		tmp = math.fabs((th * (ky / math.sin(kx))))
	elif ky <= 4.3e+40:
		tmp = math.sin(th)
	else:
		tmp = math.fabs(math.sin(th))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 3.7e-179)
		tmp = Float64(sin(th) * Float64(ky / kx));
	elseif (ky <= 1.12e-82)
		tmp = abs(Float64(th * Float64(ky / sin(kx))));
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 3.7e-179)
		tmp = sin(th) * (ky / kx);
	elseif (ky <= 1.12e-82)
		tmp = abs((th * (ky / sin(kx))));
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 3.7e-179], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 1.12e-82], N[Abs[N[(th * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[ky, 4.3e+40], N[Sin[th], $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 3.7 \cdot 10^{-179}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

\mathbf{elif}\;ky \leq 1.12 \cdot 10^{-82}:\\
\;\;\;\;\left|th \cdot \frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\left|\sin th\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < 3.6999999999999999e-179

    1. Initial program 85.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*85.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 28.5%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in kx around 0 20.0%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    7. Step-by-step derivation
      1. *-commutative20.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{kx} \]
      2. associate-/l*22.8%

        \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]
    8. Simplified22.8%

      \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]

    if 3.6999999999999999e-179 < ky < 1.12e-82

    1. Initial program 94.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*95.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 42.5%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in th around 0 28.5%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    7. Step-by-step derivation
      1. associate-/l*28.1%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified28.1%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt20.5%

        \[\leadsto \color{blue}{\sqrt{ky \cdot \frac{th}{\sin kx}} \cdot \sqrt{ky \cdot \frac{th}{\sin kx}}} \]
      2. sqrt-unprod24.0%

        \[\leadsto \color{blue}{\sqrt{\left(ky \cdot \frac{th}{\sin kx}\right) \cdot \left(ky \cdot \frac{th}{\sin kx}\right)}} \]
      3. pow224.0%

        \[\leadsto \sqrt{\color{blue}{{\left(ky \cdot \frac{th}{\sin kx}\right)}^{2}}} \]
      4. associate-*r/24.1%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{ky \cdot th}{\sin kx}\right)}}^{2}} \]
      5. *-commutative24.1%

        \[\leadsto \sqrt{{\left(\frac{\color{blue}{th \cdot ky}}{\sin kx}\right)}^{2}} \]
    10. Applied egg-rr24.1%

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{th \cdot ky}{\sin kx}\right)}^{2}}} \]
    11. Step-by-step derivation
      1. unpow224.1%

        \[\leadsto \sqrt{\color{blue}{\frac{th \cdot ky}{\sin kx} \cdot \frac{th \cdot ky}{\sin kx}}} \]
      2. rem-sqrt-square31.3%

        \[\leadsto \color{blue}{\left|\frac{th \cdot ky}{\sin kx}\right|} \]
      3. associate-/l*31.0%

        \[\leadsto \left|\color{blue}{th \cdot \frac{ky}{\sin kx}}\right| \]
    12. Simplified31.0%

      \[\leadsto \color{blue}{\left|th \cdot \frac{ky}{\sin kx}\right|} \]

    if 1.12e-82 < ky < 4.3000000000000002e40

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/95.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 54.5%

      \[\leadsto \color{blue}{\sin th} \]

    if 4.3000000000000002e40 < ky

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.5%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. un-div-inv99.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    6. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    7. Taylor expanded in kx around 0 22.2%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
    8. Step-by-step derivation
      1. associate-/r/22.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses22.2%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt11.3%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity11.3%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod28.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow228.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    9. Applied egg-rr28.0%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow228.0%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square33.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    11. Simplified33.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification29.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 3.7 \cdot 10^{-179}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 1.12 \cdot 10^{-82}:\\ \;\;\;\;\left|th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 26.4% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.22 \cdot 10^{-177}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 3.5 \cdot 10^{-81}:\\ \;\;\;\;ky \cdot \left|\frac{th}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.22e-177)
   (* (sin th) (/ ky kx))
   (if (<= ky 3.5e-81)
     (* ky (fabs (/ th (sin kx))))
     (if (<= ky 4.3e+40) (sin th) (fabs (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.22e-177) {
		tmp = sin(th) * (ky / kx);
	} else if (ky <= 3.5e-81) {
		tmp = ky * fabs((th / sin(kx)));
	} else if (ky <= 4.3e+40) {
		tmp = sin(th);
	} else {
		tmp = fabs(sin(th));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.22d-177) then
        tmp = sin(th) * (ky / kx)
    else if (ky <= 3.5d-81) then
        tmp = ky * abs((th / sin(kx)))
    else if (ky <= 4.3d+40) then
        tmp = sin(th)
    else
        tmp = abs(sin(th))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.22e-177) {
		tmp = Math.sin(th) * (ky / kx);
	} else if (ky <= 3.5e-81) {
		tmp = ky * Math.abs((th / Math.sin(kx)));
	} else if (ky <= 4.3e+40) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.22e-177:
		tmp = math.sin(th) * (ky / kx)
	elif ky <= 3.5e-81:
		tmp = ky * math.fabs((th / math.sin(kx)))
	elif ky <= 4.3e+40:
		tmp = math.sin(th)
	else:
		tmp = math.fabs(math.sin(th))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.22e-177)
		tmp = Float64(sin(th) * Float64(ky / kx));
	elseif (ky <= 3.5e-81)
		tmp = Float64(ky * abs(Float64(th / sin(kx))));
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.22e-177)
		tmp = sin(th) * (ky / kx);
	elseif (ky <= 3.5e-81)
		tmp = ky * abs((th / sin(kx)));
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.22e-177], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 3.5e-81], N[(ky * N[Abs[N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 4.3e+40], N[Sin[th], $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.22 \cdot 10^{-177}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

\mathbf{elif}\;ky \leq 3.5 \cdot 10^{-81}:\\
\;\;\;\;ky \cdot \left|\frac{th}{\sin kx}\right|\\

\mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\left|\sin th\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < 1.22e-177

    1. Initial program 85.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*85.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg85.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow285.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 28.5%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in kx around 0 20.0%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    7. Step-by-step derivation
      1. *-commutative20.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{kx} \]
      2. associate-/l*22.8%

        \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]
    8. Simplified22.8%

      \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]

    if 1.22e-177 < ky < 3.49999999999999986e-81

    1. Initial program 94.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/91.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*95.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg95.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow295.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 42.5%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in th around 0 28.5%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    7. Step-by-step derivation
      1. associate-/l*28.1%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified28.1%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt15.7%

        \[\leadsto ky \cdot \color{blue}{\left(\sqrt{\frac{th}{\sin kx}} \cdot \sqrt{\frac{th}{\sin kx}}\right)} \]
      2. sqrt-unprod26.5%

        \[\leadsto ky \cdot \color{blue}{\sqrt{\frac{th}{\sin kx} \cdot \frac{th}{\sin kx}}} \]
      3. pow226.5%

        \[\leadsto ky \cdot \sqrt{\color{blue}{{\left(\frac{th}{\sin kx}\right)}^{2}}} \]
    10. Applied egg-rr26.5%

      \[\leadsto ky \cdot \color{blue}{\sqrt{{\left(\frac{th}{\sin kx}\right)}^{2}}} \]
    11. Step-by-step derivation
      1. unpow226.5%

        \[\leadsto ky \cdot \sqrt{\color{blue}{\frac{th}{\sin kx} \cdot \frac{th}{\sin kx}}} \]
      2. rem-sqrt-square30.9%

        \[\leadsto ky \cdot \color{blue}{\left|\frac{th}{\sin kx}\right|} \]
    12. Simplified30.9%

      \[\leadsto ky \cdot \color{blue}{\left|\frac{th}{\sin kx}\right|} \]

    if 3.49999999999999986e-81 < ky < 4.3000000000000002e40

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/95.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 54.5%

      \[\leadsto \color{blue}{\sin th} \]

    if 4.3000000000000002e40 < ky

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.5%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. un-div-inv99.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    6. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    7. Taylor expanded in kx around 0 22.2%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
    8. Step-by-step derivation
      1. associate-/r/22.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses22.2%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt11.3%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity11.3%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod28.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow228.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    9. Applied egg-rr28.0%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow228.0%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square33.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    11. Simplified33.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification29.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.22 \cdot 10^{-177}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 3.5 \cdot 10^{-81}:\\ \;\;\;\;ky \cdot \left|\frac{th}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 26.9% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.85 \cdot 10^{-114}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.85e-114)
   (* (sin th) (/ ky kx))
   (if (<= ky 4.3e+40) (sin th) (fabs (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.85e-114) {
		tmp = sin(th) * (ky / kx);
	} else if (ky <= 4.3e+40) {
		tmp = sin(th);
	} else {
		tmp = fabs(sin(th));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.85d-114) then
        tmp = sin(th) * (ky / kx)
    else if (ky <= 4.3d+40) then
        tmp = sin(th)
    else
        tmp = abs(sin(th))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.85e-114) {
		tmp = Math.sin(th) * (ky / kx);
	} else if (ky <= 4.3e+40) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.85e-114:
		tmp = math.sin(th) * (ky / kx)
	elif ky <= 4.3e+40:
		tmp = math.sin(th)
	else:
		tmp = math.fabs(math.sin(th))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.85e-114)
		tmp = Float64(sin(th) * Float64(ky / kx));
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.85e-114)
		tmp = sin(th) * (ky / kx);
	elseif (ky <= 4.3e+40)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.85e-114], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 4.3e+40], N[Sin[th], $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.85 \cdot 10^{-114}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

\mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\left|\sin th\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 1.84999999999999982e-114

    1. Initial program 85.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*85.4%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 29.7%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in kx around 0 20.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    7. Step-by-step derivation
      1. *-commutative20.9%

        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{kx} \]
      2. associate-/l*23.4%

        \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]
    8. Simplified23.4%

      \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]

    if 1.84999999999999982e-114 < ky < 4.3000000000000002e40

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.7%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 47.1%

      \[\leadsto \color{blue}{\sin th} \]

    if 4.3000000000000002e40 < ky

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.5%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. un-div-inv99.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    6. Applied egg-rr99.5%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    7. Taylor expanded in kx around 0 22.2%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
    8. Step-by-step derivation
      1. associate-/r/22.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses22.2%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. add-sqr-sqrt11.3%

        \[\leadsto 1 \cdot \color{blue}{\left(\sqrt{\sin th} \cdot \sqrt{\sin th}\right)} \]
      4. *-un-lft-identity11.3%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod28.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow228.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    9. Applied egg-rr28.0%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    10. Step-by-step derivation
      1. unpow228.0%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square33.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    11. Simplified33.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification29.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.85 \cdot 10^{-114}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 4.3 \cdot 10^{+40}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 27.1% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.15 \cdot 10^{-114}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.15e-114) (* ky (/ (sin th) kx)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.15e-114) {
		tmp = ky * (sin(th) / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.15d-114) then
        tmp = ky * (sin(th) / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.15e-114) {
		tmp = ky * (Math.sin(th) / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.15e-114:
		tmp = ky * (math.sin(th) / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.15e-114)
		tmp = Float64(ky * Float64(sin(th) / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.15e-114)
		tmp = ky * (sin(th) / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.15e-114], N[(ky * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.15 \cdot 10^{-114}:\\
\;\;\;\;ky \cdot \frac{\sin th}{kx}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 1.15e-114

    1. Initial program 85.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*85.4%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 29.7%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in kx around 0 20.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    7. Step-by-step derivation
      1. associate-/l*23.5%

        \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]
    8. Simplified23.5%

      \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]

    if 1.15e-114 < ky

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 33.0%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.15 \cdot 10^{-114}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 27.1% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.42 \cdot 10^{-114}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.42e-114) (* (sin th) (/ ky kx)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.42e-114) {
		tmp = sin(th) * (ky / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.42d-114) then
        tmp = sin(th) * (ky / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.42e-114) {
		tmp = Math.sin(th) * (ky / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.42e-114:
		tmp = math.sin(th) * (ky / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.42e-114)
		tmp = Float64(sin(th) * Float64(ky / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.42e-114)
		tmp = sin(th) * (ky / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.42e-114], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.42 \cdot 10^{-114}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 1.42e-114

    1. Initial program 85.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*85.4%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg85.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow285.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 29.7%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in kx around 0 20.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    7. Step-by-step derivation
      1. *-commutative20.9%

        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{kx} \]
      2. associate-/l*23.4%

        \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]
    8. Simplified23.4%

      \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{kx}} \]

    if 1.42e-114 < ky

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 33.0%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.42 \cdot 10^{-114}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 26.0% accurate, 6.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 2.8 \cdot 10^{-35}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= kx 2.8e-35) (sin th) (* ky (/ th kx))))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 2.8e-35) {
		tmp = sin(th);
	} else {
		tmp = ky * (th / kx);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 2.8d-35) then
        tmp = sin(th)
    else
        tmp = ky * (th / kx)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 2.8e-35) {
		tmp = Math.sin(th);
	} else {
		tmp = ky * (th / kx);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 2.8e-35:
		tmp = math.sin(th)
	else:
		tmp = ky * (th / kx)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 2.8e-35)
		tmp = sin(th);
	else
		tmp = Float64(ky * Float64(th / kx));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 2.8e-35)
		tmp = sin(th);
	else
		tmp = ky * (th / kx);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 2.8e-35], N[Sin[th], $MachinePrecision], N[(ky * N[(th / kx), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 2.8 \cdot 10^{-35}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;ky \cdot \frac{th}{kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 2.8e-35

    1. Initial program 87.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/84.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*87.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow287.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow287.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow287.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg87.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow287.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 29.1%

      \[\leadsto \color{blue}{\sin th} \]

    if 2.8e-35 < kx

    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-*l/98.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 40.8%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in th around 0 27.9%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    7. Step-by-step derivation
      1. associate-/l*29.0%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified29.0%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    9. Taylor expanded in kx around 0 27.3%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{kx}} \]
    10. Step-by-step derivation
      1. associate-/l*28.6%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{kx}} \]
    11. Simplified28.6%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{kx}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.8 \cdot 10^{-35}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 16.5% accurate, 70.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 2.3 \cdot 10^{-109}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= kx 2.3e-109) th (* ky (/ th kx))))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 2.3e-109) {
		tmp = th;
	} else {
		tmp = ky * (th / kx);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 2.3d-109) then
        tmp = th
    else
        tmp = ky * (th / kx)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 2.3e-109) {
		tmp = th;
	} else {
		tmp = ky * (th / kx);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 2.3e-109:
		tmp = th
	else:
		tmp = ky * (th / kx)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 2.3e-109)
		tmp = th;
	else
		tmp = Float64(ky * Float64(th / kx));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 2.3e-109)
		tmp = th;
	else
		tmp = ky * (th / kx);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 2.3e-109], th, N[(ky * N[(th / kx), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 2.3 \cdot 10^{-109}:\\
\;\;\;\;th\\

\mathbf{else}:\\
\;\;\;\;ky \cdot \frac{th}{kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 2.3000000000000001e-109

    1. Initial program 86.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/82.9%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*86.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow286.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow286.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow286.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg86.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow286.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. clear-num99.5%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. un-div-inv99.7%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    6. Applied egg-rr99.7%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    7. Taylor expanded in kx around 0 27.9%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
    8. Taylor expanded in th around 0 14.6%

      \[\leadsto \color{blue}{th} \]

    if 2.3000000000000001e-109 < kx

    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-*l/98.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. associate-/l*99.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      3. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      4. sqr-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      5. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
      6. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      7. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
      8. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
      9. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
      10. sin-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
      11. sqr-neg99.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      12. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in ky around 0 40.0%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Taylor expanded in th around 0 24.6%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    7. Step-by-step derivation
      1. associate-/l*25.6%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    8. Simplified25.6%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    9. Taylor expanded in kx around 0 24.2%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{kx}} \]
    10. Step-by-step derivation
      1. associate-/l*25.2%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{kx}} \]
    11. Simplified25.2%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{kx}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification18.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.3 \cdot 10^{-109}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 13.8% 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 90.6%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. associate-*l/88.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    2. associate-/l*90.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    3. unpow290.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
    4. sqr-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \]
    5. sin-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \]
    6. sin-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    7. unpow290.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \]
    8. unpow290.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    9. sin-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right) + {\sin ky}^{2}}} \]
    10. sin-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)} + {\sin ky}^{2}}} \]
    11. sqr-neg90.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
    12. unpow290.6%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. clear-num99.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    2. un-div-inv99.6%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
  6. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
  7. Taylor expanded in kx around 0 23.0%

    \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
  8. Taylor expanded in th around 0 11.7%

    \[\leadsto \color{blue}{th} \]
  9. Final simplification11.7%

    \[\leadsto th \]
  10. Add Preprocessing

Reproduce

?
herbie shell --seed 2024044 
(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)))