Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.7%
Time: 25.2s
Alternatives: 17
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 17 alternatives:

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

Initial Program: 94.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.7% accurate, 1.4× speedup?

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

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}
Derivation
  1. Initial program 92.2%

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

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

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

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

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

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

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

Alternative 2: 64.3% accurate, 1.0× speedup?

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

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

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

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

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 91.7%

      \[\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-*r/91.6%

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 th) < 2e-16

    1. Initial program 95.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}} \]
    7. Step-by-step derivation
      1. clear-num98.8%

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

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

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

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

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

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

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

    if 2e-16 < (sin.f64 th)

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 72.4% accurate, 1.0× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;t_2\\


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

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 th) < 2e-16

    1. Initial program 95.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}} \]
    7. Step-by-step derivation
      1. clear-num98.8%

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

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

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

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

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

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

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

    if 2e-16 < (sin.f64 th) < 0.599999999999999978

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 74.7% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-52}:\\
\;\;\;\;\sin th \cdot \frac{1}{t_1 \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 5e-52

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 5: 74.6% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-52}:\\
\;\;\;\;\sin th \cdot \frac{1}{t_1 \cdot \frac{1}{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-/r/99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 5e-52

    1. Initial program 83.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 6: 99.6% accurate, 1.4× speedup?

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

\\
\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}
\end{array}
Derivation
  1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

Alternative 7: 47.9% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 10^{-62}:\\
\;\;\;\;\sin th \cdot \frac{1}{\frac{\sin kx}{ky} + 0.5 \cdot \frac{ky}{kx}}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000001e-4 < (sin.f64 ky) < 1e-62

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky} + \left(0.5 \cdot \frac{1}{\sin kx} - -0.16666666666666666 \cdot \sin kx\right) \cdot ky}} \cdot \sin th \]
    9. Step-by-step derivation
      1. *-commutative45.1%

        \[\leadsto \frac{1}{\frac{\sin kx}{ky} + \color{blue}{ky \cdot \left(0.5 \cdot \frac{1}{\sin kx} - -0.16666666666666666 \cdot \sin kx\right)}} \cdot \sin th \]
      2. cancel-sign-sub-inv45.1%

        \[\leadsto \frac{1}{\frac{\sin kx}{ky} + ky \cdot \color{blue}{\left(0.5 \cdot \frac{1}{\sin kx} + \left(--0.16666666666666666\right) \cdot \sin kx\right)}} \cdot \sin th \]
      3. associate-*r/45.1%

        \[\leadsto \frac{1}{\frac{\sin kx}{ky} + ky \cdot \left(\color{blue}{\frac{0.5 \cdot 1}{\sin kx}} + \left(--0.16666666666666666\right) \cdot \sin kx\right)} \cdot \sin th \]
      4. metadata-eval45.1%

        \[\leadsto \frac{1}{\frac{\sin kx}{ky} + ky \cdot \left(\frac{\color{blue}{0.5}}{\sin kx} + \left(--0.16666666666666666\right) \cdot \sin kx\right)} \cdot \sin th \]
      5. metadata-eval45.1%

        \[\leadsto \frac{1}{\frac{\sin kx}{ky} + ky \cdot \left(\frac{0.5}{\sin kx} + \color{blue}{0.16666666666666666} \cdot \sin kx\right)} \cdot \sin th \]
    10. Simplified45.1%

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky} + ky \cdot \left(\frac{0.5}{\sin kx} + 0.16666666666666666 \cdot \sin kx\right)}} \cdot \sin th \]
    11. Taylor expanded in kx around 0 45.1%

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

    if 1e-62 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.0005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-62}:\\ \;\;\;\;\sin th \cdot \frac{1}{\frac{\sin kx}{ky} + 0.5 \cdot \frac{ky}{kx}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 8: 47.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.0005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-62}:\\ \;\;\;\;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.0005)
   (fabs (sin th))
   (if (<= (sin ky) 1e-62) (* ky (/ (sin th) (sin kx))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.0005) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 1e-62) {
		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.0005d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 1d-62) 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.0005) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 1e-62) {
		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.0005:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 1e-62:
		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.0005)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-62)
		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.0005)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-62)
		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.0005], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-62], 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.0005:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 10^{-62}:\\
\;\;\;\;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) < -5.0000000000000001e-4

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000001e-4 < (sin.f64 ky) < 1e-62

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin th \cdot ky}{\sin kx}} \]
    7. Step-by-step derivation
      1. *-commutative41.8%

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

        \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{\sin kx}} \]
    8. Simplified44.5%

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

    if 1e-62 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

Alternative 9: 33.5% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;ky \leq -1.75 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -190000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -2.5 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -6.4 \cdot 10^{-80}:\\ \;\;\;\;\frac{th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;ky \leq -1.95 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -9.5 \cdot 10^{-152}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;ky \leq 9.2 \cdot 10^{-184}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))))
   (if (<= ky -1.75e+159)
     t_1
     (if (<= ky -190000.0)
       (sin th)
       (if (<= ky -2.5e-5)
         t_1
         (if (<= ky -6.4e-80)
           (/ th (/ (sin kx) ky))
           (if (<= ky -1.95e-147)
             t_1
             (if (<= ky -9.5e-152)
               (* th (/ ky (sin kx)))
               (if (<= ky 9.2e-184) (/ (sin th) (/ kx ky)) (sin th))))))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double tmp;
	if (ky <= -1.75e+159) {
		tmp = t_1;
	} else if (ky <= -190000.0) {
		tmp = sin(th);
	} else if (ky <= -2.5e-5) {
		tmp = t_1;
	} else if (ky <= -6.4e-80) {
		tmp = th / (sin(kx) / ky);
	} else if (ky <= -1.95e-147) {
		tmp = t_1;
	} else if (ky <= -9.5e-152) {
		tmp = th * (ky / sin(kx));
	} else if (ky <= 9.2e-184) {
		tmp = sin(th) / (kx / ky);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = abs(sin(th))
    if (ky <= (-1.75d+159)) then
        tmp = t_1
    else if (ky <= (-190000.0d0)) then
        tmp = sin(th)
    else if (ky <= (-2.5d-5)) then
        tmp = t_1
    else if (ky <= (-6.4d-80)) then
        tmp = th / (sin(kx) / ky)
    else if (ky <= (-1.95d-147)) then
        tmp = t_1
    else if (ky <= (-9.5d-152)) then
        tmp = th * (ky / sin(kx))
    else if (ky <= 9.2d-184) then
        tmp = sin(th) / (kx / ky)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.abs(Math.sin(th));
	double tmp;
	if (ky <= -1.75e+159) {
		tmp = t_1;
	} else if (ky <= -190000.0) {
		tmp = Math.sin(th);
	} else if (ky <= -2.5e-5) {
		tmp = t_1;
	} else if (ky <= -6.4e-80) {
		tmp = th / (Math.sin(kx) / ky);
	} else if (ky <= -1.95e-147) {
		tmp = t_1;
	} else if (ky <= -9.5e-152) {
		tmp = th * (ky / Math.sin(kx));
	} else if (ky <= 9.2e-184) {
		tmp = Math.sin(th) / (kx / ky);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	tmp = 0
	if ky <= -1.75e+159:
		tmp = t_1
	elif ky <= -190000.0:
		tmp = math.sin(th)
	elif ky <= -2.5e-5:
		tmp = t_1
	elif ky <= -6.4e-80:
		tmp = th / (math.sin(kx) / ky)
	elif ky <= -1.95e-147:
		tmp = t_1
	elif ky <= -9.5e-152:
		tmp = th * (ky / math.sin(kx))
	elif ky <= 9.2e-184:
		tmp = math.sin(th) / (kx / ky)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	tmp = 0.0
	if (ky <= -1.75e+159)
		tmp = t_1;
	elseif (ky <= -190000.0)
		tmp = sin(th);
	elseif (ky <= -2.5e-5)
		tmp = t_1;
	elseif (ky <= -6.4e-80)
		tmp = Float64(th / Float64(sin(kx) / ky));
	elseif (ky <= -1.95e-147)
		tmp = t_1;
	elseif (ky <= -9.5e-152)
		tmp = Float64(th * Float64(ky / sin(kx)));
	elseif (ky <= 9.2e-184)
		tmp = Float64(sin(th) / Float64(kx / ky));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	tmp = 0.0;
	if (ky <= -1.75e+159)
		tmp = t_1;
	elseif (ky <= -190000.0)
		tmp = sin(th);
	elseif (ky <= -2.5e-5)
		tmp = t_1;
	elseif (ky <= -6.4e-80)
		tmp = th / (sin(kx) / ky);
	elseif (ky <= -1.95e-147)
		tmp = t_1;
	elseif (ky <= -9.5e-152)
		tmp = th * (ky / sin(kx));
	elseif (ky <= 9.2e-184)
		tmp = sin(th) / (kx / ky);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[ky, -1.75e+159], t$95$1, If[LessEqual[ky, -190000.0], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -2.5e-5], t$95$1, If[LessEqual[ky, -6.4e-80], N[(th / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, -1.95e-147], t$95$1, If[LessEqual[ky, -9.5e-152], N[(th * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 9.2e-184], N[(N[Sin[th], $MachinePrecision] / N[(kx / ky), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;ky \leq -1.75 \cdot 10^{+159}:\\
\;\;\;\;t_1\\

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

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

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

\mathbf{elif}\;ky \leq -1.95 \cdot 10^{-147}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if ky < -1.75e159 or -1.9e5 < ky < -2.50000000000000012e-5 or -6.3999999999999998e-80 < ky < -1.9499999999999999e-147

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75e159 < ky < -1.9e5 or 9.1999999999999998e-184 < ky

    1. Initial program 97.5%

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

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

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

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

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

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

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

    if -2.50000000000000012e-5 < ky < -6.3999999999999998e-80

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    8. Step-by-step derivation
      1. *-commutative15.5%

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

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

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

    if -1.9499999999999999e-147 < ky < -9.49999999999999925e-152

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{th}{\frac{\sin kx}{ky}}} \]
    10. Step-by-step derivation
      1. div-inv36.8%

        \[\leadsto \color{blue}{th \cdot \frac{1}{\frac{\sin kx}{ky}}} \]
      2. clear-num36.8%

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

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

    if -9.49999999999999925e-152 < ky < 9.1999999999999998e-184

    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.75 \cdot 10^{+159}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -190000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -2.5 \cdot 10^{-5}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -6.4 \cdot 10^{-80}:\\ \;\;\;\;\frac{th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;ky \leq -1.95 \cdot 10^{-147}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -9.5 \cdot 10^{-152}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;ky \leq 9.2 \cdot 10^{-184}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 10: 33.9% accurate, 3.4× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < -1.75e159

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75e159 < ky < -3.10000000000000009 or 6.1000000000000002e-183 < ky

    1. Initial program 97.5%

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

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

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

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

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

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

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

    if -3.10000000000000009 < ky < -6.20000000000000032e-133

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    8. Step-by-step derivation
      1. *-commutative16.9%

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

        \[\leadsto \color{blue}{\frac{th}{\frac{\sin kx}{ky}}} \]
    9. Simplified19.5%

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{th \cdot ky}{\sin kx}}\right| \]
      4. *-commutative27.6%

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

        \[\leadsto \left|\color{blue}{\frac{ky}{\frac{\sin kx}{th}}}\right| \]
    13. Simplified30.2%

      \[\leadsto \color{blue}{\left|\frac{ky}{\frac{\sin kx}{th}}\right|} \]
    14. Step-by-step derivation
      1. associate-/r/30.2%

        \[\leadsto \left|\color{blue}{\frac{ky}{\sin kx} \cdot th}\right| \]
    15. Applied egg-rr30.2%

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

    if -6.20000000000000032e-133 < ky < 6.1000000000000002e-183

    1. Initial program 70.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.75 \cdot 10^{+159}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -3.1:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -6.2 \cdot 10^{-133}:\\ \;\;\;\;\left|th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 6.1 \cdot 10^{-183}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 31.4% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.9e5 or 8.00000000000000053e-63 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -1.9e5 < ky < 8.00000000000000053e-63

    1. Initial program 83.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    8. Step-by-step derivation
      1. *-commutative26.7%

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

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

      \[\leadsto \color{blue}{\frac{th}{\frac{\sin kx}{ky}}} \]
    10. Step-by-step derivation
      1. div-inv29.3%

        \[\leadsto \color{blue}{th \cdot \frac{1}{\frac{\sin kx}{ky}}} \]
      2. clear-num29.3%

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

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

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

Alternative 12: 31.4% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.9e5 or 8.00000000000000053e-63 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -1.9e5 < ky < 8.00000000000000053e-63

    1. Initial program 83.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    8. Step-by-step derivation
      1. *-commutative26.7%

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

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

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

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

Alternative 13: 33.3% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.9e5 or 7.5000000000000004e-183 < ky

    1. Initial program 97.9%

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

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

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

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

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

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

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

    if -1.9e5 < ky < 7.5000000000000004e-183

    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 31.0% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -7.79999999999999986e-4 or 4.0000000000000002e-184 < ky

    1. Initial program 97.9%

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

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

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

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

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

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

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

    if -7.79999999999999986e-4 < ky < 4.0000000000000002e-184

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 20.8% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.32 \cdot 10^{+16}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.32e16 or 1e-62 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

    if -1.32e16 < ky < 1e-62

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified23.0%

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    14. Applied egg-rr23.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.32 \cdot 10^{+16}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 10^{-62}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 16: 20.8% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.32 \cdot 10^{+16}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.32e16 or 5.50000000000000022e-62 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

    if -1.32e16 < ky < 5.50000000000000022e-62

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.32 \cdot 10^{+16}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 5.5 \cdot 10^{-62}:\\ \;\;\;\;\frac{th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 17: 14.0% accurate, 709.0× speedup?

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

\\
th
\end{array}
Derivation
  1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  6. Final simplification14.3%

    \[\leadsto th \]

Reproduce

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