Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.6% → 99.7%
Time: 26.6s
Alternatives: 19
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 alternatives:

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

Initial Program: 93.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 77.1% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

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

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 77.1% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

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

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 77.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 65.0% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

    if -0.149999999999999994 < (sin.f64 kx) < 0.0100000000000000002

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 65.0% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

    if -0.149999999999999994 < (sin.f64 kx) < 0.0100000000000000002

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 75.4% accurate, 1.7× speedup?

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

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

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

\mathbf{elif}\;ky \leq 6 \cdot 10^{+64}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{t_2}\\

\mathbf{elif}\;ky \leq 6 \cdot 10^{+232}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < -0.00139999999999999999 or 6.0000000000000004e64 < ky < 6.00000000000000006e232

    1. Initial program 99.6%

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

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

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

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

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

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

    if -0.00139999999999999999 < ky < 0.0111999999999999999

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0111999999999999999 < ky < 6.0000000000000004e64

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

    if 6.00000000000000006e232 < ky

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 62.9% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

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

        \[\leadsto -1 \cdot \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
      3. mul-1-neg51.6%

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

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

        \[\leadsto -\color{blue}{\sin th \cdot \frac{ky}{\sin kx}} \]
    11. Simplified51.7%

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

    if -0.149999999999999994 < (sin.f64 kx) < 0.0100000000000000002

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 62.9% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot \sin th}{\frac{\sin kx}{ky}}} \]
      4. neg-mul-151.6%

        \[\leadsto \frac{\color{blue}{-\sin th}}{\frac{\sin kx}{ky}} \]
    11. Simplified51.6%

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

    if -0.149999999999999994 < (sin.f64 kx) < 0.0100000000000000002

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 62.9% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(ky \cdot \frac{\sin th}{\sin kx}\right)}^{2}}} \]
    9. Taylor expanded in ky around -inf 51.7%

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

    if -0.149999999999999994 < (sin.f64 kx) < 0.0100000000000000002

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0100000000000000002 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 33.8% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999996e-113 < (sin.f64 ky) < 9.9999999999999995e-127

    1. Initial program 83.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 61.5%

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

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

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

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

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

    if 9.9999999999999995e-127 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

Alternative 13: 33.8% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.0000000000000001e-115 < (sin.f64 ky) < 9.9999999999999995e-127

    1. Initial program 83.3%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 61.0%

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

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

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

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

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

    if 9.9999999999999995e-127 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

Alternative 14: 40.0% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 2 \cdot 10^{-117}:\\
\;\;\;\;\sin 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) < 2.00000000000000006e-117

    1. Initial program 92.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000006e-117 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

Alternative 15: 33.3% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -0.95 \lor \neg \left(ky \leq 1.1 \cdot 10^{-123}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.94999999999999996 or 1.10000000000000003e-123 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

    if -0.94999999999999996 < ky < 1.10000000000000003e-123

    1. Initial program 87.8%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 56.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -0.95 \lor \neg \left(ky \leq 1.1 \cdot 10^{-123}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \end{array} \]

Alternative 16: 30.3% accurate, 6.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -0.95 \lor \neg \left(ky \leq 1.35 \cdot 10^{-126}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.94999999999999996 or 1.34999999999999998e-126 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

    if -0.94999999999999996 < ky < 1.34999999999999998e-126

    1. Initial program 87.8%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 56.9%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified20.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -0.95 \lor \neg \left(ky \leq 1.35 \cdot 10^{-126}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \end{array} \]

Alternative 17: 20.7% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.02e40 or 2.8e-117 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

    if -1.02e40 < ky < 2.8e-117

    1. Initial program 89.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 57.7%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified19.1%

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

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

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

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

Alternative 18: 20.7% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.02e40 or 3.10000000000000011e-117 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

    if -1.02e40 < ky < 3.10000000000000011e-117

    1. Initial program 89.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\right)}}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-{\sin \left(-ky\right)}^{\left(\frac{\frac{2}{2}}{2}\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 57.7%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified19.1%

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

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

Alternative 19: 13.1% 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 95.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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