Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.7%
Time: 14.4s
Alternatives: 23
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 23 alternatives:

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

Initial Program: 94.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 44.9% accurate, 1.1× speedup?

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

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \log \color{blue}{\left(e^{\frac{\sin th}{\sin kx}}\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt12.2%

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

        \[\leadsto \sin ky \cdot \color{blue}{\sqrt{\log \left(e^{\frac{\sin th}{\sin kx}}\right) \cdot \log \left(e^{\frac{\sin th}{\sin kx}}\right)}} \]
      3. pow227.4%

        \[\leadsto \sin ky \cdot \sqrt{\color{blue}{{\log \left(e^{\frac{\sin th}{\sin kx}}\right)}^{2}}} \]
      4. rem-log-exp32.8%

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

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

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

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

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

    if -0.021999999999999999 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr62.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.022:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sin kx}{\sin th \cdot \sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 45.1% accurate, 1.1× speedup?

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

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|} \]
      3. associate-*r/28.4%

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot \sin ky}{\sin kx}}\right| \]
      4. *-commutative28.4%

        \[\leadsto \left|\frac{\color{blue}{\sin ky \cdot \sin th}}{\sin kx}\right| \]
      5. associate-/l*28.4%

        \[\leadsto \left|\color{blue}{\sin ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    7. Simplified28.4%

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

    if -0.021999999999999999 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr62.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.022:\\ \;\;\;\;\left|\sin ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sin kx}{\sin th \cdot \sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 43.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_1 := th \cdot \sin ky\\
\mathbf{if}\;\sin kx \leq -0.04:\\
\;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{t\_1}}\\

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

\mathbf{elif}\;\sin kx \leq 10^{-27}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

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


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

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    8. Applied egg-rr28.5%

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr62.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{th \cdot \sin ky}}\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sin kx}{\sin th \cdot \sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 43.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_1 := th \cdot \sin ky\\
\mathbf{if}\;\sin kx \leq -0.04:\\
\;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{t\_1}}\\

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

\mathbf{elif}\;\sin kx \leq 10^{-27}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

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


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

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    8. Applied egg-rr28.5%

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. clear-num62.5%

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

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

      \[\leadsto \color{blue}{{\left(\frac{\sin kx}{\sin ky}\right)}^{-1}} \cdot \sin th \]
    6. Step-by-step derivation
      1. unpow-162.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{th \cdot \sin ky}}\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{1}{\frac{\sin kx}{\sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 41.8% accurate, 1.1× speedup?

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

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. clear-num62.5%

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

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

      \[\leadsto \color{blue}{{\left(\frac{\sin kx}{\sin ky}\right)}^{-1}} \cdot \sin th \]
    6. Step-by-step derivation
      1. unpow-162.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\left|th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{1}{\frac{\sin kx}{\sin ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 41.8% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (sin.f64 kx) < 1e-27

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-27 < (sin.f64 kx)

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.04:\\ \;\;\;\;\left|th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-27}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 77.2% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 ky) < 2e-8

    1. Initial program 85.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2e-8 < (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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 41.4% accurate, 1.4× speedup?

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

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

\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.0400000000000000008

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (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. unpow299.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin kx}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 10: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 11: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 37.8% accurate, 1.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if kx < 1.05e-117

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < kx < 9.50000000000000001e-28

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.50000000000000001e-28 < kx

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr53.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.05 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 9.5 \cdot 10^{-28}:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 39.0% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr12.6%

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 1.05e-117

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < (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. unpow299.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{\sin kx}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 14: 69.0% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.7%

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

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

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

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

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

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

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

    if 6.99999999999999993e-4 < kx

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr55.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 0.0007:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 68.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.49999999999999996e-4 < kx

    1. Initial program 99.3%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr55.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 0.00035:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 61.7% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0235 < th

    1. Initial program 92.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 0.0235:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 36.5% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999955e-308 < (sin.f64 ky) < 2e-197

    1. Initial program 71.4%

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

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

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

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

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr52.6%

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

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

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

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

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

    if 2e-197 < (sin.f64 ky)

    1. Initial program 97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 18: 30.5% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 88.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.05e-117 < 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. unpow299.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 19: 26.4% accurate, 6.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 0.78:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 0.78000000000000003

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.78000000000000003 < kx

    1. Initial program 99.3%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
      3. *-commutative32.9%

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr32.9%

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

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

      \[\leadsto \frac{1}{\frac{\sin kx}{th \cdot \color{blue}{ky}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 20: 26.5% accurate, 6.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 0.78:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 0.78000000000000003

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.78000000000000003 < kx

    1. Initial program 99.3%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
      3. *-commutative32.9%

        \[\leadsto \frac{1}{\frac{\sin kx}{\color{blue}{\sin th \cdot \sin ky}}} \]
    5. Applied egg-rr32.9%

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

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

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

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

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

Alternative 21: 24.5% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.7 \cdot 10^{+35}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot {th}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 1.7000000000000001e35

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.7000000000000001e35 < kx

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{th \cdot \left(1 + -0.16666666666666666 \cdot {th}^{2}\right)} \]
    7. Taylor expanded in th around inf 6.7%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {th}^{3}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 22: 23.2% accurate, 7.0× speedup?

\[\begin{array}{l} \\ \sin th \end{array} \]
(FPCore (kx ky th) :precision binary64 (sin th))
double code(double kx, double ky, double th) {
	return 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(th)
end function
public static double code(double kx, double ky, double th) {
	return Math.sin(th);
}
def code(kx, ky, th):
	return math.sin(th)
function code(kx, ky, th)
	return sin(th)
end
function tmp = code(kx, ky, th)
	tmp = sin(th);
end
code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sin th} \]
  6. Add Preprocessing

Alternative 23: 13.3% accurate, 709.0× speedup?

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

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. unpow292.0%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
    2. sqr-neg92.0%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
    3. sin-neg92.0%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
    4. sin-neg92.0%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
    5. unpow292.0%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    6. associate-*l/90.9%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
    7. associate-/l*92.0%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
    8. +-commutative92.0%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin \left(-kx\right)}^{2}}}} \]
    9. unpow292.0%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{{\sin ky}^{2} + \color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)}}} \]
    10. sin-neg92.0%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{{\sin ky}^{2} + \color{blue}{\left(-\sin kx\right)} \cdot \sin \left(-kx\right)}} \]
    11. sin-neg92.0%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{{\sin ky}^{2} + \left(-\sin kx\right) \cdot \color{blue}{\left(-\sin kx\right)}}} \]
  3. Simplified99.6%

    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in kx around 0 25.1%

    \[\leadsto \color{blue}{\sin th} \]
  6. Taylor expanded in th around 0 15.0%

    \[\leadsto \color{blue}{th} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024167 
(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)))