Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 23.9s
Alternatives: 20
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 20 alternatives:

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

Initial Program: 93.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 76.9% accurate, 0.8× speedup?

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

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

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

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

\mathbf{elif}\;\sin kx \leq 0.78:\\
\;\;\;\;\sin ky \cdot t_2\\

\mathbf{elif}\;\sin kx \leq 0.9:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{t_2}{\frac{1}{\sin ky}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 kx) < -0.77000000000000002 or 0.78000000000000003 < (sin.f64 kx) < 0.900000000000000022

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.77000000000000002 < (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\left|\sin kx\right|}} \cdot ky \]
    10. Applied egg-rr49.6%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 3.9999999999999998e-7

    1. Initial program 86.0%

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

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

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

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

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

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

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

    if 3.9999999999999998e-7 < (sin.f64 kx) < 0.78000000000000003

    1. Initial program 99.5%

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

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

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

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

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

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

    if 0.900000000000000022 < (sin.f64 kx)

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.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. Step-by-step derivation
      1. clear-num99.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 76.9% accurate, 0.8× speedup?

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

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

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

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

\mathbf{elif}\;\sin kx \leq 0.78:\\
\;\;\;\;\sin ky \cdot t_1\\

\mathbf{elif}\;\sin kx \leq 0.9:\\
\;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{\frac{1}{\sin ky}}\\


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

    if -0.77000000000000002 < (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\left|\sin kx\right|}} \cdot ky \]
    10. Applied egg-rr49.6%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 3.9999999999999998e-7

    1. Initial program 86.0%

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

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

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

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

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

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

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

    if 3.9999999999999998e-7 < (sin.f64 kx) < 0.78000000000000003

    1. Initial program 99.5%

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

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

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

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

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

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

    if 0.78000000000000003 < (sin.f64 kx) < 0.900000000000000022

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.900000000000000022 < (sin.f64 kx)

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow299.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. Step-by-step derivation
      1. clear-num99.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 78.8% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;\sin ky \leq -0.0005:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \left|\frac{1}{\sin ky}\right|\right)\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\sin th \cdot \frac{1}{\sin ky}\right)} \cdot \sin ky \]
      4. associate-*l*2.8%

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

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

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

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

        \[\leadsto \sin th \cdot \left(\sqrt{\color{blue}{{\sin ky}^{-1}} \cdot \frac{1}{\sin ky}} \cdot \sin ky\right) \]
      4. inv-pow72.5%

        \[\leadsto \sin th \cdot \left(\sqrt{{\sin ky}^{-1} \cdot \color{blue}{{\sin ky}^{-1}}} \cdot \sin ky\right) \]
      5. pow-prod-up72.5%

        \[\leadsto \sin th \cdot \left(\sqrt{\color{blue}{{\sin ky}^{\left(-1 + -1\right)}}} \cdot \sin ky\right) \]
      6. metadata-eval72.5%

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

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

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

        \[\leadsto \sin th \cdot \left(\sqrt{\color{blue}{{\sin ky}^{-1} \cdot {\sin ky}^{-1}}} \cdot \sin ky\right) \]
      3. unpow-172.5%

        \[\leadsto \sin th \cdot \left(\sqrt{\color{blue}{\frac{1}{\sin ky}} \cdot {\sin ky}^{-1}} \cdot \sin ky\right) \]
      4. unpow-172.5%

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

        \[\leadsto \sin th \cdot \left(\color{blue}{\left|\frac{1}{\sin ky}\right|} \cdot \sin ky\right) \]
    10. Simplified72.5%

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

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

    1. Initial program 86.6%

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow286.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. Step-by-step derivation
      1. clear-num99.5%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000005e-4 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 5: 40.6% accurate, 1.2× speedup?

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

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

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

\mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-175}:\\
\;\;\;\;-th\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 ky) < -1.00000000000000008e-5 or -1e-175 < (sin.f64 ky) < -2e-205

    1. Initial program 96.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < -2.00000000000000008e-153

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000008e-153 < (sin.f64 ky) < -1e-175

    1. Initial program 2.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\sin ky} \cdot th \]
      4. associate-*l/2.7%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin ky} \cdot \sin ky\right)} \cdot th \]
      5. lft-mult-inverse2.7%

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

        \[\leadsto \color{blue}{th} \]
      7. add-sqr-sqrt2.2%

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

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    7. Applied egg-rr27.6%

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

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

        \[\leadsto \color{blue}{-th} \]
    10. Simplified100.0%

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

    if -2e-205 < (sin.f64 ky) < 4.9999999999999995e-97

    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{kx}{ky}}} \]
    11. Simplified48.0%

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

    if 4.9999999999999995e-97 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-5}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-153}:\\ \;\;\;\;\frac{ky \cdot \sin th}{kx}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-175}:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-205}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-97}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 77.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\left|\sin kx\right|}} \cdot ky \]
    10. Applied egg-rr47.9%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 3.9999999999999998e-7

    1. Initial program 86.0%

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

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

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

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

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

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

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

    if 3.9999999999999998e-7 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

Alternative 7: 61.3% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.99999999999999947e-4 < (sin.f64 ky) < 9.99999999999999999e-15

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\left|\sin kx\right|}} \cdot ky \]
    10. Applied egg-rr79.3%

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 8: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 75.6% accurate, 1.7× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < -350

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

    if -350 < th < 0.0539999999999999994

    1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0539999999999999994 < th

    1. Initial program 97.9%

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

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

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

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

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

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

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

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

Alternative 10: 75.5% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;th \leq 0.00033:\\
\;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < -350

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

    if -350 < th < 3.3e-4

    1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.3e-4 < th

    1. Initial program 97.9%

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

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

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

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

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

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

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

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

Alternative 11: 48.2% accurate, 1.7× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5e-31 < (sin.f64 ky) < 4.9999999999999995e-97

    1. Initial program 82.9%

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

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

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

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

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

    if 4.9999999999999995e-97 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 12: 48.2% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5e-31 < (sin.f64 ky) < 4.9999999999999995e-97

    1. Initial program 82.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999995e-97 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 13: 48.2% accurate, 1.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5e-31 < (sin.f64 ky) < 4.9999999999999995e-97

    1. Initial program 82.9%

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

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

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

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

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

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

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

    if 4.9999999999999995e-97 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 14: 32.2% accurate, 6.3× speedup?

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

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

\mathbf{elif}\;ky \leq -3.9 \cdot 10^{-163}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -1.45 \cdot 10^{-214}:\\
\;\;\;\;-th\\

\mathbf{elif}\;ky \leq 1.5 \cdot 10^{-96}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -5.8e8 or 1.5e-96 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -5.8e8 < ky < -3.9000000000000002e-163 or -1.44999999999999993e-214 < ky < 1.5e-96

    1. Initial program 89.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.9000000000000002e-163 < ky < -1.44999999999999993e-214

    1. Initial program 42.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot th} \]
      3. *-un-lft-identity2.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\sin ky} \cdot th \]
      4. associate-*l/2.4%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin ky} \cdot \sin ky\right)} \cdot th \]
      5. lft-mult-inverse2.4%

        \[\leadsto \color{blue}{1} \cdot th \]
      6. *-un-lft-identity2.4%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      8. sqrt-unprod10.9%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    7. Applied egg-rr10.9%

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

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

        \[\leadsto \color{blue}{-th} \]
    10. Simplified43.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -580000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -3.9 \cdot 10^{-163}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{elif}\;ky \leq -1.45 \cdot 10^{-214}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 1.5 \cdot 10^{-96}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 15: 34.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.4e8 or 1.05000000000000001e-96 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -8.4e8 < ky < 1.05000000000000001e-96

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 34.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.4e8 or 7.9999999999999993e-96 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -8.4e8 < ky < 7.9999999999999993e-96

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{kx}{ky}}} \]
    11. Simplified32.4%

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

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

Alternative 17: 26.9% accurate, 6.7× speedup?

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

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

\mathbf{elif}\;ky \leq -4.5 \cdot 10^{-296}:\\
\;\;\;\;-th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.4e8 or -4.5000000000000002e-296 < ky

    1. Initial program 96.8%

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

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

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

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

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

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

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

    if -8.4e8 < ky < -4.5000000000000002e-296

    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot th} \]
      3. *-un-lft-identity3.3%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\sin ky} \cdot th \]
      4. associate-*l/3.3%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin ky} \cdot \sin ky\right)} \cdot th \]
      5. lft-mult-inverse3.3%

        \[\leadsto \color{blue}{1} \cdot th \]
      6. *-un-lft-identity3.3%

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

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

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    7. Applied egg-rr11.6%

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

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

        \[\leadsto \color{blue}{-th} \]
    10. Simplified15.9%

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

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

Alternative 18: 25.4% accurate, 6.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 3.49999999999999995e-6

    1. Initial program 90.9%

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

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

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

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

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

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

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

    if 3.49999999999999995e-6 < kx

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot th} \]
      3. *-un-lft-identity4.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\sin ky} \cdot th \]
      4. associate-*l/4.4%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin ky} \cdot \sin ky\right)} \cdot th \]
      5. lft-mult-inverse4.4%

        \[\leadsto \color{blue}{1} \cdot th \]
      6. *-un-lft-identity4.4%

        \[\leadsto \color{blue}{th} \]
      7. add-sqr-sqrt1.8%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      8. sqrt-unprod14.7%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    7. Applied egg-rr14.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 3.5 \cdot 10^{-6}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sqrt{th \cdot th}\\ \end{array} \]

Alternative 19: 17.1% accurate, 174.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -1.55 \cdot 10^{-298}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= ky -1.55e-298) (- th) th))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -1.55e-298) {
		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 <= (-1.55d-298)) 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 <= -1.55e-298) {
		tmp = -th;
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -1.55e-298:
		tmp = -th
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -1.55e-298)
		tmp = Float64(-th);
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -1.55e-298)
		tmp = -th;
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -1.55e-298], (-th), th]
\begin{array}{l}

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

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


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

    1. Initial program 89.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot th} \]
      3. *-un-lft-identity6.9%

        \[\leadsto \frac{\color{blue}{1 \cdot \sin ky}}{\sin ky} \cdot th \]
      4. associate-*l/6.9%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin ky} \cdot \sin ky\right)} \cdot th \]
      5. lft-mult-inverse6.9%

        \[\leadsto \color{blue}{1} \cdot th \]
      6. *-un-lft-identity6.9%

        \[\leadsto \color{blue}{th} \]
      7. add-sqr-sqrt3.5%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      8. sqrt-unprod10.4%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    7. Applied egg-rr10.4%

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

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

        \[\leadsto \color{blue}{-th} \]
    10. Simplified17.1%

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

    if -1.5500000000000001e-298 < 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.3%

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

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

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

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

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

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

Alternative 20: 13.6% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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