Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 18.7s
Alternatives: 14
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 14 alternatives:

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

Initial Program: 94.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

Alternative 2: 60.3% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified62.0%

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

    if -9.9999999999999997e-73 < (sin.f64 ky) < 4.99999999999999973e-284

    1. Initial program 82.3%

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

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

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

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

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

        \[\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 ky around 0 99.7%

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

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

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

    if 4.99999999999999973e-284 < (sin.f64 ky) < 4.99999999999999963e-77

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999963e-77 < (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. associate-*l/99.6%

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      6. hypot-def99.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 61.6%

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

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

Alternative 3: 81.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 th) < 4.00000000000000015e-25

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}{th}} \]
      11. unpow294.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. div-inv99.6%

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

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

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

    if 4.00000000000000015e-25 < (sin.f64 th)

    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.5%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 81.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 th) < 4.00000000000000015e-25

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}{th}} \]
      11. unpow294.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. associate-/r/99.8%

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

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

    if 4.00000000000000015e-25 < (sin.f64 th)

    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.5%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 78.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified60.6%

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

    if -0.0100000000000000002 < (sin.f64 ky) < 2.0000000000000001e-18

    1. Initial program 88.8%

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

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

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

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

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

        \[\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 ky around 0 99.7%

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

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

    if 2.0000000000000001e-18 < (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. associate-*l/99.5%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.01:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-18}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\mathsf{hypot}\left(ky, \sin kx\right)}\\ \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 94.5%

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

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

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

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

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

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

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

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

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

Alternative 7: 55.5% accurate, 1.7× speedup?

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

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-132}:\\
\;\;\;\;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) < -9.9999999999999997e-73

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified62.0%

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

    if -9.9999999999999997e-73 < (sin.f64 ky) < 4.9999999999999999e-132

    1. Initial program 84.0%

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

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

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

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

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

        \[\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 ky around 0 99.7%

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

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

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

    if 4.9999999999999999e-132 < (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. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

Alternative 8: 55.5% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified62.0%

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

    if -9.9999999999999997e-73 < (sin.f64 ky) < 4.9999999999999999e-132

    1. Initial program 84.0%

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

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

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

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

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

        \[\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 ky around 0 55.8%

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

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

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

    if 4.9999999999999999e-132 < (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. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

Alternative 9: 49.0% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/94.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 ky around 0 30.0%

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified60.0%

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

    if -4.99999999999999983e-106 < (sin.f64 ky) < 4.9999999999999999e-132

    1. Initial program 82.4%

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

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

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

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

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

      \[\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/40.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999999e-132 < (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. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

Alternative 10: 51.2% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

        \[\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 ky around 0 30.9%

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified59.3%

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

    if -5.00000000000000015e-118 < (sin.f64 ky) < 4.9999999999999999e-132

    1. Initial program 82.2%

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999999e-132 < (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. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

Alternative 11: 29.9% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -5 \cdot 10^{-311} \lor \neg \left(ky \leq 9.6 \cdot 10^{+129}\right) \land ky \leq 10^{+210}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= ky -5e-311) (and (not (<= ky 9.6e+129)) (<= ky 1e+210)))
   (- (sin th))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -5e-311) || (!(ky <= 9.6e+129) && (ky <= 1e+210))) {
		tmp = -sin(th);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((ky <= (-5d-311)) .or. (.not. (ky <= 9.6d+129)) .and. (ky <= 1d+210)) then
        tmp = -sin(th)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -5e-311) || (!(ky <= 9.6e+129) && (ky <= 1e+210))) {
		tmp = -Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (ky <= -5e-311) or (not (ky <= 9.6e+129) and (ky <= 1e+210)):
		tmp = -math.sin(th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((ky <= -5e-311) || (!(ky <= 9.6e+129) && (ky <= 1e+210)))
		tmp = Float64(-sin(th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((ky <= -5e-311) || (~((ky <= 9.6e+129)) && (ky <= 1e+210)))
		tmp = -sin(th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[ky, -5e-311], And[N[Not[LessEqual[ky, 9.6e+129]], $MachinePrecision], LessEqual[ky, 1e+210]]], (-N[Sin[th], $MachinePrecision]), N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -5 \cdot 10^{-311} \lor \neg \left(ky \leq 9.6 \cdot 10^{+129}\right) \land ky \leq 10^{+210}:\\
\;\;\;\;-\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -5.00000000000023e-311 or 9.5999999999999995e129 < ky < 9.99999999999999927e209

    1. Initial program 94.0%

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

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

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

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

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

        \[\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 ky around 0 45.4%

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

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

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

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified32.3%

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

    if -5.00000000000023e-311 < ky < 9.5999999999999995e129 or 9.99999999999999927e209 < ky

    1. Initial program 95.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -5 \cdot 10^{-311} \lor \neg \left(ky \leq 9.6 \cdot 10^{+129}\right) \land ky \leq 10^{+210}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 12: 26.2% accurate, 6.7× speedup?

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

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

\mathbf{elif}\;ky \leq -2.06 \cdot 10^{-255}:\\
\;\;\;\;-th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -155 or -2.05999999999999994e-255 < ky

    1. Initial program 95.6%

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

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

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

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

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

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

    if -155 < ky < -2.05999999999999994e-255

    1. Initial program 90.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto ky \cdot \color{blue}{\left(-1 \cdot \frac{\sin th}{ky}\right)} \]
    7. Step-by-step derivation
      1. associate-*r/34.5%

        \[\leadsto ky \cdot \color{blue}{\frac{-1 \cdot \sin th}{ky}} \]
      2. neg-mul-134.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot th} \]
    10. Step-by-step derivation
      1. mul-1-neg25.9%

        \[\leadsto \color{blue}{-th} \]
    11. Simplified25.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -155:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -2.06 \cdot 10^{-255}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 13: 16.6% accurate, 174.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -2.1 \cdot 10^{-233}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= ky -2.1e-233) (- th) th))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -2.1e-233) {
		tmp = -th;
	} else {
		tmp = th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= (-2.1d-233)) then
        tmp = -th
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -2.1e-233) {
		tmp = -th;
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -2.1e-233:
		tmp = -th
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -2.1e-233)
		tmp = Float64(-th);
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -2.1e-233)
		tmp = -th;
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -2.1e-233], (-th), th]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.0999999999999999e-233

    1. Initial program 95.5%

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

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

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

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

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

        \[\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 ky around 0 43.7%

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

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

      \[\leadsto ky \cdot \color{blue}{\left(-1 \cdot \frac{\sin th}{ky}\right)} \]
    7. Step-by-step derivation
      1. associate-*r/29.3%

        \[\leadsto ky \cdot \color{blue}{\frac{-1 \cdot \sin th}{ky}} \]
      2. neg-mul-129.3%

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

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

      \[\leadsto \color{blue}{-1 \cdot th} \]
    10. Step-by-step derivation
      1. mul-1-neg21.5%

        \[\leadsto \color{blue}{-th} \]
    11. Simplified21.5%

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

    if -2.0999999999999999e-233 < ky

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.1 \cdot 10^{-233}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 14: 13.7% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
  4. Taylor expanded in th around 0 47.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/47.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  8. Final simplification15.0%

    \[\leadsto th \]

Reproduce

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