Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 24.0s
Alternatives: 17
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 alternatives:

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

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

\\
\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}
\end{array}
Derivation
  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.7%

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

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

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

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

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

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

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

Alternative 2: 48.1% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-30}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.853999999999999981 < (sin.f64 ky) < -1e-30

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\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 kx around 0 2.8%

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

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

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

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

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

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

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

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

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

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

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

    if -1e-30 < (sin.f64 ky) < 1.0000000000000001e-114

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. clear-num98.3%

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 3: 66.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1e-3 < (sin.f64 th) < 5.00000000000000018e-11

    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. Taylor expanded in th around 0 84.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000018e-11 < (sin.f64 th)

    1. Initial program 97.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 66.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1e-3 < (sin.f64 th) < 5.00000000000000018e-11

    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. Taylor expanded in th around 0 84.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000018e-11 < (sin.f64 th)

    1. Initial program 97.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 74.1% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

    if -1e-3 < (sin.f64 th) < 5.00000000000000018e-11

    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. Taylor expanded in th around 0 84.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000018e-11 < (sin.f64 th)

    1. Initial program 97.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 48.1% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 10^{-114}:\\
\;\;\;\;\sin 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) < -1e-30

    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 kx around 0 2.6%

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.4%

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

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

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

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

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

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

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

    if -1e-30 < (sin.f64 ky) < 1.0000000000000001e-114

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. clear-num98.3%

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 7: 99.7% accurate, 1.4× speedup?

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

\\
\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}
\end{array}
Derivation
  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.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 \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

Alternative 8: 48.1% accurate, 1.7× speedup?

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

\mathbf{elif}\;\sin ky \leq 10^{-114}:\\
\;\;\;\;\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) < -1e-30

    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 kx around 0 2.6%

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.4%

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

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

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

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

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

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

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

    if -1e-30 < (sin.f64 ky) < 1.0000000000000001e-114

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 9: 40.5% accurate, 2.3× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 10^{-114}:\\
\;\;\;\;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) < -1e-30

    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 kx around 0 2.6%

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.4%

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

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

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

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

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

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

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

    if -1e-30 < (sin.f64 ky) < 1.0000000000000001e-114

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 25.4%

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 10: 31.8% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 91.2%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 19.9%

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

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

    if 9.9999999999999997e-148 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 11: 32.9% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 16.4%

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 12: 31.4% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.8e6 or 9.9999999999999997e-148 < 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 29.8%

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

    if -1.8e6 < ky < 9.9999999999999997e-148

    1. Initial program 84.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 26.8%

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

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

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

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

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

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

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

Alternative 13: 21.7% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -4.20000000000000003e80 or 5.6999999999999997e-114 < 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. associate-/r/99.5%

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

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

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

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

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

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

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

        \[\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 kx around 0 29.7%

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

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

    if -4.20000000000000003e80 < ky < 5.6999999999999997e-114

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 25.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -4.2 \cdot 10^{+80}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 5.7 \cdot 10^{-114}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 14: 21.7% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.7999999999999999e83 or 8.1999999999999993e-115 < 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. associate-/r/99.5%

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

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

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

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

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

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

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

        \[\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 kx around 0 29.7%

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

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

    if -1.7999999999999999e83 < ky < 8.1999999999999993e-115

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 25.0%

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

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

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

      \[\leadsto \frac{ky}{\color{blue}{\frac{kx}{th}}} \]
    11. Step-by-step derivation
      1. clear-num23.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.8 \cdot 10^{+83}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{-115}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 15: 21.6% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.00000000000000025e83 or 1.9499999999999999e-113 < 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. associate-/r/99.5%

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

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

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

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

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

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

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

        \[\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 kx around 0 29.7%

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

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

    if -8.00000000000000025e83 < ky < 1.9499999999999999e-113

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 25.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -8 \cdot 10^{+83}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.95 \cdot 10^{-113}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 16: 21.7% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.60000000000000029e82 or 1.75e-114 < 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. associate-/r/99.5%

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

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

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

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

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

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

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

        \[\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 kx around 0 29.7%

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

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

    if -8.60000000000000029e82 < ky < 1.75e-114

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin ky \cdot \left(th \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    7. Taylor expanded in ky around 0 25.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -8.6 \cdot 10^{+82}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.75 \cdot 10^{-114}:\\ \;\;\;\;\frac{th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 17: 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 93.9%

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

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

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

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

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

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

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

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

      \[\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 kx around 0 21.1%

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

    \[\leadsto \color{blue}{th} \]
  6. Final simplification11.0%

    \[\leadsto th \]

Reproduce

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