Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 43.8s
Alternatives: 19
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 alternatives:

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

Initial Program: 93.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 94.4%

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

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

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

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

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

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

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

Alternative 2: 53.9% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000014e-17 < (sin.f64 ky) < -3.99999999999999999e-305

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

    if -3.99999999999999999e-305 < (sin.f64 ky) < 1.0000000000000001e-18

    1. Initial program 85.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Step-by-step derivation
      1. 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.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left|\frac{ky}{\sin kx}\right|}}{\frac{1}{\sin th}} \]
    10. Simplified84.3%

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

    if 1.0000000000000001e-18 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 3: 70.8% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.0000000000000001e-18

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}\right)\right)} - 1 \]
      6. +-commutative33.7%

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

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

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

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

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

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

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

    if 1.0000000000000001e-18 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 4: 76.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.0000000000000001e-18

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}\right)\right)} - 1 \]
      6. +-commutative34.5%

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\sqrt{\color{blue}{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}}\right)\right)} - 1 \]
      7. hypot-udef38.1%

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

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

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

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

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

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

    if 1.0000000000000001e-18 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 5: 76.7% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

      \[\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{{\sin ky}^{2} + \color{blue}{\sin kx \cdot \sin kx}}}{\sin th}} \]
      4. sqr-neg99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}} \cdot \frac{1}{th} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      4. unpow247.3%

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot 1}{th}} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      7. *-commutative47.5%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right)} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      9. associate-*r*47.3%

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right) + \color{blue}{\left(0.16666666666666666 \cdot th\right) \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    6. Simplified47.3%

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.0000000000000001e-18

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}\right)\right)} - 1 \]
      6. +-commutative34.5%

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\sqrt{\color{blue}{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}}\right)\right)} - 1 \]
      7. hypot-udef38.1%

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

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

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

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

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

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

    if 1.0000000000000001e-18 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 6: 76.7% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

        \[\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}}} \]
      4. hypot-udef99.5%

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.0000000000000001e-18

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}\right)\right)} - 1 \]
      6. +-commutative34.5%

        \[\leadsto e^{\mathsf{log1p}\left(ky \cdot \left(\sin th \cdot \frac{1}{\sqrt{\color{blue}{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}}\right)\right)} - 1 \]
      7. hypot-udef38.1%

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

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

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

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

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

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

    if 1.0000000000000001e-18 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 7: 41.2% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 10^{-146}:\\
\;\;\;\;\frac{\frac{ky}{kx}}{\frac{1}{\sin th}}\\

\mathbf{elif}\;\sin ky \leq 10^{-74}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-32}:\\
\;\;\;\;\frac{\frac{ky}{\sin kx}}{th \cdot 0.16666666666666666 + \frac{1}{th}}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999923e-66 < (sin.f64 ky) < 1.00000000000000003e-146

    1. Initial program 84.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-146 < (sin.f64 ky) < 9.99999999999999958e-75 or 5e-32 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if 9.99999999999999958e-75 < (sin.f64 ky) < 5e-32

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-65}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-146}:\\ \;\;\;\;\frac{\frac{ky}{kx}}{\frac{1}{\sin th}}\\ \mathbf{elif}\;\sin ky \leq 10^{-74}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-32}:\\ \;\;\;\;\frac{\frac{ky}{\sin kx}}{th \cdot 0.16666666666666666 + \frac{1}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 8: 33.4% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 10^{-146}:\\
\;\;\;\;\frac{\frac{ky}{kx}}{\frac{1}{\sin th}}\\

\mathbf{elif}\;\sin ky \leq 10^{-74}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-32}:\\
\;\;\;\;\frac{\frac{ky}{\sin kx}}{th \cdot 0.16666666666666666 + \frac{1}{th}}\\

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


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

    1. Initial program 91.7%

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

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

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

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

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

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

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

        \[\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}}} \]
      4. hypot-udef91.6%

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-146 < (sin.f64 ky) < 9.99999999999999958e-75 or 5e-32 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if 9.99999999999999958e-75 < (sin.f64 ky) < 5e-32

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 73.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq -2.26 \cdot 10^{-7} \lor \neg \left(th \leq 4.6 \cdot 10^{+25}\right):\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= th -2.26e-7) (not (<= th 4.6e+25)))
   (/
    (sin th)
    (* (hypot (sin kx) (sin ky)) (+ (* ky 0.16666666666666666) (/ 1.0 ky))))
   (* (/ (sin ky) (hypot (sin ky) (sin kx))) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((th <= -2.26e-7) || !(th <= 4.6e+25)) {
		tmp = sin(th) / (hypot(sin(kx), sin(ky)) * ((ky * 0.16666666666666666) + (1.0 / ky)));
	} else {
		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((th <= -2.26e-7) || !(th <= 4.6e+25)) {
		tmp = Math.sin(th) / (Math.hypot(Math.sin(kx), Math.sin(ky)) * ((ky * 0.16666666666666666) + (1.0 / ky)));
	} else {
		tmp = (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (th <= -2.26e-7) or not (th <= 4.6e+25):
		tmp = math.sin(th) / (math.hypot(math.sin(kx), math.sin(ky)) * ((ky * 0.16666666666666666) + (1.0 / ky)))
	else:
		tmp = (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((th <= -2.26e-7) || !(th <= 4.6e+25))
		tmp = Float64(sin(th) / Float64(hypot(sin(kx), sin(ky)) * Float64(Float64(ky * 0.16666666666666666) + Float64(1.0 / ky))));
	else
		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((th <= -2.26e-7) || ~((th <= 4.6e+25)))
		tmp = sin(th) / (hypot(sin(kx), sin(ky)) * ((ky * 0.16666666666666666) + (1.0 / ky)));
	else
		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[th, -2.26e-7], N[Not[LessEqual[th, 4.6e+25]], $MachinePrecision]], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] * N[(N[(ky * 0.16666666666666666), $MachinePrecision] + N[(1.0 / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq -2.26 \cdot 10^{-7} \lor \neg \left(th \leq 4.6 \cdot 10^{+25}\right):\\
\;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < -2.26000000000000012e-7 or 4.5999999999999996e25 < th

    1. Initial program 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.26000000000000012e-7 < th < 4.5999999999999996e25

    1. Initial program 93.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq -2.26 \cdot 10^{-7} \lor \neg \left(th \leq 4.6 \cdot 10^{+25}\right):\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \end{array} \]

Alternative 10: 32.1% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 10^{-146} \lor \neg \left(\sin ky \leq 10^{-74}\right) \land \sin ky \leq 5 \cdot 10^{-32}:\\
\;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 ky) < 1.00000000000000003e-146 or 9.99999999999999958e-75 < (sin.f64 ky) < 5e-32

    1. Initial program 92.0%

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

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

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

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

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

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

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

        \[\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}}} \]
      4. hypot-udef91.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-146 < (sin.f64 ky) < 9.99999999999999958e-75 or 5e-32 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq 10^{-146} \lor \neg \left(\sin ky \leq 10^{-74}\right) \land \sin ky \leq 5 \cdot 10^{-32}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 32.3% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 10^{-146}:\\
\;\;\;\;\frac{ky \cdot \sin th}{kx}\\

\mathbf{elif}\;\sin ky \leq 10^{-74}:\\
\;\;\;\;\sin th\\

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

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


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

    1. Initial program 91.7%

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

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

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

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

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

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

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

        \[\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}}} \]
      4. hypot-udef91.6%

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-146 < (sin.f64 ky) < 9.99999999999999958e-75 or 5e-32 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if 9.99999999999999958e-75 < (sin.f64 ky) < 5e-32

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 33.4% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 10^{-146}:\\
\;\;\;\;\frac{\frac{ky}{kx}}{\frac{1}{\sin th}}\\

\mathbf{elif}\;\sin ky \leq 10^{-74}:\\
\;\;\;\;\sin th\\

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

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


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

    1. Initial program 91.7%

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

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

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

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

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

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

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

        \[\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}}} \]
      4. hypot-udef91.6%

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-146 < (sin.f64 ky) < 9.99999999999999958e-75 or 5e-32 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if 9.99999999999999958e-75 < (sin.f64 ky) < 5e-32

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 47.7% accurate, 1.7× speedup?

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000014e-17 < (sin.f64 ky) < 5e-32

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 14: 47.7% accurate, 1.7× speedup?

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000014e-17 < (sin.f64 ky) < 5e-32

    1. Initial program 87.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0 57.8%

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 15: 47.7% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000014e-17 < (sin.f64 ky) < 5e-32

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 16: 32.1% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -9.5:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6.6 \cdot 10^{-146} \lor \neg \left(ky \leq 3.6 \cdot 10^{-70}\right) \land ky \leq 3.2 \cdot 10^{-32}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -9.5)
   (sin th)
   (if (or (<= ky 6.6e-146) (and (not (<= ky 3.6e-70)) (<= ky 3.2e-32)))
     (* ky (/ th (sin kx)))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -9.5) {
		tmp = sin(th);
	} else if ((ky <= 6.6e-146) || (!(ky <= 3.6e-70) && (ky <= 3.2e-32))) {
		tmp = ky * (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 (ky <= (-9.5d0)) then
        tmp = sin(th)
    else if ((ky <= 6.6d-146) .or. (.not. (ky <= 3.6d-70)) .and. (ky <= 3.2d-32)) then
        tmp = ky * (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 (ky <= -9.5) {
		tmp = Math.sin(th);
	} else if ((ky <= 6.6e-146) || (!(ky <= 3.6e-70) && (ky <= 3.2e-32))) {
		tmp = ky * (th / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -9.5:
		tmp = math.sin(th)
	elif (ky <= 6.6e-146) or (not (ky <= 3.6e-70) and (ky <= 3.2e-32)):
		tmp = ky * (th / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -9.5)
		tmp = sin(th);
	elseif ((ky <= 6.6e-146) || (!(ky <= 3.6e-70) && (ky <= 3.2e-32)))
		tmp = Float64(ky * Float64(th / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -9.5)
		tmp = sin(th);
	elseif ((ky <= 6.6e-146) || (~((ky <= 3.6e-70)) && (ky <= 3.2e-32)))
		tmp = ky * (th / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -9.5], N[Sin[th], $MachinePrecision], If[Or[LessEqual[ky, 6.6e-146], And[N[Not[LessEqual[ky, 3.6e-70]], $MachinePrecision], LessEqual[ky, 3.2e-32]]], N[(ky * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;ky \leq 6.6 \cdot 10^{-146} \lor \neg \left(ky \leq 3.6 \cdot 10^{-70}\right) \land ky \leq 3.2 \cdot 10^{-32}:\\
\;\;\;\;ky \cdot \frac{th}{\sin kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -9.5 or 6.6e-146 < ky < 3.6000000000000002e-70 or 3.2000000000000002e-32 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -9.5 < ky < 6.6e-146 or 3.6000000000000002e-70 < ky < 3.2000000000000002e-32

    1. Initial program 87.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    10. Step-by-step derivation
      1. clear-num34.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -9.5:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6.6 \cdot 10^{-146} \lor \neg \left(ky \leq 3.6 \cdot 10^{-70}\right) \land ky \leq 3.2 \cdot 10^{-32}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 17: 31.2% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -9.5 or 3.05e-145 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

    if -9.5 < ky < 3.05e-145

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified32.1%

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

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

Alternative 18: 21.4% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.80000000000000004 or 1.02000000000000002e-32 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
    5. Taylor expanded in th around 0 20.8%

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

    if -0.80000000000000004 < ky < 1.02000000000000002e-32

    1. Initial program 88.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified30.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -0.8:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.02 \cdot 10^{-32}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 19: 13.7% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sin th} \]
  5. Taylor expanded in th around 0 14.2%

    \[\leadsto \color{blue}{th} \]
  6. Final simplification14.2%

    \[\leadsto th \]

Reproduce

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