Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 13.0s
Alternatives: 34
Speedup: 1.2×

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 34 alternatives:

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

Initial Program: 93.8% 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.2× speedup?

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

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    2. lift-+.f64N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    4. lift-pow.f64N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    6. lift-pow.f64N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    8. lower-hypot.f6499.7

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

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

Alternative 2: 83.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th \cdot \left(th \cdot th\right), \left(\mathsf{fma}\left(th \cdot th, -0.0001984126984126984, 0.008333333333333333\right) \cdot th\right) \cdot th - 0.16666666666666666, th\right)\\ \mathbf{elif}\;t\_3 \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (pow (sin kx) 2.0))
        (t_2 (pow (sin ky) 2.0))
        (t_3 (/ (sin ky) (sqrt (+ t_1 t_2)))))
   (if (<= t_3 -1.0)
     (* (/ (sin ky) (sqrt t_2)) (sin th))
     (if (<= t_3 -0.12)
       (*
        (/ (sin ky) (hypot (sin ky) (sin kx)))
        (fma
         (* th (* th th))
         (-
          (*
           (* (fma (* th th) -0.0001984126984126984 0.008333333333333333) th)
           th)
          0.16666666666666666)
         th))
       (if (<= t_3 0.0002)
         (* (/ (sin ky) (sqrt (+ t_1 (* ky ky)))) (sin th))
         (if (<= t_3 0.998)
           (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
           (if (<= t_3 2.0)
             (* (fma (* kx (/ kx t_2)) -0.5 1.0) (sin th))
             (*
              (/
               (sin ky)
               (hypot
                (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                (sin kx)))
              (sin th)))))))))
double code(double kx, double ky, double th) {
	double t_1 = pow(sin(kx), 2.0);
	double t_2 = pow(sin(ky), 2.0);
	double t_3 = sin(ky) / sqrt((t_1 + t_2));
	double tmp;
	if (t_3 <= -1.0) {
		tmp = (sin(ky) / sqrt(t_2)) * sin(th);
	} else if (t_3 <= -0.12) {
		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * fma((th * (th * th)), (((fma((th * th), -0.0001984126984126984, 0.008333333333333333) * th) * th) - 0.16666666666666666), th);
	} else if (t_3 <= 0.0002) {
		tmp = (sin(ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
	} else if (t_3 <= 0.998) {
		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
	} else if (t_3 <= 2.0) {
		tmp = fma((kx * (kx / t_2)), -0.5, 1.0) * sin(th);
	} else {
		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = sin(kx) ^ 2.0
	t_2 = sin(ky) ^ 2.0
	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + t_2)))
	tmp = 0.0
	if (t_3 <= -1.0)
		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * sin(th));
	elseif (t_3 <= -0.12)
		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * fma(Float64(th * Float64(th * th)), Float64(Float64(Float64(fma(Float64(th * th), -0.0001984126984126984, 0.008333333333333333) * th) * th) - 0.16666666666666666), th));
	elseif (t_3 <= 0.0002)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
	elseif (t_3 <= 0.998)
		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
	elseif (t_3 <= 2.0)
		tmp = Float64(fma(Float64(kx * Float64(kx / t_2)), -0.5, 1.0) * sin(th));
	else
		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(th * th), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision] - 0.16666666666666666), $MachinePrecision] + th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0002], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(N[(kx * N[(kx / t$95$2), $MachinePrecision]), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := {\sin kx}^{2}\\
t_2 := {\sin ky}^{2}\\
t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\
\mathbf{if}\;t\_3 \leq -1:\\
\;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\

\mathbf{elif}\;t\_3 \leq -0.12:\\
\;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th \cdot \left(th \cdot th\right), \left(\mathsf{fma}\left(th \cdot th, -0.0001984126984126984, 0.008333333333333333\right) \cdot th\right) \cdot th - 0.16666666666666666, th\right)\\

\mathbf{elif}\;t\_3 \leq 0.0002:\\
\;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\

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

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

    1. Initial program 82.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. sqr-neg-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\mathsf{neg}\left(\sin ky\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}}} \cdot \sin th \]
      4. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
      5. cos-+PI/2-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
      6. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right)}} \cdot \sin th \]
      7. cos-+PI/2-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)}}} \cdot \sin th \]
      8. 1-sub-sin-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(1 - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}}} \cdot \sin th \]
      9. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{\frac{2}{2}} - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
      10. sin-+PI/2-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \color{blue}{\cos ky} \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
      11. sin-+PI/2-revN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \cos ky \cdot \color{blue}{\cos ky}\right)}} \cdot \sin th \]
      12. lower--.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\frac{2}{2} - \cos ky \cdot \cos ky\right)}}} \cdot \sin th \]
      13. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{1} - \cos ky \cdot \cos ky\right)}} \cdot \sin th \]
      14. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky \cdot \cos ky}\right)}} \cdot \sin th \]
      15. lower-cos.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky} \cdot \cos ky\right)}} \cdot \sin th \]
      16. lower-cos.f6462.1

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{1 - {\cos ky}^{2}}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{1 - \color{blue}{\cos ky \cdot \cos ky}}} \cdot \sin th \]
      2. 1-sub-cosN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
      4. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]
      5. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
      6. lower-sin.f6482.4

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]

    if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.12

    1. Initial program 99.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
      2. lift-+.f64N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      4. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      6. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      8. lower-hypot.f6499.2

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + {th}^{2} \cdot \left({th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}\right)\right)\right)} \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \color{blue}{\left({th}^{2} \cdot \left({th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}\right) + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left({th}^{2} \cdot \left({th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}\right)\right) + th \cdot 1\right)} \]
      3. associate-*r*N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(th \cdot {th}^{2}\right) \cdot \left({th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}\right)} + th \cdot 1\right) \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(th \cdot {th}^{2}\right) \cdot \left({th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}\right) + \color{blue}{th}\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\mathsf{fma}\left(th \cdot {th}^{2}, {th}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {th}^{2}\right) - \frac{1}{6}, th\right)} \]
    7. Applied rewrites52.4%

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

    if -0.12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

    if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

    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 th around 0

      \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. lower-*.f64N/A

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

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

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      7. unpow2N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
      8. lower-fma.f64N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
      9. lower-sin.f64N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
      10. lower-sin.f64N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
      11. lower-pow.f64N/A

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
      12. lower-sin.f6450.1

        \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
    5. Applied rewrites50.1%

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

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

      if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{\left(1 + \frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}\right)} \cdot \sin th \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}} + 1\right)} \cdot \sin th \]
        2. *-commutativeN/A

          \[\leadsto \left(\color{blue}{\frac{{kx}^{2}}{{\sin ky}^{2}} \cdot \frac{-1}{2}} + 1\right) \cdot \sin th \]
        3. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{kx}^{2}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right)} \cdot \sin th \]
        4. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{kx \cdot kx}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
        5. associate-/l*N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
        6. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
        7. lower-/.f64N/A

          \[\leadsto \mathsf{fma}\left(kx \cdot \color{blue}{\frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
        8. lower-pow.f64N/A

          \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{\color{blue}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
        9. lower-sin.f6497.7

          \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{{\color{blue}{\sin ky}}^{2}}, -0.5, 1\right) \cdot \sin th \]
      5. Applied rewrites97.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right)} \cdot \sin th \]

      if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

      1. Initial program 2.0%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-sqrt.f64N/A

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
        2. lift-+.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
        4. lift-pow.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
        6. lift-pow.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
        8. lower-hypot.f64100.0

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

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

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
      6. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
        2. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
        3. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
        4. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
        5. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
        6. unpow2N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
        7. lower-*.f64100.0

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
      7. Applied rewrites100.0%

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
    7. Recombined 6 regimes into one program.
    8. Final simplification81.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th \cdot \left(th \cdot th\right), \left(\mathsf{fma}\left(th \cdot th, -0.0001984126984126984, 0.008333333333333333\right) \cdot th\right) \cdot th - 0.16666666666666666, th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 83.4% accurate, 0.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_3 \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
     :precision binary64
     (let* ((t_1 (pow (sin kx) 2.0))
            (t_2 (pow (sin ky) 2.0))
            (t_3 (/ (sin ky) (sqrt (+ t_1 t_2)))))
       (if (<= t_3 -1.0)
         (* (/ (sin ky) (sqrt t_2)) (sin th))
         (if (<= t_3 -0.12)
           (*
            (/ (sin ky) (hypot (sin ky) (sin kx)))
            (*
             (fma
              (- (* (* th th) 0.008333333333333333) 0.16666666666666666)
              (* th th)
              1.0)
             th))
           (if (<= t_3 0.0002)
             (* (/ (sin ky) (sqrt (+ t_1 (* ky ky)))) (sin th))
             (if (<= t_3 0.998)
               (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
               (if (<= t_3 2.0)
                 (* (fma (* kx (/ kx t_2)) -0.5 1.0) (sin th))
                 (*
                  (/
                   (sin ky)
                   (hypot
                    (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                    (sin kx)))
                  (sin th)))))))))
    double code(double kx, double ky, double th) {
    	double t_1 = pow(sin(kx), 2.0);
    	double t_2 = pow(sin(ky), 2.0);
    	double t_3 = sin(ky) / sqrt((t_1 + t_2));
    	double tmp;
    	if (t_3 <= -1.0) {
    		tmp = (sin(ky) / sqrt(t_2)) * sin(th);
    	} else if (t_3 <= -0.12) {
    		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * (fma((((th * th) * 0.008333333333333333) - 0.16666666666666666), (th * th), 1.0) * th);
    	} else if (t_3 <= 0.0002) {
    		tmp = (sin(ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
    	} else if (t_3 <= 0.998) {
    		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
    	} else if (t_3 <= 2.0) {
    		tmp = fma((kx * (kx / t_2)), -0.5, 1.0) * sin(th);
    	} else {
    		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
    	}
    	return tmp;
    }
    
    function code(kx, ky, th)
    	t_1 = sin(kx) ^ 2.0
    	t_2 = sin(ky) ^ 2.0
    	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + t_2)))
    	tmp = 0.0
    	if (t_3 <= -1.0)
    		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * sin(th));
    	elseif (t_3 <= -0.12)
    		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * Float64(fma(Float64(Float64(Float64(th * th) * 0.008333333333333333) - 0.16666666666666666), Float64(th * th), 1.0) * th));
    	elseif (t_3 <= 0.0002)
    		tmp = Float64(Float64(sin(ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
    	elseif (t_3 <= 0.998)
    		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
    	elseif (t_3 <= 2.0)
    		tmp = Float64(fma(Float64(kx * Float64(kx / t_2)), -0.5, 1.0) * sin(th));
    	else
    		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
    	end
    	return tmp
    end
    
    code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.12], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(th * th), $MachinePrecision] * 0.008333333333333333), $MachinePrecision] - 0.16666666666666666), $MachinePrecision] * N[(th * th), $MachinePrecision] + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0002], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(N[(kx * N[(kx / t$95$2), $MachinePrecision]), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := {\sin kx}^{2}\\
    t_2 := {\sin ky}^{2}\\
    t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\
    \mathbf{if}\;t\_3 \leq -1:\\
    \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\
    
    \mathbf{elif}\;t\_3 \leq -0.12:\\
    \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\right)\\
    
    \mathbf{elif}\;t\_3 \leq 0.0002:\\
    \;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
    
    \mathbf{elif}\;t\_3 \leq 0.998:\\
    \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
    
    \mathbf{elif}\;t\_3 \leq 2:\\
    \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 6 regimes
    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

      1. Initial program 82.4%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-pow.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
        2. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
        3. sqr-neg-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\mathsf{neg}\left(\sin ky\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}}} \cdot \sin th \]
        4. lift-sin.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
        5. cos-+PI/2-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
        6. lift-sin.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right)}} \cdot \sin th \]
        7. cos-+PI/2-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)}}} \cdot \sin th \]
        8. 1-sub-sin-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(1 - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}}} \cdot \sin th \]
        9. metadata-evalN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{\frac{2}{2}} - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
        10. sin-+PI/2-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \color{blue}{\cos ky} \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
        11. sin-+PI/2-revN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \cos ky \cdot \color{blue}{\cos ky}\right)}} \cdot \sin th \]
        12. lower--.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\frac{2}{2} - \cos ky \cdot \cos ky\right)}}} \cdot \sin th \]
        13. metadata-evalN/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{1} - \cos ky \cdot \cos ky\right)}} \cdot \sin th \]
        14. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky \cdot \cos ky}\right)}} \cdot \sin th \]
        15. lower-cos.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky} \cdot \cos ky\right)}} \cdot \sin th \]
        16. lower-cos.f6462.1

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{1 - {\cos ky}^{2}}}} \cdot \sin th \]
      6. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{1 - \color{blue}{\cos ky \cdot \cos ky}}} \cdot \sin th \]
        2. 1-sub-cosN/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
        3. unpow2N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
        4. lower-sqrt.f64N/A

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]
        5. lower-pow.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
        6. lower-sin.f6482.4

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]

      if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.12

      1. Initial program 99.3%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-sqrt.f64N/A

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
        2. lift-+.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
        4. lift-pow.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
        6. lift-pow.f64N/A

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

          \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
        8. lower-hypot.f6499.2

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

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

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right)\right)} \]
      6. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) \cdot th\right)} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) \cdot th\right)} \]
        3. +-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right) + 1\right)} \cdot th\right) \]
        4. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{\left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right) \cdot {th}^{2}} + 1\right) \cdot th\right) \]
        5. lower-fma.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}, {th}^{2}, 1\right)} \cdot th\right) \]
        6. lower--.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}}, {th}^{2}, 1\right) \cdot th\right) \]
        7. *-commutativeN/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{{th}^{2} \cdot \frac{1}{120}} - \frac{1}{6}, {th}^{2}, 1\right) \cdot th\right) \]
        8. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{{th}^{2} \cdot \frac{1}{120}} - \frac{1}{6}, {th}^{2}, 1\right) \cdot th\right) \]
        9. unpow2N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{\left(th \cdot th\right)} \cdot \frac{1}{120} - \frac{1}{6}, {th}^{2}, 1\right) \cdot th\right) \]
        10. lower-*.f64N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{\left(th \cdot th\right)} \cdot \frac{1}{120} - \frac{1}{6}, {th}^{2}, 1\right) \cdot th\right) \]
        11. unpow2N/A

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\left(th \cdot th\right) \cdot \frac{1}{120} - \frac{1}{6}, \color{blue}{th \cdot th}, 1\right) \cdot th\right) \]
        12. lower-*.f6452.0

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, \color{blue}{th \cdot th}, 1\right) \cdot th\right) \]
      7. Applied rewrites52.0%

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

      if -0.12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

      1. Initial program 99.6%

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. unpow2N/A

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

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

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

      if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

      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 th around 0

        \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      4. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
        3. lower-*.f64N/A

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

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

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
        6. lower-/.f64N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
        7. unpow2N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
        8. lower-fma.f64N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
        9. lower-sin.f64N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
        10. lower-sin.f64N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
        11. lower-pow.f64N/A

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
        12. lower-sin.f6450.1

          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
      5. Applied rewrites50.1%

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

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

        if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{\left(1 + \frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}\right)} \cdot \sin th \]
        4. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}} + 1\right)} \cdot \sin th \]
          2. *-commutativeN/A

            \[\leadsto \left(\color{blue}{\frac{{kx}^{2}}{{\sin ky}^{2}} \cdot \frac{-1}{2}} + 1\right) \cdot \sin th \]
          3. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{kx}^{2}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right)} \cdot \sin th \]
          4. unpow2N/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{kx \cdot kx}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
          5. associate-/l*N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
          6. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
          7. lower-/.f64N/A

            \[\leadsto \mathsf{fma}\left(kx \cdot \color{blue}{\frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
          8. lower-pow.f64N/A

            \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{\color{blue}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
          9. lower-sin.f6497.7

            \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{{\color{blue}{\sin ky}}^{2}}, -0.5, 1\right) \cdot \sin th \]
        5. Applied rewrites97.7%

          \[\leadsto \color{blue}{\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right)} \cdot \sin th \]

        if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

        1. Initial program 2.0%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-sqrt.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          2. lift-+.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
          4. lift-pow.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
          6. lift-pow.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
          8. lower-hypot.f64100.0

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

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

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
          2. lower-*.f64N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
          3. +-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
          4. *-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
          5. lower-fma.f64N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
          6. unpow2N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
          7. lower-*.f64100.0

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
        7. Applied rewrites100.0%

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
      7. Recombined 6 regimes into one program.
      8. Final simplification81.7%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 83.2% accurate, 0.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_3 \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \end{array} \]
      (FPCore (kx ky th)
       :precision binary64
       (let* ((t_1 (pow (sin kx) 2.0))
              (t_2 (pow (sin ky) 2.0))
              (t_3 (/ (sin ky) (sqrt (+ t_1 t_2)))))
         (if (<= t_3 -1.0)
           (* (/ (sin ky) (sqrt t_2)) (sin th))
           (if (<= t_3 -0.12)
             (*
              (/
               (sin ky)
               (/
                (sqrt
                 (fma
                  (- 1.0 (cos (* 2.0 ky)))
                  2.0
                  (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                2.0))
              (* (fma (* th th) -0.16666666666666666 1.0) th))
             (if (<= t_3 0.0002)
               (* (/ (sin ky) (sqrt (+ t_1 (* ky ky)))) (sin th))
               (if (<= t_3 0.998)
                 (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
                 (if (<= t_3 2.0)
                   (* (fma (* kx (/ kx t_2)) -0.5 1.0) (sin th))
                   (*
                    (/
                     (sin ky)
                     (hypot
                      (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                      (sin kx)))
                    (sin th)))))))))
      double code(double kx, double ky, double th) {
      	double t_1 = pow(sin(kx), 2.0);
      	double t_2 = pow(sin(ky), 2.0);
      	double t_3 = sin(ky) / sqrt((t_1 + t_2));
      	double tmp;
      	if (t_3 <= -1.0) {
      		tmp = (sin(ky) / sqrt(t_2)) * sin(th);
      	} else if (t_3 <= -0.12) {
      		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
      	} else if (t_3 <= 0.0002) {
      		tmp = (sin(ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
      	} else if (t_3 <= 0.998) {
      		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
      	} else if (t_3 <= 2.0) {
      		tmp = fma((kx * (kx / t_2)), -0.5, 1.0) * sin(th);
      	} else {
      		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
      	}
      	return tmp;
      }
      
      function code(kx, ky, th)
      	t_1 = sin(kx) ^ 2.0
      	t_2 = sin(ky) ^ 2.0
      	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + t_2)))
      	tmp = 0.0
      	if (t_3 <= -1.0)
      		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * sin(th));
      	elseif (t_3 <= -0.12)
      		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
      	elseif (t_3 <= 0.0002)
      		tmp = Float64(Float64(sin(ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
      	elseif (t_3 <= 0.998)
      		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
      	elseif (t_3 <= 2.0)
      		tmp = Float64(fma(Float64(kx * Float64(kx / t_2)), -0.5, 1.0) * sin(th));
      	else
      		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
      	end
      	return tmp
      end
      
      code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.12], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0002], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(N[(kx * N[(kx / t$95$2), $MachinePrecision]), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_1 := {\sin kx}^{2}\\
      t_2 := {\sin ky}^{2}\\
      t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\
      \mathbf{if}\;t\_3 \leq -1:\\
      \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\
      
      \mathbf{elif}\;t\_3 \leq -0.12:\\
      \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
      
      \mathbf{elif}\;t\_3 \leq 0.0002:\\
      \;\;\;\;\frac{\sin ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
      
      \mathbf{elif}\;t\_3 \leq 0.998:\\
      \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
      
      \mathbf{elif}\;t\_3 \leq 2:\\
      \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 6 regimes
      2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

        1. Initial program 82.4%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
          2. unpow2N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
          3. sqr-neg-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\mathsf{neg}\left(\sin ky\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}}} \cdot \sin th \]
          4. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
          5. cos-+PI/2-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
          6. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right)}} \cdot \sin th \]
          7. cos-+PI/2-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)}}} \cdot \sin th \]
          8. 1-sub-sin-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(1 - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}}} \cdot \sin th \]
          9. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{\frac{2}{2}} - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
          10. sin-+PI/2-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \color{blue}{\cos ky} \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
          11. sin-+PI/2-revN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \cos ky \cdot \color{blue}{\cos ky}\right)}} \cdot \sin th \]
          12. lower--.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\frac{2}{2} - \cos ky \cdot \cos ky\right)}}} \cdot \sin th \]
          13. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{1} - \cos ky \cdot \cos ky\right)}} \cdot \sin th \]
          14. lower-*.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky \cdot \cos ky}\right)}} \cdot \sin th \]
          15. lower-cos.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky} \cdot \cos ky\right)}} \cdot \sin th \]
          16. lower-cos.f6462.1

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

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

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{1 - {\cos ky}^{2}}}} \cdot \sin th \]
        6. Step-by-step derivation
          1. unpow2N/A

            \[\leadsto \frac{\sin ky}{\sqrt{1 - \color{blue}{\cos ky \cdot \cos ky}}} \cdot \sin th \]
          2. 1-sub-cosN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
          3. unpow2N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
          4. lower-sqrt.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]
          5. lower-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
          6. lower-sin.f6482.4

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

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]

        if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.12

        1. Initial program 99.3%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-sqrt.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          2. lift-+.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
          4. lift-pow.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
          6. lift-pow.f64N/A

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

            \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
          8. lower-hypot.f6499.2

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

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

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
          2. lower-*.f64N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
          3. +-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
          4. *-commutativeN/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
          5. lower-fma.f64N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
          6. unpow2N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
          7. lower-*.f6451.7

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

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
        8. Step-by-step derivation
          1. lift-hypot.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          2. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          3. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          4. sin-multN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          5. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          6. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          7. sin-multN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          8. frac-addN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          9. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          10. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          11. sqrt-divN/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          12. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          13. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          14. lower-/.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
        9. Applied rewrites51.8%

          \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

        if -0.12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

        1. Initial program 99.6%

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

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
        4. Step-by-step derivation
          1. unpow2N/A

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

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

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

        if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

        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 th around 0

          \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
        4. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
          3. lower-*.f64N/A

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

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

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          6. lower-/.f64N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          7. unpow2N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
          8. lower-fma.f64N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
          9. lower-sin.f64N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
          10. lower-sin.f64N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
          11. lower-pow.f64N/A

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
          12. lower-sin.f6450.1

            \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
        5. Applied rewrites50.1%

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

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

          if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{\left(1 + \frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}\right)} \cdot \sin th \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}} + 1\right)} \cdot \sin th \]
            2. *-commutativeN/A

              \[\leadsto \left(\color{blue}{\frac{{kx}^{2}}{{\sin ky}^{2}} \cdot \frac{-1}{2}} + 1\right) \cdot \sin th \]
            3. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{kx}^{2}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right)} \cdot \sin th \]
            4. unpow2N/A

              \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{kx \cdot kx}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
            5. associate-/l*N/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
            6. lower-*.f64N/A

              \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
            7. lower-/.f64N/A

              \[\leadsto \mathsf{fma}\left(kx \cdot \color{blue}{\frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
            8. lower-pow.f64N/A

              \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{\color{blue}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
            9. lower-sin.f6497.7

              \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{{\color{blue}{\sin ky}}^{2}}, -0.5, 1\right) \cdot \sin th \]
          5. Applied rewrites97.7%

            \[\leadsto \color{blue}{\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right)} \cdot \sin th \]

          if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

          1. Initial program 2.0%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-sqrt.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
            2. lift-+.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
            4. lift-pow.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
            6. lift-pow.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
            8. lower-hypot.f64100.0

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

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

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
          6. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
            2. lower-*.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
            3. +-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
            4. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
            5. lower-fma.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
            6. unpow2N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
            7. lower-*.f64100.0

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
          7. Applied rewrites100.0%

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
        7. Recombined 6 regimes into one program.
        8. Final simplification81.7%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \]
        9. Add Preprocessing

        Alternative 5: 83.2% accurate, 0.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_3 \leq 0.1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        (FPCore (kx ky th)
         :precision binary64
         (let* ((t_1
                 (*
                  (/
                   (sin ky)
                   (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                  (sin th)))
                (t_2 (pow (sin ky) 2.0))
                (t_3 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_2)))))
           (if (<= t_3 -1.0)
             (* (/ (sin ky) (sqrt t_2)) (sin th))
             (if (<= t_3 -0.12)
               (*
                (/
                 (sin ky)
                 (/
                  (sqrt
                   (fma
                    (- 1.0 (cos (* 2.0 ky)))
                    2.0
                    (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                  2.0))
                (* (fma (* th th) -0.16666666666666666 1.0) th))
               (if (<= t_3 0.1)
                 t_1
                 (if (<= t_3 0.998)
                   (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
                   (if (<= t_3 2.0)
                     (* (fma (* kx (/ kx t_2)) -0.5 1.0) (sin th))
                     t_1)))))))
        double code(double kx, double ky, double th) {
        	double t_1 = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
        	double t_2 = pow(sin(ky), 2.0);
        	double t_3 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_2));
        	double tmp;
        	if (t_3 <= -1.0) {
        		tmp = (sin(ky) / sqrt(t_2)) * sin(th);
        	} else if (t_3 <= -0.12) {
        		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
        	} else if (t_3 <= 0.1) {
        		tmp = t_1;
        	} else if (t_3 <= 0.998) {
        		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
        	} else if (t_3 <= 2.0) {
        		tmp = fma((kx * (kx / t_2)), -0.5, 1.0) * sin(th);
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        function code(kx, ky, th)
        	t_1 = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th))
        	t_2 = sin(ky) ^ 2.0
        	t_3 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_2)))
        	tmp = 0.0
        	if (t_3 <= -1.0)
        		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * sin(th));
        	elseif (t_3 <= -0.12)
        		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
        	elseif (t_3 <= 0.1)
        		tmp = t_1;
        	elseif (t_3 <= 0.998)
        		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
        	elseif (t_3 <= 2.0)
        		tmp = Float64(fma(Float64(kx * Float64(kx / t_2)), -0.5, 1.0) * sin(th));
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.12], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.1], t$95$1, If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(N[(kx * N[(kx / t$95$2), $MachinePrecision]), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
        t_2 := {\sin ky}^{2}\\
        t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_2}}\\
        \mathbf{if}\;t\_3 \leq -1:\\
        \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\
        
        \mathbf{elif}\;t\_3 \leq -0.12:\\
        \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
        
        \mathbf{elif}\;t\_3 \leq 0.1:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;t\_3 \leq 0.998:\\
        \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
        
        \mathbf{elif}\;t\_3 \leq 2:\\
        \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{t\_2}, -0.5, 1\right) \cdot \sin th\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 5 regimes
        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

          1. Initial program 82.4%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-pow.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
            2. unpow2N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
            3. sqr-neg-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\mathsf{neg}\left(\sin ky\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}}} \cdot \sin th \]
            4. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
            5. cos-+PI/2-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
            6. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right)}} \cdot \sin th \]
            7. cos-+PI/2-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)}}} \cdot \sin th \]
            8. 1-sub-sin-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(1 - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}}} \cdot \sin th \]
            9. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{\frac{2}{2}} - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
            10. sin-+PI/2-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \color{blue}{\cos ky} \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
            11. sin-+PI/2-revN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \cos ky \cdot \color{blue}{\cos ky}\right)}} \cdot \sin th \]
            12. lower--.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\frac{2}{2} - \cos ky \cdot \cos ky\right)}}} \cdot \sin th \]
            13. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{1} - \cos ky \cdot \cos ky\right)}} \cdot \sin th \]
            14. lower-*.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky \cdot \cos ky}\right)}} \cdot \sin th \]
            15. lower-cos.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky} \cdot \cos ky\right)}} \cdot \sin th \]
            16. lower-cos.f6462.1

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

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

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{1 - {\cos ky}^{2}}}} \cdot \sin th \]
          6. Step-by-step derivation
            1. unpow2N/A

              \[\leadsto \frac{\sin ky}{\sqrt{1 - \color{blue}{\cos ky \cdot \cos ky}}} \cdot \sin th \]
            2. 1-sub-cosN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
            3. unpow2N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
            4. lower-sqrt.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]
            5. lower-pow.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
            6. lower-sin.f6482.4

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

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]

          if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.12

          1. Initial program 99.3%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-sqrt.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
            2. lift-+.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
            4. lift-pow.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
            6. lift-pow.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
            8. lower-hypot.f6499.2

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

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

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
          6. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
            2. lower-*.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
            3. +-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
            4. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
            5. lower-fma.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
            6. unpow2N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
            7. lower-*.f6451.7

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

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
          8. Step-by-step derivation
            1. lift-hypot.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            2. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            3. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            4. sin-multN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            5. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            6. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            7. sin-multN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            8. frac-addN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            9. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            10. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            11. sqrt-divN/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            12. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            13. metadata-evalN/A

              \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            14. lower-/.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
          9. Applied rewrites51.8%

            \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

          if -0.12 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.10000000000000001 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

          1. Initial program 98.6%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-sqrt.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
            2. lift-+.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
            4. lift-pow.f64N/A

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

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
            6. lift-pow.f64N/A

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

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

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

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

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
          6. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
            2. lower-*.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
            3. +-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
            4. *-commutativeN/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
            5. lower-fma.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
            6. unpow2N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
            7. lower-*.f6496.5

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

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

          if 0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

          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 th around 0

            \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          4. Step-by-step derivation
            1. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
            3. lower-*.f64N/A

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

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

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
            6. lower-/.f64N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
            7. unpow2N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
            8. lower-fma.f64N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
            9. lower-sin.f64N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
            10. lower-sin.f64N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
            11. lower-pow.f64N/A

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
            12. lower-sin.f6450.1

              \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
          5. Applied rewrites50.1%

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

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

            if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{\left(1 + \frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}}\right)} \cdot \sin th \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \color{blue}{\left(\frac{-1}{2} \cdot \frac{{kx}^{2}}{{\sin ky}^{2}} + 1\right)} \cdot \sin th \]
              2. *-commutativeN/A

                \[\leadsto \left(\color{blue}{\frac{{kx}^{2}}{{\sin ky}^{2}} \cdot \frac{-1}{2}} + 1\right) \cdot \sin th \]
              3. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{kx}^{2}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right)} \cdot \sin th \]
              4. unpow2N/A

                \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{kx \cdot kx}}{{\sin ky}^{2}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
              5. associate-/l*N/A

                \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
              6. lower-*.f64N/A

                \[\leadsto \mathsf{fma}\left(\color{blue}{kx \cdot \frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
              7. lower-/.f64N/A

                \[\leadsto \mathsf{fma}\left(kx \cdot \color{blue}{\frac{kx}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
              8. lower-pow.f64N/A

                \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{\color{blue}{{\sin ky}^{2}}}, \frac{-1}{2}, 1\right) \cdot \sin th \]
              9. lower-sin.f6497.7

                \[\leadsto \mathsf{fma}\left(kx \cdot \frac{kx}{{\color{blue}{\sin ky}}^{2}}, -0.5, 1\right) \cdot \sin th \]
            5. Applied rewrites97.7%

              \[\leadsto \color{blue}{\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right)} \cdot \sin th \]
          7. Recombined 5 regimes into one program.
          8. Final simplification81.7%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.12:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2:\\ \;\;\;\;\mathsf{fma}\left(kx \cdot \frac{kx}{{\sin ky}^{2}}, -0.5, 1\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \end{array} \]
          9. Add Preprocessing

          Alternative 6: 77.5% accurate, 0.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_2 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.998:\\ \;\;\;\;\left(\sin ky \cdot th\right) \cdot {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
          (FPCore (kx ky th)
           :precision binary64
           (let* ((t_1 (pow (sin kx) 2.0))
                  (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
             (if (<= t_2 -1.0)
               (*
                (sqrt (pow (- 1.0 (cos (* -2.0 ky))) -1.0))
                (* (* (sqrt 2.0) (sin th)) (sin ky)))
               (if (<= t_2 -0.1)
                 (*
                  (/
                   (sin ky)
                   (/
                    (sqrt
                     (fma
                      (- 1.0 (cos (* 2.0 ky)))
                      2.0
                      (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                    2.0))
                  (* (fma (* th th) -0.16666666666666666 1.0) th))
                 (if (<= t_2 0.0002)
                   (*
                    (/
                     (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                     (sqrt (+ t_1 (* ky ky))))
                    (sin th))
                   (if (<= t_2 0.998)
                     (* (* (sin ky) th) (pow (hypot (sin kx) (sin ky)) -1.0))
                     (sin th)))))))
          double code(double kx, double ky, double th) {
          	double t_1 = pow(sin(kx), 2.0);
          	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
          	double tmp;
          	if (t_2 <= -1.0) {
          		tmp = sqrt(pow((1.0 - cos((-2.0 * ky))), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
          	} else if (t_2 <= -0.1) {
          		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
          	} else if (t_2 <= 0.0002) {
          		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
          	} else if (t_2 <= 0.998) {
          		tmp = (sin(ky) * th) * pow(hypot(sin(kx), sin(ky)), -1.0);
          	} else {
          		tmp = sin(th);
          	}
          	return tmp;
          }
          
          function code(kx, ky, th)
          	t_1 = sin(kx) ^ 2.0
          	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
          	tmp = 0.0
          	if (t_2 <= -1.0)
          		tmp = Float64(sqrt((Float64(1.0 - cos(Float64(-2.0 * ky))) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
          	elseif (t_2 <= -0.1)
          		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
          	elseif (t_2 <= 0.0002)
          		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
          	elseif (t_2 <= 0.998)
          		tmp = Float64(Float64(sin(ky) * th) * (hypot(sin(kx), sin(ky)) ^ -1.0));
          	else
          		tmp = sin(th);
          	end
          	return tmp
          end
          
          code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.1], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.998], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] * N[Power[N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_1 := {\sin kx}^{2}\\
          t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
          \mathbf{if}\;t\_2 \leq -1:\\
          \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
          
          \mathbf{elif}\;t\_2 \leq -0.1:\\
          \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
          
          \mathbf{elif}\;t\_2 \leq 0.0002:\\
          \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
          
          \mathbf{elif}\;t\_2 \leq 0.998:\\
          \;\;\;\;\left(\sin ky \cdot th\right) \cdot {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1}\\
          
          \mathbf{else}:\\
          \;\;\;\;\sin th\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 5 regimes
          2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

            1. Initial program 82.4%

              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            2. Add Preprocessing
            3. Step-by-step derivation
              1. lift-*.f64N/A

                \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
              2. lift-/.f64N/A

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

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

                \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
              5. *-commutativeN/A

                \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
              6. lower-*.f64N/A

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

                \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
              8. lift-sqrt.f64N/A

                \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
              9. lift-+.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
              10. +-commutativeN/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
              11. lift-pow.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
              12. unpow2N/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
              13. lift-pow.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
              14. unpow2N/A

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

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

              \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
            5. Step-by-step derivation
              1. lift-hypot.f64N/A

                \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
              2. lift-sin.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
              3. lift-sin.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
              4. sin-multN/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
              5. lift-sin.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
              6. lift-sin.f64N/A

                \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
              7. sin-multN/A

                \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
              8. div-add-revN/A

                \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
              9. sqrt-divN/A

                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
              10. lower-/.f64N/A

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

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

              \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
            8. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
              2. lower-*.f64N/A

                \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
              3. lower-sqrt.f64N/A

                \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              4. lower-/.f64N/A

                \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              5. lower--.f64N/A

                \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              6. cos-neg-revN/A

                \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              7. lower-cos.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              8. distribute-lft-neg-inN/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              9. metadata-evalN/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              10. lower-*.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
              11. *-commutativeN/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
              12. lower-*.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
              13. *-commutativeN/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
              14. lower-*.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
              15. lower-sqrt.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
              16. lower-sin.f64N/A

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
              17. lower-sin.f6462.1

                \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
            9. Applied rewrites62.1%

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

            if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

            1. Initial program 99.3%

              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            2. Add Preprocessing
            3. Step-by-step derivation
              1. lift-sqrt.f64N/A

                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
              2. lift-+.f64N/A

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

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
              4. lift-pow.f64N/A

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

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
              6. lift-pow.f64N/A

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

                \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
              8. lower-hypot.f6499.2

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

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

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
            6. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
              2. lower-*.f64N/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
              3. +-commutativeN/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
              4. *-commutativeN/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
              5. lower-fma.f64N/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
              6. unpow2N/A

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
              7. lower-*.f6450.3

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

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
            8. Step-by-step derivation
              1. lift-hypot.f64N/A

                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              2. lift-sin.f64N/A

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              3. lift-sin.f64N/A

                \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              4. sin-multN/A

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              5. lift-sin.f64N/A

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              6. lift-sin.f64N/A

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              7. sin-multN/A

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              8. frac-addN/A

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              9. metadata-evalN/A

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              10. metadata-evalN/A

                \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              11. sqrt-divN/A

                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              12. metadata-evalN/A

                \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              13. metadata-evalN/A

                \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              14. lower-/.f64N/A

                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
            9. Applied rewrites50.4%

              \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

            if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

            1. Initial program 99.6%

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

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
            4. Step-by-step derivation
              1. unpow2N/A

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

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

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
            6. Taylor expanded in ky around 0

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

                \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              2. lower-*.f64N/A

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

                \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              4. *-commutativeN/A

                \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              5. lower-fma.f64N/A

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              6. unpow2N/A

                \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              7. lower-*.f6498.6

                \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
            8. Applied rewrites98.6%

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

            if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

            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 th around 0

              \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
            4. Step-by-step derivation
              1. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
              3. lower-*.f64N/A

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

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

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
              6. lower-/.f64N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
              7. unpow2N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
              8. lower-fma.f64N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
              9. lower-sin.f64N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
              10. lower-sin.f64N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
              11. lower-pow.f64N/A

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
              12. lower-sin.f6450.1

                \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
            5. Applied rewrites50.1%

              \[\leadsto \color{blue}{\left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
            6. Step-by-step derivation
              1. Applied rewrites50.0%

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

              if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

              1. Initial program 97.8%

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

                \[\leadsto \color{blue}{\sin th} \]
              4. Step-by-step derivation
                1. lower-sin.f6498.5

                  \[\leadsto \color{blue}{\sin th} \]
              5. Applied rewrites98.5%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\left(\sin ky \cdot th\right) \cdot {\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
            9. Add Preprocessing

            Alternative 7: 77.5% accurate, 0.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := \cos \left(-2 \cdot ky\right)\\ t_2 := {\sin kx}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\ t_4 := \cos \left(-2 \cdot kx\right)\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - t\_1\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_3 \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - t\_4\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_3 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_2 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - t\_4\right) - t\_1\right)}^{-1}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
            (FPCore (kx ky th)
             :precision binary64
             (let* ((t_1 (cos (* -2.0 ky)))
                    (t_2 (pow (sin kx) 2.0))
                    (t_3 (/ (sin ky) (sqrt (+ t_2 (pow (sin ky) 2.0)))))
                    (t_4 (cos (* -2.0 kx))))
               (if (<= t_3 -1.0)
                 (* (sqrt (pow (- 1.0 t_1) -1.0)) (* (* (sqrt 2.0) (sin th)) (sin ky)))
                 (if (<= t_3 -0.1)
                   (*
                    (/
                     (sin ky)
                     (/ (sqrt (fma (- 1.0 (cos (* 2.0 ky))) 2.0 (* 2.0 (- 1.0 t_4)))) 2.0))
                    (* (fma (* th th) -0.16666666666666666 1.0) th))
                   (if (<= t_3 0.0002)
                     (*
                      (/
                       (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                       (sqrt (+ t_2 (* ky ky))))
                      (sin th))
                     (if (<= t_3 0.998)
                       (*
                        (* (* th (sin ky)) (sqrt 2.0))
                        (sqrt (pow (- (- 2.0 t_4) t_1) -1.0)))
                       (sin th)))))))
            double code(double kx, double ky, double th) {
            	double t_1 = cos((-2.0 * ky));
            	double t_2 = pow(sin(kx), 2.0);
            	double t_3 = sin(ky) / sqrt((t_2 + pow(sin(ky), 2.0)));
            	double t_4 = cos((-2.0 * kx));
            	double tmp;
            	if (t_3 <= -1.0) {
            		tmp = sqrt(pow((1.0 - t_1), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
            	} else if (t_3 <= -0.1) {
            		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - t_4)))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
            	} else if (t_3 <= 0.0002) {
            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_2 + (ky * ky)))) * sin(th);
            	} else if (t_3 <= 0.998) {
            		tmp = ((th * sin(ky)) * sqrt(2.0)) * sqrt(pow(((2.0 - t_4) - t_1), -1.0));
            	} else {
            		tmp = sin(th);
            	}
            	return tmp;
            }
            
            function code(kx, ky, th)
            	t_1 = cos(Float64(-2.0 * ky))
            	t_2 = sin(kx) ^ 2.0
            	t_3 = Float64(sin(ky) / sqrt(Float64(t_2 + (sin(ky) ^ 2.0))))
            	t_4 = cos(Float64(-2.0 * kx))
            	tmp = 0.0
            	if (t_3 <= -1.0)
            		tmp = Float64(sqrt((Float64(1.0 - t_1) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
            	elseif (t_3 <= -0.1)
            		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - t_4)))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
            	elseif (t_3 <= 0.0002)
            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_2 + Float64(ky * ky)))) * sin(th));
            	elseif (t_3 <= 0.998)
            		tmp = Float64(Float64(Float64(th * sin(ky)) * sqrt(2.0)) * sqrt((Float64(Float64(2.0 - t_4) - t_1) ^ -1.0)));
            	else
            		tmp = sin(th);
            	end
            	return tmp
            end
            
            code[kx_, ky_, th_] := Block[{t$95$1 = N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - t$95$1), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.1], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(N[(2.0 - t$95$4), $MachinePrecision] - t$95$1), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_1 := \cos \left(-2 \cdot ky\right)\\
            t_2 := {\sin kx}^{2}\\
            t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\
            t_4 := \cos \left(-2 \cdot kx\right)\\
            \mathbf{if}\;t\_3 \leq -1:\\
            \;\;\;\;\sqrt{{\left(1 - t\_1\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
            
            \mathbf{elif}\;t\_3 \leq -0.1:\\
            \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - t\_4\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
            
            \mathbf{elif}\;t\_3 \leq 0.0002:\\
            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_2 + ky \cdot ky}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_3 \leq 0.998:\\
            \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - t\_4\right) - t\_1\right)}^{-1}}\\
            
            \mathbf{else}:\\
            \;\;\;\;\sin th\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 5 regimes
            2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

              1. Initial program 82.4%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

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

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
              8. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                3. lower-sqrt.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                4. lower-/.f64N/A

                  \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                5. lower--.f64N/A

                  \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                6. cos-neg-revN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                7. lower-cos.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                8. distribute-lft-neg-inN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                9. metadata-evalN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                10. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                11. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                12. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                13. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                14. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                15. lower-sqrt.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                16. lower-sin.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                17. lower-sin.f6462.1

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
              9. Applied rewrites62.1%

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

              if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

              1. Initial program 99.3%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                2. lift-+.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                4. lift-pow.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                6. lift-pow.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                8. lower-hypot.f6499.2

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

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

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
              6. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                3. +-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                6. unpow2N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                7. lower-*.f6450.3

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

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
              8. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                8. frac-addN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                9. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                10. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                11. sqrt-divN/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                12. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                13. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                14. lower-/.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              9. Applied rewrites50.4%

                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

              if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

              1. Initial program 99.6%

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. unpow2N/A

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
              6. Taylor expanded in ky around 0

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

                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                2. lower-*.f64N/A

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

                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                6. unpow2N/A

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                7. lower-*.f6498.6

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              8. Applied rewrites98.6%

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

              if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

              1. Initial program 99.5%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin ky \]
                15. lower-hypot.f6499.4

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
              8. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                2. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                3. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                4. lower-*.f64N/A

                  \[\leadsto \left(\color{blue}{\left(th \cdot \sin ky\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                5. lower-sin.f64N/A

                  \[\leadsto \left(\left(th \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                6. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                7. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                8. lower-/.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                9. associate--r+N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                10. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                11. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right)} - \cos \left(2 \cdot ky\right)}} \]
                12. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                13. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                14. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                15. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                16. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{-2} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                17. lower-*.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(-2 \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                18. cos-neg-revN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                19. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                20. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \]
              9. Applied rewrites49.9%

                \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)}}} \]

              if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

              1. Initial program 97.8%

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

                \[\leadsto \color{blue}{\sin th} \]
              4. Step-by-step derivation
                1. lower-sin.f6498.5

                  \[\leadsto \color{blue}{\sin th} \]
              5. Applied rewrites98.5%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)\right)}^{-1}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
            5. Add Preprocessing

            Alternative 8: 77.5% accurate, 0.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ t_3 := \cos \left(-2 \cdot ky\right)\\ t_4 := \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - t\_3\right)}^{-1}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - t\_3\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq -0.1:\\ \;\;\;\;\left(\left(\sqrt{2} \cdot th\right) \cdot t\_4\right) \cdot \sin ky\\ \mathbf{elif}\;t\_2 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.998:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot t\_4\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
            (FPCore (kx ky th)
             :precision binary64
             (let* ((t_1 (pow (sin kx) 2.0))
                    (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0)))))
                    (t_3 (cos (* -2.0 ky)))
                    (t_4 (sqrt (pow (- (- 2.0 (cos (* -2.0 kx))) t_3) -1.0))))
               (if (<= t_2 -1.0)
                 (* (sqrt (pow (- 1.0 t_3) -1.0)) (* (* (sqrt 2.0) (sin th)) (sin ky)))
                 (if (<= t_2 -0.1)
                   (* (* (* (sqrt 2.0) th) t_4) (sin ky))
                   (if (<= t_2 0.0002)
                     (*
                      (/
                       (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                       (sqrt (+ t_1 (* ky ky))))
                      (sin th))
                     (if (<= t_2 0.998)
                       (* (* (* th (sin ky)) (sqrt 2.0)) t_4)
                       (sin th)))))))
            double code(double kx, double ky, double th) {
            	double t_1 = pow(sin(kx), 2.0);
            	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
            	double t_3 = cos((-2.0 * ky));
            	double t_4 = sqrt(pow(((2.0 - cos((-2.0 * kx))) - t_3), -1.0));
            	double tmp;
            	if (t_2 <= -1.0) {
            		tmp = sqrt(pow((1.0 - t_3), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
            	} else if (t_2 <= -0.1) {
            		tmp = ((sqrt(2.0) * th) * t_4) * sin(ky);
            	} else if (t_2 <= 0.0002) {
            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
            	} else if (t_2 <= 0.998) {
            		tmp = ((th * sin(ky)) * sqrt(2.0)) * t_4;
            	} else {
            		tmp = sin(th);
            	}
            	return tmp;
            }
            
            function code(kx, ky, th)
            	t_1 = sin(kx) ^ 2.0
            	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
            	t_3 = cos(Float64(-2.0 * ky))
            	t_4 = sqrt((Float64(Float64(2.0 - cos(Float64(-2.0 * kx))) - t_3) ^ -1.0))
            	tmp = 0.0
            	if (t_2 <= -1.0)
            		tmp = Float64(sqrt((Float64(1.0 - t_3) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
            	elseif (t_2 <= -0.1)
            		tmp = Float64(Float64(Float64(sqrt(2.0) * th) * t_4) * sin(ky));
            	elseif (t_2 <= 0.0002)
            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
            	elseif (t_2 <= 0.998)
            		tmp = Float64(Float64(Float64(th * sin(ky)) * sqrt(2.0)) * t_4);
            	else
            		tmp = sin(th);
            	end
            	return tmp
            end
            
            code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[Power[N[(N[(2.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$3), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - t$95$3), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.1], N[(N[(N[(N[Sqrt[2.0], $MachinePrecision] * th), $MachinePrecision] * t$95$4), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.998], N[(N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * t$95$4), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_1 := {\sin kx}^{2}\\
            t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
            t_3 := \cos \left(-2 \cdot ky\right)\\
            t_4 := \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - t\_3\right)}^{-1}}\\
            \mathbf{if}\;t\_2 \leq -1:\\
            \;\;\;\;\sqrt{{\left(1 - t\_3\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
            
            \mathbf{elif}\;t\_2 \leq -0.1:\\
            \;\;\;\;\left(\left(\sqrt{2} \cdot th\right) \cdot t\_4\right) \cdot \sin ky\\
            
            \mathbf{elif}\;t\_2 \leq 0.0002:\\
            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_2 \leq 0.998:\\
            \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot t\_4\\
            
            \mathbf{else}:\\
            \;\;\;\;\sin th\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 5 regimes
            2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

              1. Initial program 82.4%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

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

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
              8. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                3. lower-sqrt.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                4. lower-/.f64N/A

                  \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                5. lower--.f64N/A

                  \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                6. cos-neg-revN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                7. lower-cos.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                8. distribute-lft-neg-inN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                9. metadata-evalN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                10. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                11. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                12. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                13. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                14. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                15. lower-sqrt.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                16. lower-sin.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                17. lower-sin.f6462.1

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
              9. Applied rewrites62.1%

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

              if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

              1. Initial program 99.3%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                7. lower-/.f6499.1

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin ky \]
                15. lower-hypot.f6499.1

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(\left(th \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}\right)} \cdot \sin ky \]
              8. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}\right)} \cdot \sin ky \]
                2. *-commutativeN/A

                  \[\leadsto \left(\color{blue}{\left(\sqrt{2} \cdot th\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
                3. lower-*.f64N/A

                  \[\leadsto \left(\color{blue}{\left(\sqrt{2} \cdot th\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
                4. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(\color{blue}{\sqrt{2}} \cdot th\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}\right) \cdot \sin ky \]
                5. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin ky \]
                6. lower-/.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}}\right) \cdot \sin ky \]
                7. associate--r+N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}}\right) \cdot \sin ky \]
                8. lower--.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}}\right) \cdot \sin ky \]
                9. lower--.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right)} - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                10. metadata-evalN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                11. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                12. lower-cos.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                13. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                14. metadata-evalN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{-2} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                15. lower-*.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(-2 \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}}\right) \cdot \sin ky \]
                16. cos-neg-revN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}}\right) \cdot \sin ky \]
                17. lower-cos.f64N/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}}\right) \cdot \sin ky \]
                18. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}}\right) \cdot \sin ky \]
                19. metadata-evalN/A

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(\color{blue}{-2} \cdot ky\right)}}\right) \cdot \sin ky \]
                20. lower-*.f6449.7

                  \[\leadsto \left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \color{blue}{\left(-2 \cdot ky\right)}}}\right) \cdot \sin ky \]
              9. Applied rewrites49.7%

                \[\leadsto \color{blue}{\left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)}}\right)} \cdot \sin ky \]

              if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

              1. Initial program 99.6%

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. unpow2N/A

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
              6. Taylor expanded in ky around 0

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

                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                2. lower-*.f64N/A

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

                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                6. unpow2N/A

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                7. lower-*.f6498.6

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              8. Applied rewrites98.6%

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

              if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

              1. Initial program 99.5%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin ky \]
                15. lower-hypot.f6499.4

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
              8. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                2. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                3. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                4. lower-*.f64N/A

                  \[\leadsto \left(\color{blue}{\left(th \cdot \sin ky\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                5. lower-sin.f64N/A

                  \[\leadsto \left(\left(th \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                6. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                7. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                8. lower-/.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                9. associate--r+N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                10. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                11. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right)} - \cos \left(2 \cdot ky\right)}} \]
                12. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                13. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                14. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                15. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                16. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{-2} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                17. lower-*.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(-2 \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                18. cos-neg-revN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                19. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                20. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \]
              9. Applied rewrites49.9%

                \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)}}} \]

              if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

              1. Initial program 97.8%

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

                \[\leadsto \color{blue}{\sin th} \]
              4. Step-by-step derivation
                1. lower-sin.f6498.5

                  \[\leadsto \color{blue}{\sin th} \]
              5. Applied rewrites98.5%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\left(\left(\sqrt{2} \cdot th\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)\right)}^{-1}}\right) \cdot \sin ky\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)\right)}^{-1}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
            5. Add Preprocessing

            Alternative 9: 77.5% accurate, 0.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ t_3 := \cos \left(-2 \cdot ky\right)\\ t_4 := \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - t\_3\right)}^{-1}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - t\_3\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq -0.1:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_2 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.998:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
            (FPCore (kx ky th)
             :precision binary64
             (let* ((t_1 (pow (sin kx) 2.0))
                    (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0)))))
                    (t_3 (cos (* -2.0 ky)))
                    (t_4
                     (*
                      (* (* th (sin ky)) (sqrt 2.0))
                      (sqrt (pow (- (- 2.0 (cos (* -2.0 kx))) t_3) -1.0)))))
               (if (<= t_2 -1.0)
                 (* (sqrt (pow (- 1.0 t_3) -1.0)) (* (* (sqrt 2.0) (sin th)) (sin ky)))
                 (if (<= t_2 -0.1)
                   t_4
                   (if (<= t_2 0.0002)
                     (*
                      (/
                       (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                       (sqrt (+ t_1 (* ky ky))))
                      (sin th))
                     (if (<= t_2 0.998) t_4 (sin th)))))))
            double code(double kx, double ky, double th) {
            	double t_1 = pow(sin(kx), 2.0);
            	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
            	double t_3 = cos((-2.0 * ky));
            	double t_4 = ((th * sin(ky)) * sqrt(2.0)) * sqrt(pow(((2.0 - cos((-2.0 * kx))) - t_3), -1.0));
            	double tmp;
            	if (t_2 <= -1.0) {
            		tmp = sqrt(pow((1.0 - t_3), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
            	} else if (t_2 <= -0.1) {
            		tmp = t_4;
            	} else if (t_2 <= 0.0002) {
            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
            	} else if (t_2 <= 0.998) {
            		tmp = t_4;
            	} else {
            		tmp = sin(th);
            	}
            	return tmp;
            }
            
            function code(kx, ky, th)
            	t_1 = sin(kx) ^ 2.0
            	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
            	t_3 = cos(Float64(-2.0 * ky))
            	t_4 = Float64(Float64(Float64(th * sin(ky)) * sqrt(2.0)) * sqrt((Float64(Float64(2.0 - cos(Float64(-2.0 * kx))) - t_3) ^ -1.0)))
            	tmp = 0.0
            	if (t_2 <= -1.0)
            		tmp = Float64(sqrt((Float64(1.0 - t_3) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
            	elseif (t_2 <= -0.1)
            		tmp = t_4;
            	elseif (t_2 <= 0.0002)
            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
            	elseif (t_2 <= 0.998)
            		tmp = t_4;
            	else
            		tmp = sin(th);
            	end
            	return tmp
            end
            
            code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[(N[(2.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$3), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - t$95$3), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.1], t$95$4, If[LessEqual[t$95$2, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.998], t$95$4, N[Sin[th], $MachinePrecision]]]]]]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_1 := {\sin kx}^{2}\\
            t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
            t_3 := \cos \left(-2 \cdot ky\right)\\
            t_4 := \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - t\_3\right)}^{-1}}\\
            \mathbf{if}\;t\_2 \leq -1:\\
            \;\;\;\;\sqrt{{\left(1 - t\_3\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
            
            \mathbf{elif}\;t\_2 \leq -0.1:\\
            \;\;\;\;t\_4\\
            
            \mathbf{elif}\;t\_2 \leq 0.0002:\\
            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_2 \leq 0.998:\\
            \;\;\;\;t\_4\\
            
            \mathbf{else}:\\
            \;\;\;\;\sin th\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 4 regimes
            2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

              1. Initial program 82.4%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

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

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
              8. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                3. lower-sqrt.f64N/A

                  \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                4. lower-/.f64N/A

                  \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                5. lower--.f64N/A

                  \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                6. cos-neg-revN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                7. lower-cos.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                8. distribute-lft-neg-inN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                9. metadata-evalN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                10. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                11. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                12. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                13. *-commutativeN/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                14. lower-*.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                15. lower-sqrt.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                16. lower-sin.f64N/A

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                17. lower-sin.f6462.1

                  \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
              9. Applied rewrites62.1%

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

              if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001 or 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

              1. Initial program 99.4%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                2. lift-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                5. *-commutativeN/A

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                6. lower-*.f64N/A

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                8. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                9. lift-+.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                10. +-commutativeN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                11. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                12. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                13. lift-pow.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                14. unpow2N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin ky \]
                15. lower-hypot.f6499.2

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

                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
              5. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                8. div-add-revN/A

                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                9. sqrt-divN/A

                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                10. lower-/.f64N/A

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

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

                \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
              8. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(th \cdot \left(\sin ky \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                2. associate-*r*N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                3. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right)} \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                4. lower-*.f64N/A

                  \[\leadsto \left(\color{blue}{\left(th \cdot \sin ky\right)} \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                5. lower-sin.f64N/A

                  \[\leadsto \left(\left(th \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                6. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \color{blue}{\sqrt{2}}\right) \cdot \sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}} \]
                7. lower-sqrt.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                8. lower-/.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\color{blue}{\frac{1}{2 - \left(\cos \left(-2 \cdot kx\right) + \cos \left(2 \cdot ky\right)\right)}}} \]
                9. associate--r+N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                10. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}}} \]
                11. lower--.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\color{blue}{\left(2 - \cos \left(-2 \cdot kx\right)\right)} - \cos \left(2 \cdot ky\right)}} \]
                12. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                13. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                14. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                15. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                16. metadata-evalN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(\color{blue}{-2} \cdot kx\right)\right) - \cos \left(2 \cdot ky\right)}} \]
                17. lower-*.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \color{blue}{\left(-2 \cdot kx\right)}\right) - \cos \left(2 \cdot ky\right)}} \]
                18. cos-neg-revN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                19. lower-cos.f64N/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \]
                20. distribute-lft-neg-inN/A

                  \[\leadsto \left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \]
              9. Applied rewrites49.8%

                \[\leadsto \color{blue}{\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{\frac{1}{\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)}}} \]

              if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

              1. Initial program 99.6%

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. unpow2N/A

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
              6. Taylor expanded in ky around 0

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

                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                2. lower-*.f64N/A

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

                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                6. unpow2N/A

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                7. lower-*.f6498.6

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              8. Applied rewrites98.6%

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

              if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

              1. Initial program 97.8%

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

                \[\leadsto \color{blue}{\sin th} \]
              4. Step-by-step derivation
                1. lower-sin.f6498.5

                  \[\leadsto \color{blue}{\sin th} \]
              5. Applied rewrites98.5%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)\right)}^{-1}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\left(\left(th \cdot \sin ky\right) \cdot \sqrt{2}\right) \cdot \sqrt{{\left(\left(2 - \cos \left(-2 \cdot kx\right)\right) - \cos \left(-2 \cdot ky\right)\right)}^{-1}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
            5. Add Preprocessing

            Alternative 10: 81.7% accurate, 0.2× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\ \mathbf{if}\;t\_3 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_3 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
            (FPCore (kx ky th)
             :precision binary64
             (let* ((t_1 (pow (sin kx) 2.0))
                    (t_2 (pow (sin ky) 2.0))
                    (t_3 (/ (sin ky) (sqrt (+ t_1 t_2)))))
               (if (<= t_3 -1.0)
                 (* (/ (sin ky) (sqrt t_2)) (sin th))
                 (if (<= t_3 -0.1)
                   (*
                    (/
                     (sin ky)
                     (/
                      (sqrt
                       (fma
                        (- 1.0 (cos (* 2.0 ky)))
                        2.0
                        (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                      2.0))
                    (* (fma (* th th) -0.16666666666666666 1.0) th))
                   (if (<= t_3 0.0002)
                     (*
                      (/
                       (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                       (sqrt (+ t_1 (* ky ky))))
                      (sin th))
                     (if (<= t_3 0.998)
                       (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
                       (sin th)))))))
            double code(double kx, double ky, double th) {
            	double t_1 = pow(sin(kx), 2.0);
            	double t_2 = pow(sin(ky), 2.0);
            	double t_3 = sin(ky) / sqrt((t_1 + t_2));
            	double tmp;
            	if (t_3 <= -1.0) {
            		tmp = (sin(ky) / sqrt(t_2)) * sin(th);
            	} else if (t_3 <= -0.1) {
            		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
            	} else if (t_3 <= 0.0002) {
            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
            	} else if (t_3 <= 0.998) {
            		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
            	} else {
            		tmp = sin(th);
            	}
            	return tmp;
            }
            
            function code(kx, ky, th)
            	t_1 = sin(kx) ^ 2.0
            	t_2 = sin(ky) ^ 2.0
            	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + t_2)))
            	tmp = 0.0
            	if (t_3 <= -1.0)
            		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * sin(th));
            	elseif (t_3 <= -0.1)
            		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
            	elseif (t_3 <= 0.0002)
            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
            	elseif (t_3 <= 0.998)
            		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
            	else
            		tmp = sin(th);
            	end
            	return tmp
            end
            
            code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.1], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_1 := {\sin kx}^{2}\\
            t_2 := {\sin ky}^{2}\\
            t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\
            \mathbf{if}\;t\_3 \leq -1:\\
            \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_3 \leq -0.1:\\
            \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
            
            \mathbf{elif}\;t\_3 \leq 0.0002:\\
            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
            
            \mathbf{elif}\;t\_3 \leq 0.998:\\
            \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
            
            \mathbf{else}:\\
            \;\;\;\;\sin th\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 5 regimes
            2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

              1. Initial program 82.4%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-pow.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                2. unpow2N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
                3. sqr-neg-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\mathsf{neg}\left(\sin ky\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}}} \cdot \sin th \]
                4. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right) \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
                5. cos-+PI/2-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \left(\mathsf{neg}\left(\sin ky\right)\right)}} \cdot \sin th \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \left(\mathsf{neg}\left(\color{blue}{\sin ky}\right)\right)}} \cdot \sin th \]
                7. cos-+PI/2-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \color{blue}{\cos \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)}}} \cdot \sin th \]
                8. 1-sub-sin-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(1 - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}}} \cdot \sin th \]
                9. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{\frac{2}{2}} - \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right) \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
                10. sin-+PI/2-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \color{blue}{\cos ky} \cdot \sin \left(ky + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)}} \cdot \sin th \]
                11. sin-+PI/2-revN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\frac{2}{2} - \cos ky \cdot \color{blue}{\cos ky}\right)}} \cdot \sin th \]
                12. lower--.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\left(\frac{2}{2} - \cos ky \cdot \cos ky\right)}}} \cdot \sin th \]
                13. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(\color{blue}{1} - \cos ky \cdot \cos ky\right)}} \cdot \sin th \]
                14. lower-*.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky \cdot \cos ky}\right)}} \cdot \sin th \]
                15. lower-cos.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 - \color{blue}{\cos ky} \cdot \cos ky\right)}} \cdot \sin th \]
                16. lower-cos.f6462.1

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

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

                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{1 - {\cos ky}^{2}}}} \cdot \sin th \]
              6. Step-by-step derivation
                1. unpow2N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{1 - \color{blue}{\cos ky \cdot \cos ky}}} \cdot \sin th \]
                2. 1-sub-cosN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
                3. unpow2N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                4. lower-sqrt.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]
                5. lower-pow.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                6. lower-sin.f6482.4

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

                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \cdot \sin th \]

              if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

              1. Initial program 99.3%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Step-by-step derivation
                1. lift-sqrt.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                2. lift-+.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                4. lift-pow.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                6. lift-pow.f64N/A

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

                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                8. lower-hypot.f6499.2

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

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

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
              6. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                2. lower-*.f64N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                3. +-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                6. unpow2N/A

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                7. lower-*.f6450.3

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

                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
              8. Step-by-step derivation
                1. lift-hypot.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                2. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                3. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                4. sin-multN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                5. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                6. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                7. sin-multN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                8. frac-addN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                9. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                10. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                11. sqrt-divN/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                12. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                13. metadata-evalN/A

                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                14. lower-/.f64N/A

                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              9. Applied rewrites50.4%

                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

              if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

              1. Initial program 99.6%

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. unpow2N/A

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
              6. Taylor expanded in ky around 0

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

                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                2. lower-*.f64N/A

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

                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                4. *-commutativeN/A

                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                5. lower-fma.f64N/A

                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                6. unpow2N/A

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                7. lower-*.f6498.6

                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
              8. Applied rewrites98.6%

                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

              if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

              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 th around 0

                \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
              4. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                2. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                3. lower-*.f64N/A

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

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

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                6. lower-/.f64N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                7. unpow2N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
                8. lower-fma.f64N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
                9. lower-sin.f64N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
                10. lower-sin.f64N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
                11. lower-pow.f64N/A

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
                12. lower-sin.f6450.1

                  \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
              5. Applied rewrites50.1%

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

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

                if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                1. Initial program 97.8%

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

                  \[\leadsto \color{blue}{\sin th} \]
                4. Step-by-step derivation
                  1. lower-sin.f6498.5

                    \[\leadsto \color{blue}{\sin th} \]
                5. Applied rewrites98.5%

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
              9. Add Preprocessing

              Alternative 11: 77.6% accurate, 0.2× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_2 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
              (FPCore (kx ky th)
               :precision binary64
               (let* ((t_1 (pow (sin kx) 2.0))
                      (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                 (if (<= t_2 -1.0)
                   (*
                    (sqrt (pow (- 1.0 (cos (* -2.0 ky))) -1.0))
                    (* (* (sqrt 2.0) (sin th)) (sin ky)))
                   (if (<= t_2 -0.1)
                     (*
                      (/
                       (sin ky)
                       (/
                        (sqrt
                         (fma
                          (- 1.0 (cos (* 2.0 ky)))
                          2.0
                          (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                        2.0))
                      (* (fma (* th th) -0.16666666666666666 1.0) th))
                     (if (<= t_2 0.0002)
                       (*
                        (/
                         (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                         (sqrt (+ t_1 (* ky ky))))
                        (sin th))
                       (if (<= t_2 0.998)
                         (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
                         (sin th)))))))
              double code(double kx, double ky, double th) {
              	double t_1 = pow(sin(kx), 2.0);
              	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
              	double tmp;
              	if (t_2 <= -1.0) {
              		tmp = sqrt(pow((1.0 - cos((-2.0 * ky))), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
              	} else if (t_2 <= -0.1) {
              		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
              	} else if (t_2 <= 0.0002) {
              		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
              	} else if (t_2 <= 0.998) {
              		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
              	} else {
              		tmp = sin(th);
              	}
              	return tmp;
              }
              
              function code(kx, ky, th)
              	t_1 = sin(kx) ^ 2.0
              	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
              	tmp = 0.0
              	if (t_2 <= -1.0)
              		tmp = Float64(sqrt((Float64(1.0 - cos(Float64(-2.0 * ky))) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
              	elseif (t_2 <= -0.1)
              		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
              	elseif (t_2 <= 0.0002)
              		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
              	elseif (t_2 <= 0.998)
              		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
              	else
              		tmp = sin(th);
              	end
              	return tmp
              end
              
              code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.1], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_1 := {\sin kx}^{2}\\
              t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
              \mathbf{if}\;t\_2 \leq -1:\\
              \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
              
              \mathbf{elif}\;t\_2 \leq -0.1:\\
              \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
              
              \mathbf{elif}\;t\_2 \leq 0.0002:\\
              \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
              
              \mathbf{elif}\;t\_2 \leq 0.998:\\
              \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
              
              \mathbf{else}:\\
              \;\;\;\;\sin th\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 5 regimes
              2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

                1. Initial program 82.4%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. Add Preprocessing
                3. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                  2. lift-/.f64N/A

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

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

                    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  5. *-commutativeN/A

                    \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                  6. lower-*.f64N/A

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

                    \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                  8. lift-sqrt.f64N/A

                    \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                  9. lift-+.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                  10. +-commutativeN/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                  11. lift-pow.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                  12. unpow2N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                  13. lift-pow.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                  14. unpow2N/A

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

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

                  \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                5. Step-by-step derivation
                  1. lift-hypot.f64N/A

                    \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                  2. lift-sin.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                  3. lift-sin.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                  4. sin-multN/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                  5. lift-sin.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                  6. lift-sin.f64N/A

                    \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                  7. sin-multN/A

                    \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                  8. div-add-revN/A

                    \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                  9. sqrt-divN/A

                    \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                  10. lower-/.f64N/A

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

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

                  \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
                8. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                  2. lower-*.f64N/A

                    \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                  3. lower-sqrt.f64N/A

                    \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  4. lower-/.f64N/A

                    \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  5. lower--.f64N/A

                    \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  6. cos-neg-revN/A

                    \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  7. lower-cos.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  8. distribute-lft-neg-inN/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  9. metadata-evalN/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  10. lower-*.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                  11. *-commutativeN/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                  12. lower-*.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                  13. *-commutativeN/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                  14. lower-*.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                  15. lower-sqrt.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                  16. lower-sin.f64N/A

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                  17. lower-sin.f6462.1

                    \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
                9. Applied rewrites62.1%

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

                if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

                1. Initial program 99.3%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. Add Preprocessing
                3. Step-by-step derivation
                  1. lift-sqrt.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  2. lift-+.f64N/A

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                  4. lift-pow.f64N/A

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                  6. lift-pow.f64N/A

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                  8. lower-hypot.f6499.2

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

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

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
                6. Step-by-step derivation
                  1. *-commutativeN/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                  2. lower-*.f64N/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                  3. +-commutativeN/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                  4. *-commutativeN/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                  5. lower-fma.f64N/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                  6. unpow2N/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  7. lower-*.f6450.3

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

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
                8. Step-by-step derivation
                  1. lift-hypot.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  2. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  3. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  4. sin-multN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  5. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  6. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  7. sin-multN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  8. frac-addN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  9. metadata-evalN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  10. metadata-evalN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  11. sqrt-divN/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  12. metadata-evalN/A

                    \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  13. metadata-evalN/A

                    \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  14. lower-/.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                9. Applied rewrites50.4%

                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

                if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

                1. Initial program 99.6%

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

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                4. Step-by-step derivation
                  1. unpow2N/A

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

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

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                6. Taylor expanded in ky around 0

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

                    \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  2. lower-*.f64N/A

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

                    \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  4. *-commutativeN/A

                    \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  5. lower-fma.f64N/A

                    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  6. unpow2N/A

                    \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  7. lower-*.f6498.6

                    \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                8. Applied rewrites98.6%

                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

                if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                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 th around 0

                  \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                4. Step-by-step derivation
                  1. lower-*.f64N/A

                    \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  2. *-commutativeN/A

                    \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                  3. lower-*.f64N/A

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

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

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  6. lower-/.f64N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  7. unpow2N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
                  8. lower-fma.f64N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
                  9. lower-sin.f64N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
                  10. lower-sin.f64N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
                  11. lower-pow.f64N/A

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
                  12. lower-sin.f6450.1

                    \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
                5. Applied rewrites50.1%

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

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

                  if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                  1. Initial program 97.8%

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

                    \[\leadsto \color{blue}{\sin th} \]
                  4. Step-by-step derivation
                    1. lower-sin.f6498.5

                      \[\leadsto \color{blue}{\sin th} \]
                  5. Applied rewrites98.5%

                    \[\leadsto \color{blue}{\sin th} \]
                7. Recombined 5 regimes into one program.
                8. Final simplification77.9%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                9. Add Preprocessing

                Alternative 12: 77.6% accurate, 0.2× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_2 \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.998:\\ \;\;\;\;\frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                (FPCore (kx ky th)
                 :precision binary64
                 (let* ((t_1 (pow (sin kx) 2.0))
                        (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                   (if (<= t_2 -1.0)
                     (*
                      (sqrt (pow (- 1.0 (cos (* -2.0 ky))) -1.0))
                      (* (* (sqrt 2.0) (sin th)) (sin ky)))
                     (if (<= t_2 -0.1)
                       (*
                        (/
                         (sin ky)
                         (/
                          (sqrt
                           (fma
                            (- 1.0 (cos (* 2.0 ky)))
                            2.0
                            (* 2.0 (- 1.0 (cos (* -2.0 kx))))))
                          2.0))
                        (* (fma (* th th) -0.16666666666666666 1.0) th))
                       (if (<= t_2 0.0002)
                         (*
                          (/
                           (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                           (sqrt (+ t_1 (* ky ky))))
                          (sin th))
                         (if (<= t_2 0.998)
                           (* (/ th (hypot (sin kx) (sin ky))) (sin ky))
                           (sin th)))))))
                double code(double kx, double ky, double th) {
                	double t_1 = pow(sin(kx), 2.0);
                	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
                	double tmp;
                	if (t_2 <= -1.0) {
                		tmp = sqrt(pow((1.0 - cos((-2.0 * ky))), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
                	} else if (t_2 <= -0.1) {
                		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((-2.0 * kx)))))) / 2.0)) * (fma((th * th), -0.16666666666666666, 1.0) * th);
                	} else if (t_2 <= 0.0002) {
                		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
                	} else if (t_2 <= 0.998) {
                		tmp = (th / hypot(sin(kx), sin(ky))) * sin(ky);
                	} else {
                		tmp = sin(th);
                	}
                	return tmp;
                }
                
                function code(kx, ky, th)
                	t_1 = sin(kx) ^ 2.0
                	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
                	tmp = 0.0
                	if (t_2 <= -1.0)
                		tmp = Float64(sqrt((Float64(1.0 - cos(Float64(-2.0 * ky))) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
                	elseif (t_2 <= -0.1)
                		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(-2.0 * kx)))))) / 2.0)) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
                	elseif (t_2 <= 0.0002)
                		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
                	elseif (t_2 <= 0.998)
                		tmp = Float64(Float64(th / hypot(sin(kx), sin(ky))) * sin(ky));
                	else
                		tmp = sin(th);
                	end
                	return tmp
                end
                
                code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.1], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0002], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.998], N[(N[(th / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                t_1 := {\sin kx}^{2}\\
                t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
                \mathbf{if}\;t\_2 \leq -1:\\
                \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
                
                \mathbf{elif}\;t\_2 \leq -0.1:\\
                \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
                
                \mathbf{elif}\;t\_2 \leq 0.0002:\\
                \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
                
                \mathbf{elif}\;t\_2 \leq 0.998:\\
                \;\;\;\;\frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\\
                
                \mathbf{else}:\\
                \;\;\;\;\sin th\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 5 regimes
                2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

                  1. Initial program 82.4%

                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift-*.f64N/A

                      \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                    2. lift-/.f64N/A

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

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

                      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                    5. *-commutativeN/A

                      \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                    6. lower-*.f64N/A

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

                      \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                    8. lift-sqrt.f64N/A

                      \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                    9. lift-+.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                    10. +-commutativeN/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                    11. lift-pow.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                    12. unpow2N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                    13. lift-pow.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                    14. unpow2N/A

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

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

                    \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                  5. Step-by-step derivation
                    1. lift-hypot.f64N/A

                      \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                    2. lift-sin.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                    3. lift-sin.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                    4. sin-multN/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                    5. lift-sin.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                    6. lift-sin.f64N/A

                      \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                    7. sin-multN/A

                      \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                    8. div-add-revN/A

                      \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                    9. sqrt-divN/A

                      \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                    10. lower-/.f64N/A

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

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

                    \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
                  8. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                    2. lower-*.f64N/A

                      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                    3. lower-sqrt.f64N/A

                      \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    4. lower-/.f64N/A

                      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    5. lower--.f64N/A

                      \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    6. cos-neg-revN/A

                      \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    7. lower-cos.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    8. distribute-lft-neg-inN/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    9. metadata-evalN/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    10. lower-*.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                    11. *-commutativeN/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                    12. lower-*.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                    13. *-commutativeN/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                    14. lower-*.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                    15. lower-sqrt.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                    16. lower-sin.f64N/A

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                    17. lower-sin.f6462.1

                      \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
                  9. Applied rewrites62.1%

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

                  if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.10000000000000001

                  1. Initial program 99.3%

                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift-sqrt.f64N/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                    2. lift-+.f64N/A

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                    4. lift-pow.f64N/A

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                    6. lift-pow.f64N/A

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                    8. lower-hypot.f6499.2

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

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

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
                  6. Step-by-step derivation
                    1. *-commutativeN/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                    2. lower-*.f64N/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                    3. +-commutativeN/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                    4. *-commutativeN/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                    5. lower-fma.f64N/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                    6. unpow2N/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    7. lower-*.f6450.3

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

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
                  8. Step-by-step derivation
                    1. lift-hypot.f64N/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    2. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    3. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    4. sin-multN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    5. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    6. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    7. sin-multN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    8. frac-addN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    9. metadata-evalN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    10. metadata-evalN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    11. sqrt-divN/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    12. metadata-evalN/A

                      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    13. metadata-evalN/A

                      \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    14. lower-/.f64N/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                  9. Applied rewrites50.4%

                    \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]

                  if -0.10000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

                  1. Initial program 99.6%

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

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                  4. Step-by-step derivation
                    1. unpow2N/A

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                  6. Taylor expanded in ky around 0

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

                      \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    2. lower-*.f64N/A

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

                      \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    4. *-commutativeN/A

                      \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    5. lower-fma.f64N/A

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    6. unpow2N/A

                      \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    7. lower-*.f6498.6

                      \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                  8. Applied rewrites98.6%

                    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

                  if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                  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 th around 0

                    \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  4. Step-by-step derivation
                    1. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                    2. *-commutativeN/A

                      \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                    3. lower-*.f64N/A

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

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

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                    6. lower-/.f64N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                    7. unpow2N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
                    8. lower-fma.f64N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
                    9. lower-sin.f64N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
                    10. lower-sin.f64N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
                    11. lower-pow.f64N/A

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
                    12. lower-sin.f6450.1

                      \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
                  5. Applied rewrites50.1%

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

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

                    if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 97.8%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6498.5

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites98.5%

                      \[\leadsto \color{blue}{\sin th} \]
                  7. Recombined 5 regimes into one program.
                  8. Final simplification77.9%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.1:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(-2 \cdot kx\right)\right)\right)}}{2}} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.998:\\ \;\;\;\;\frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  9. Add Preprocessing

                  Alternative 13: 68.3% accurate, 0.3× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;t\_2 \leq -0.05:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (let* ((t_1 (pow (sin kx) 2.0))
                          (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                     (if (<= t_2 -1.0)
                       (*
                        (/
                         (sin ky)
                         (hypot (sin ky) (* (fma -0.16666666666666666 (* kx kx) 1.0) kx)))
                        (* (fma (* th th) -0.16666666666666666 1.0) th))
                       (if (<= t_2 -0.05)
                         (* (/ (sin ky) (sqrt (- 0.5 (* (cos (* -2.0 kx)) 0.5)))) (sin th))
                         (if (<= t_2 0.005)
                           (*
                            (/
                             (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                             (sqrt (+ t_1 (* ky ky))))
                            (sin th))
                           (sin th))))))
                  double code(double kx, double ky, double th) {
                  	double t_1 = pow(sin(kx), 2.0);
                  	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
                  	double tmp;
                  	if (t_2 <= -1.0) {
                  		tmp = (sin(ky) / hypot(sin(ky), (fma(-0.16666666666666666, (kx * kx), 1.0) * kx))) * (fma((th * th), -0.16666666666666666, 1.0) * th);
                  	} else if (t_2 <= -0.05) {
                  		tmp = (sin(ky) / sqrt((0.5 - (cos((-2.0 * kx)) * 0.5)))) * sin(th);
                  	} else if (t_2 <= 0.005) {
                  		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  function code(kx, ky, th)
                  	t_1 = sin(kx) ^ 2.0
                  	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
                  	tmp = 0.0
                  	if (t_2 <= -1.0)
                  		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), Float64(fma(-0.16666666666666666, Float64(kx * kx), 1.0) * kx))) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
                  	elseif (t_2 <= -0.05)
                  		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(cos(Float64(-2.0 * kx)) * 0.5)))) * sin(th));
                  	elseif (t_2 <= 0.005)
                  		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1.0], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[(N[(-0.16666666666666666 * N[(kx * kx), $MachinePrecision] + 1.0), $MachinePrecision] * kx), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.05], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.005], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_1 := {\sin kx}^{2}\\
                  t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
                  \mathbf{if}\;t\_2 \leq -1:\\
                  \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
                  
                  \mathbf{elif}\;t\_2 \leq -0.05:\\
                  \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\
                  
                  \mathbf{elif}\;t\_2 \leq 0.005:\\
                  \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 4 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -1

                    1. Initial program 82.4%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. Add Preprocessing
                    3. Step-by-step derivation
                      1. lift-sqrt.f64N/A

                        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                      2. lift-+.f64N/A

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                      4. lift-pow.f64N/A

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                      6. lift-pow.f64N/A

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                      8. lower-hypot.f6499.9

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

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

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
                    6. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                      2. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                      3. +-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                      4. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                      5. lower-fma.f64N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                      6. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      7. lower-*.f6453.0

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, -0.16666666666666666, 1\right) \cdot th\right) \]
                    7. Applied rewrites53.0%

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

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(1 + \frac{-1}{6} \cdot {kx}^{2}\right)}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                    9. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(1 + \frac{-1}{6} \cdot {kx}^{2}\right) \cdot kx}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      2. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(1 + \frac{-1}{6} \cdot {kx}^{2}\right) \cdot kx}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      3. +-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(\frac{-1}{6} \cdot {kx}^{2} + 1\right)} \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      4. lower-fma.f64N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {kx}^{2}, 1\right)} \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      5. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{kx \cdot kx}, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                      6. lower-*.f6453.0

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, \color{blue}{kx \cdot kx}, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]
                    10. Applied rewrites53.0%

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

                    if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.050000000000000003

                    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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f649.2

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Step-by-step derivation
                      1. lift-pow.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                      2. pow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                      3. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                      4. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                      5. sqr-sin-aN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      6. lower--.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      7. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      8. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      9. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      10. lower-cos.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      11. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      12. lower-*.f648.7

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                    8. Taylor expanded in ky around 0

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                    9. Step-by-step derivation
                      1. lower-sqrt.f64N/A

                        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                      2. lower--.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                      3. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \sin th \]
                      4. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \sin th \]
                      5. cos-neg-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                      6. lower-cos.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                      7. distribute-lft-neg-inN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                      8. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                      9. metadata-eval21.1

                        \[\leadsto \frac{\sin ky}{\sqrt{0.5 - \cos \left(\color{blue}{-2} \cdot kx\right) \cdot 0.5}} \cdot \sin th \]
                    10. Applied rewrites21.1%

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}}} \cdot \sin th \]

                    if -0.050000000000000003 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.0050000000000000001

                    1. Initial program 99.6%

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f6499.4

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Taylor expanded in ky around 0

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

                        \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      2. lower-*.f64N/A

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

                        \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      4. *-commutativeN/A

                        \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      5. lower-fma.f64N/A

                        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      6. unpow2N/A

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      7. lower-*.f6499.4

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    8. Applied rewrites99.4%

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

                    if 0.0050000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.6

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.6%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -1:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.05:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 14: 70.7% accurate, 0.4× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -0.05:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;t\_2 \leq 0.005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (let* ((t_1 (pow (sin kx) 2.0))
                          (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                     (if (<= t_2 -0.05)
                       (*
                        (sqrt (pow (- 1.0 (cos (* -2.0 ky))) -1.0))
                        (* (* (sqrt 2.0) (sin th)) (sin ky)))
                       (if (<= t_2 0.005)
                         (*
                          (/
                           (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                           (sqrt (+ t_1 (* ky ky))))
                          (sin th))
                         (sin th)))))
                  double code(double kx, double ky, double th) {
                  	double t_1 = pow(sin(kx), 2.0);
                  	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
                  	double tmp;
                  	if (t_2 <= -0.05) {
                  		tmp = sqrt(pow((1.0 - cos((-2.0 * ky))), -1.0)) * ((sqrt(2.0) * sin(th)) * sin(ky));
                  	} else if (t_2 <= 0.005) {
                  		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt((t_1 + (ky * ky)))) * sin(th);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  function code(kx, ky, th)
                  	t_1 = sin(kx) ^ 2.0
                  	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
                  	tmp = 0.0
                  	if (t_2 <= -0.05)
                  		tmp = Float64(sqrt((Float64(1.0 - cos(Float64(-2.0 * ky))) ^ -1.0)) * Float64(Float64(sqrt(2.0) * sin(th)) * sin(ky)));
                  	elseif (t_2 <= 0.005)
                  		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(t_1 + Float64(ky * ky)))) * sin(th));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.05], N[(N[Sqrt[N[Power[N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.005], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_1 := {\sin kx}^{2}\\
                  t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
                  \mathbf{if}\;t\_2 \leq -0.05:\\
                  \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\
                  
                  \mathbf{elif}\;t\_2 \leq 0.005:\\
                  \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{t\_1 + ky \cdot ky}} \cdot \sin th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.050000000000000003

                    1. Initial program 89.5%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. Add Preprocessing
                    3. Step-by-step derivation
                      1. lift-*.f64N/A

                        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                      2. lift-/.f64N/A

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

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

                        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                      5. *-commutativeN/A

                        \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                      6. lower-*.f64N/A

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

                        \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                      8. lift-sqrt.f64N/A

                        \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                      9. lift-+.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                      10. +-commutativeN/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                      11. lift-pow.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                      12. unpow2N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                      13. lift-pow.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                      14. unpow2N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin ky \]
                      15. lower-hypot.f6499.4

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

                      \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                    5. Step-by-step derivation
                      1. lift-hypot.f64N/A

                        \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                      2. lift-sin.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                      3. lift-sin.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                      4. sin-multN/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                      5. lift-sin.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                      6. lift-sin.f64N/A

                        \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                      7. sin-multN/A

                        \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                      8. div-add-revN/A

                        \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                      9. sqrt-divN/A

                        \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                      10. lower-/.f64N/A

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

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

                      \[\leadsto \color{blue}{\left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \]
                    8. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                      2. lower-*.f64N/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right)} \]
                      3. lower-sqrt.f64N/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      4. lower-/.f64N/A

                        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      5. lower--.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\color{blue}{1 - \cos \left(2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      6. cos-neg-revN/A

                        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      7. lower-cos.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot ky\right)\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      8. distribute-lft-neg-inN/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      9. metadata-evalN/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(\color{blue}{-2} \cdot ky\right)}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      10. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \color{blue}{\left(-2 \cdot ky\right)}}} \cdot \left(\sin ky \cdot \left(\sin th \cdot \sqrt{2}\right)\right) \]
                      11. *-commutativeN/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                      12. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \color{blue}{\left(\left(\sin th \cdot \sqrt{2}\right) \cdot \sin ky\right)} \]
                      13. *-commutativeN/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                      14. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\color{blue}{\left(\sqrt{2} \cdot \sin th\right)} \cdot \sin ky\right) \]
                      15. lower-sqrt.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\color{blue}{\sqrt{2}} \cdot \sin th\right) \cdot \sin ky\right) \]
                      16. lower-sin.f64N/A

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \color{blue}{\sin th}\right) \cdot \sin ky\right) \]
                      17. lower-sin.f6444.4

                        \[\leadsto \sqrt{\frac{1}{1 - \cos \left(-2 \cdot ky\right)}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \color{blue}{\sin ky}\right) \]
                    9. Applied rewrites44.4%

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

                    if -0.050000000000000003 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.0050000000000000001

                    1. Initial program 99.6%

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f6499.4

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Taylor expanded in ky around 0

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

                        \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      2. lower-*.f64N/A

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

                        \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      4. *-commutativeN/A

                        \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      5. lower-fma.f64N/A

                        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      6. unpow2N/A

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                      7. lower-*.f6499.4

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]
                    8. Applied rewrites99.4%

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th \]

                    if 0.0050000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.6

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.6%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.05:\\ \;\;\;\;\sqrt{{\left(1 - \cos \left(-2 \cdot ky\right)\right)}^{-1}} \cdot \left(\left(\sqrt{2} \cdot \sin th\right) \cdot \sin ky\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{{\sin kx}^{2} + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 15: 45.4% accurate, 0.5× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-125}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.005:\\ \;\;\;\;\left(\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot ky\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                     (if (<= t_1 5e-125)
                       (* (/ ky (sin kx)) (sin th))
                       (if (<= t_1 0.005)
                         (* (* (sqrt (pow (- 0.5 (* (cos (* -2.0 kx)) 0.5)) -1.0)) ky) (sin th))
                         (sin th)))))
                  double code(double kx, double ky, double th) {
                  	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                  	double tmp;
                  	if (t_1 <= 5e-125) {
                  		tmp = (ky / sin(kx)) * sin(th);
                  	} else if (t_1 <= 0.005) {
                  		tmp = (sqrt(pow((0.5 - (cos((-2.0 * kx)) * 0.5)), -1.0)) * ky) * sin(th);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(kx, ky, th)
                      real(8), intent (in) :: kx
                      real(8), intent (in) :: ky
                      real(8), intent (in) :: th
                      real(8) :: t_1
                      real(8) :: tmp
                      t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                      if (t_1 <= 5d-125) then
                          tmp = (ky / sin(kx)) * sin(th)
                      else if (t_1 <= 0.005d0) then
                          tmp = (sqrt(((0.5d0 - (cos(((-2.0d0) * kx)) * 0.5d0)) ** (-1.0d0))) * ky) * sin(th)
                      else
                          tmp = sin(th)
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double kx, double ky, double th) {
                  	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                  	double tmp;
                  	if (t_1 <= 5e-125) {
                  		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                  	} else if (t_1 <= 0.005) {
                  		tmp = (Math.sqrt(Math.pow((0.5 - (Math.cos((-2.0 * kx)) * 0.5)), -1.0)) * ky) * Math.sin(th);
                  	} else {
                  		tmp = Math.sin(th);
                  	}
                  	return tmp;
                  }
                  
                  def code(kx, ky, th):
                  	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                  	tmp = 0
                  	if t_1 <= 5e-125:
                  		tmp = (ky / math.sin(kx)) * math.sin(th)
                  	elif t_1 <= 0.005:
                  		tmp = (math.sqrt(math.pow((0.5 - (math.cos((-2.0 * kx)) * 0.5)), -1.0)) * ky) * math.sin(th)
                  	else:
                  		tmp = math.sin(th)
                  	return tmp
                  
                  function code(kx, ky, th)
                  	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                  	tmp = 0.0
                  	if (t_1 <= 5e-125)
                  		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                  	elseif (t_1 <= 0.005)
                  		tmp = Float64(Float64(sqrt((Float64(0.5 - Float64(cos(Float64(-2.0 * kx)) * 0.5)) ^ -1.0)) * ky) * sin(th));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(kx, ky, th)
                  	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                  	tmp = 0.0;
                  	if (t_1 <= 5e-125)
                  		tmp = (ky / sin(kx)) * sin(th);
                  	elseif (t_1 <= 0.005)
                  		tmp = (sqrt(((0.5 - (cos((-2.0 * kx)) * 0.5)) ^ -1.0)) * ky) * sin(th);
                  	else
                  		tmp = sin(th);
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[kx_, ky_, th_] := Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, 5e-125], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.005], N[(N[(N[Sqrt[N[Power[N[(0.5 - N[(N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * ky), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                  \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-125}:\\
                  \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                  
                  \mathbf{elif}\;t\_1 \leq 0.005:\\
                  \;\;\;\;\left(\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot ky\right) \cdot \sin th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 4.99999999999999967e-125

                    1. Initial program 94.2%

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

                      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. lower-/.f64N/A

                        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                      2. lower-sin.f6430.9

                        \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                    5. Applied rewrites30.9%

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

                    if 4.99999999999999967e-125 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.0050000000000000001

                    1. Initial program 99.4%

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f6498.4

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Step-by-step derivation
                      1. lift-pow.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                      2. pow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                      3. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                      4. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                      5. sqr-sin-aN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      6. lower--.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      7. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      8. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      9. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      10. lower-cos.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      11. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      12. lower-*.f6480.8

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                    8. Taylor expanded in ky around 0

                      \[\leadsto \color{blue}{\left(ky \cdot \sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}\right)} \cdot \sin th \]
                    9. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}} \cdot ky\right)} \cdot \sin th \]
                      2. lower-*.f64N/A

                        \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}} \cdot ky\right)} \cdot \sin th \]
                      3. lower-sqrt.f64N/A

                        \[\leadsto \left(\color{blue}{\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot ky\right) \cdot \sin th \]
                      4. lower-/.f64N/A

                        \[\leadsto \left(\sqrt{\color{blue}{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot ky\right) \cdot \sin th \]
                      5. lower--.f64N/A

                        \[\leadsto \left(\sqrt{\frac{1}{\color{blue}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot ky\right) \cdot \sin th \]
                      6. *-commutativeN/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot ky\right) \cdot \sin th \]
                      7. lower-*.f64N/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot ky\right) \cdot \sin th \]
                      8. cos-neg-revN/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot ky\right) \cdot \sin th \]
                      9. lower-cos.f64N/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot ky\right) \cdot \sin th \]
                      10. distribute-lft-neg-inN/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot ky\right) \cdot \sin th \]
                      11. lower-*.f64N/A

                        \[\leadsto \left(\sqrt{\frac{1}{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot ky\right) \cdot \sin th \]
                      12. metadata-eval73.4

                        \[\leadsto \left(\sqrt{\frac{1}{0.5 - \cos \left(\color{blue}{-2} \cdot kx\right) \cdot 0.5}} \cdot ky\right) \cdot \sin th \]
                    10. Applied rewrites73.4%

                      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot ky\right)} \cdot \sin th \]

                    if 0.0050000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.6

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.6%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-125}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\left(\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot ky\right) \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 16: 45.2% accurate, 0.5× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 2 \cdot 10^{-107}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.005:\\ \;\;\;\;\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot \left(\sin th \cdot ky\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                     (if (<= t_1 2e-107)
                       (* (/ ky (sin kx)) (sin th))
                       (if (<= t_1 0.005)
                         (* (sqrt (pow (- 0.5 (* (cos (* -2.0 kx)) 0.5)) -1.0)) (* (sin th) ky))
                         (sin th)))))
                  double code(double kx, double ky, double th) {
                  	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                  	double tmp;
                  	if (t_1 <= 2e-107) {
                  		tmp = (ky / sin(kx)) * sin(th);
                  	} else if (t_1 <= 0.005) {
                  		tmp = sqrt(pow((0.5 - (cos((-2.0 * kx)) * 0.5)), -1.0)) * (sin(th) * ky);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(kx, ky, th)
                      real(8), intent (in) :: kx
                      real(8), intent (in) :: ky
                      real(8), intent (in) :: th
                      real(8) :: t_1
                      real(8) :: tmp
                      t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                      if (t_1 <= 2d-107) then
                          tmp = (ky / sin(kx)) * sin(th)
                      else if (t_1 <= 0.005d0) then
                          tmp = sqrt(((0.5d0 - (cos(((-2.0d0) * kx)) * 0.5d0)) ** (-1.0d0))) * (sin(th) * ky)
                      else
                          tmp = sin(th)
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double kx, double ky, double th) {
                  	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                  	double tmp;
                  	if (t_1 <= 2e-107) {
                  		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                  	} else if (t_1 <= 0.005) {
                  		tmp = Math.sqrt(Math.pow((0.5 - (Math.cos((-2.0 * kx)) * 0.5)), -1.0)) * (Math.sin(th) * ky);
                  	} else {
                  		tmp = Math.sin(th);
                  	}
                  	return tmp;
                  }
                  
                  def code(kx, ky, th):
                  	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                  	tmp = 0
                  	if t_1 <= 2e-107:
                  		tmp = (ky / math.sin(kx)) * math.sin(th)
                  	elif t_1 <= 0.005:
                  		tmp = math.sqrt(math.pow((0.5 - (math.cos((-2.0 * kx)) * 0.5)), -1.0)) * (math.sin(th) * ky)
                  	else:
                  		tmp = math.sin(th)
                  	return tmp
                  
                  function code(kx, ky, th)
                  	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                  	tmp = 0.0
                  	if (t_1 <= 2e-107)
                  		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                  	elseif (t_1 <= 0.005)
                  		tmp = Float64(sqrt((Float64(0.5 - Float64(cos(Float64(-2.0 * kx)) * 0.5)) ^ -1.0)) * Float64(sin(th) * ky));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(kx, ky, th)
                  	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                  	tmp = 0.0;
                  	if (t_1 <= 2e-107)
                  		tmp = (ky / sin(kx)) * sin(th);
                  	elseif (t_1 <= 0.005)
                  		tmp = sqrt(((0.5 - (cos((-2.0 * kx)) * 0.5)) ^ -1.0)) * (sin(th) * ky);
                  	else
                  		tmp = sin(th);
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[kx_, ky_, th_] := Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, 2e-107], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.005], N[(N[Sqrt[N[Power[N[(0.5 - N[(N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                  \mathbf{if}\;t\_1 \leq 2 \cdot 10^{-107}:\\
                  \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                  
                  \mathbf{elif}\;t\_1 \leq 0.005:\\
                  \;\;\;\;\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot \left(\sin th \cdot ky\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 3 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2e-107

                    1. Initial program 94.2%

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

                      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. lower-/.f64N/A

                        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                      2. lower-sin.f6430.8

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

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

                    if 2e-107 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.0050000000000000001

                    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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f6498.4

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Step-by-step derivation
                      1. lift-pow.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                      2. pow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                      3. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                      4. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                      5. sqr-sin-aN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      6. lower--.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                      7. *-commutativeN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      8. lower-*.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                      9. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      10. lower-cos.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      11. count-2-revN/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                      12. lower-*.f6485.8

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

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                    8. Taylor expanded in ky around 0

                      \[\leadsto \color{blue}{\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \]
                    9. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \sin th\right)} \]
                      2. lower-*.f64N/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}} \cdot \left(ky \cdot \sin th\right)} \]
                      3. lower-sqrt.f64N/A

                        \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \sin th\right) \]
                      4. lower-/.f64N/A

                        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \sin th\right) \]
                      5. lower--.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\color{blue}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \left(ky \cdot \sin th\right) \]
                      6. *-commutativeN/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \left(ky \cdot \sin th\right) \]
                      7. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \left(ky \cdot \sin th\right) \]
                      8. cos-neg-revN/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \left(ky \cdot \sin th\right) \]
                      9. lower-cos.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \left(ky \cdot \sin th\right) \]
                      10. distribute-lft-neg-inN/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \left(ky \cdot \sin th\right) \]
                      11. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \left(ky \cdot \sin th\right) \]
                      12. metadata-evalN/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \cos \left(\color{blue}{-2} \cdot kx\right) \cdot \frac{1}{2}}} \cdot \left(ky \cdot \sin th\right) \]
                      13. *-commutativeN/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \cos \left(-2 \cdot kx\right) \cdot \frac{1}{2}}} \cdot \color{blue}{\left(\sin th \cdot ky\right)} \]
                      14. lower-*.f64N/A

                        \[\leadsto \sqrt{\frac{1}{\frac{1}{2} - \cos \left(-2 \cdot kx\right) \cdot \frac{1}{2}}} \cdot \color{blue}{\left(\sin th \cdot ky\right)} \]
                      15. lower-sin.f6477.9

                        \[\leadsto \sqrt{\frac{1}{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \left(\color{blue}{\sin th} \cdot ky\right) \]
                    10. Applied rewrites77.9%

                      \[\leadsto \color{blue}{\sqrt{\frac{1}{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \left(\sin th \cdot ky\right)} \]

                    if 0.0050000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.6

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.6%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-107}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.005:\\ \;\;\;\;\sqrt{{\left(0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5\right)}^{-1}} \cdot \left(\sin th \cdot ky\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 17: 44.8% accurate, 0.8× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.0002)
                     (* (/ ky (sin kx)) (sin th))
                     (sin th)))
                  double code(double kx, double ky, double th) {
                  	double tmp;
                  	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.0002) {
                  		tmp = (ky / sin(kx)) * sin(th);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(kx, ky, th)
                      real(8), intent (in) :: kx
                      real(8), intent (in) :: ky
                      real(8), intent (in) :: th
                      real(8) :: tmp
                      if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.0002d0) then
                          tmp = (ky / sin(kx)) * sin(th)
                      else
                          tmp = sin(th)
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double kx, double ky, double th) {
                  	double tmp;
                  	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.0002) {
                  		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                  	} else {
                  		tmp = Math.sin(th);
                  	}
                  	return tmp;
                  }
                  
                  def code(kx, ky, th):
                  	tmp = 0
                  	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.0002:
                  		tmp = (ky / math.sin(kx)) * math.sin(th)
                  	else:
                  		tmp = math.sin(th)
                  	return tmp
                  
                  function code(kx, ky, th)
                  	tmp = 0.0
                  	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.0002)
                  		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(kx, ky, th)
                  	tmp = 0.0;
                  	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.0002)
                  		tmp = (ky / sin(kx)) * sin(th);
                  	else
                  		tmp = sin(th);
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[kx_, ky_, th_] := If[LessEqual[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], 0.0002], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\
                  \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

                    1. Initial program 94.6%

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

                      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. lower-/.f64N/A

                        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                      2. lower-sin.f6432.7

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

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

                    if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.0

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.0%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 18: 44.2% accurate, 0.8× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 0.0002)
                     (/ (* (sin th) ky) (sin kx))
                     (sin th)))
                  double code(double kx, double ky, double th) {
                  	double tmp;
                  	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 0.0002) {
                  		tmp = (sin(th) * ky) / sin(kx);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  real(8) function code(kx, ky, th)
                      real(8), intent (in) :: kx
                      real(8), intent (in) :: ky
                      real(8), intent (in) :: th
                      real(8) :: tmp
                      if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.0002d0) then
                          tmp = (sin(th) * ky) / sin(kx)
                      else
                          tmp = sin(th)
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double kx, double ky, double th) {
                  	double tmp;
                  	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.0002) {
                  		tmp = (Math.sin(th) * ky) / Math.sin(kx);
                  	} else {
                  		tmp = Math.sin(th);
                  	}
                  	return tmp;
                  }
                  
                  def code(kx, ky, th):
                  	tmp = 0
                  	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 0.0002:
                  		tmp = (math.sin(th) * ky) / math.sin(kx)
                  	else:
                  		tmp = math.sin(th)
                  	return tmp
                  
                  function code(kx, ky, th)
                  	tmp = 0.0
                  	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.0002)
                  		tmp = Float64(Float64(sin(th) * ky) / sin(kx));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(kx, ky, th)
                  	tmp = 0.0;
                  	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 0.0002)
                  		tmp = (sin(th) * ky) / sin(kx);
                  	else
                  		tmp = sin(th);
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[kx_, ky_, th_] := If[LessEqual[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], 0.0002], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\
                  \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000001e-4

                    1. Initial program 94.6%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. Add Preprocessing
                    3. Step-by-step derivation
                      1. lift-sqrt.f64N/A

                        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                      2. lift-+.f64N/A

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                      4. lift-pow.f64N/A

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                      6. lift-pow.f64N/A

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

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

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

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

                      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                    6. Step-by-step derivation
                      1. lower-/.f64N/A

                        \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                      2. *-commutativeN/A

                        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{\sin kx} \]
                      3. lower-*.f64N/A

                        \[\leadsto \frac{\color{blue}{\sin th \cdot ky}}{\sin kx} \]
                      4. lower-sin.f64N/A

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

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

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

                    if 2.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.5%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6463.0

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites63.0%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.0002:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 19: 42.6% accurate, 0.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 2e-15)
                     (*
                      (/
                       (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                       (sqrt (+ (* kx kx) (* ky ky))))
                      (sin th))
                     (sin th)))
                  double code(double kx, double ky, double th) {
                  	double tmp;
                  	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 2e-15) {
                  		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(((kx * kx) + (ky * ky)))) * sin(th);
                  	} else {
                  		tmp = sin(th);
                  	}
                  	return tmp;
                  }
                  
                  function code(kx, ky, th)
                  	tmp = 0.0
                  	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-15)
                  		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(Float64(kx * kx) + Float64(ky * ky)))) * sin(th));
                  	else
                  		tmp = sin(th);
                  	end
                  	return tmp
                  end
                  
                  code[kx_, ky_, th_] := If[LessEqual[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], 2e-15], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-15}:\\
                  \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sin th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2.0000000000000002e-15

                    1. Initial program 94.6%

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                      2. lower-*.f6459.4

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

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                    6. Taylor expanded in kx around 0

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                    7. Step-by-step derivation
                      1. unpow2N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
                      2. lower-*.f6431.6

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

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

                      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                    10. Step-by-step derivation
                      1. *-commutativeN/A

                        \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                      2. lower-*.f64N/A

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

                        \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                      4. *-commutativeN/A

                        \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                      5. lower-fma.f64N/A

                        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                      6. unpow2N/A

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                      7. lower-*.f6430.2

                        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th \]
                    11. Applied rewrites30.2%

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

                    if 2.0000000000000002e-15 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                    1. Initial program 98.6%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6461.8

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites61.8%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-15}:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                  5. Add Preprocessing

                  Alternative 20: 15.5% accurate, 0.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\\ \end{array} \end{array} \]
                  (FPCore (kx ky th)
                   :precision binary64
                   (if (<=
                        (*
                         (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))
                         (sin th))
                        0.0)
                     (* (* (* -0.16666666666666666 th) th) th)
                     (*
                      (fma
                       (- (* (* th th) 0.008333333333333333) 0.16666666666666666)
                       (* th th)
                       1.0)
                      th)))
                  double code(double kx, double ky, double th) {
                  	double tmp;
                  	if (((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th)) <= 0.0) {
                  		tmp = ((-0.16666666666666666 * th) * th) * th;
                  	} else {
                  		tmp = fma((((th * th) * 0.008333333333333333) - 0.16666666666666666), (th * th), 1.0) * th;
                  	}
                  	return tmp;
                  }
                  
                  function code(kx, ky, th)
                  	tmp = 0.0
                  	if (Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 0.0)
                  		tmp = Float64(Float64(Float64(-0.16666666666666666 * th) * th) * th);
                  	else
                  		tmp = Float64(fma(Float64(Float64(Float64(th * th) * 0.008333333333333333) - 0.16666666666666666), Float64(th * th), 1.0) * th);
                  	end
                  	return tmp
                  end
                  
                  code[kx_, ky_, th_] := If[LessEqual[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], 0.0], N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision], N[(N[(N[(N[(N[(th * th), $MachinePrecision] * 0.008333333333333333), $MachinePrecision] - 0.16666666666666666), $MachinePrecision] * N[(th * th), $MachinePrecision] + 1.0), $MachinePrecision] * th), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\
                  \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 0.0

                    1. Initial program 96.9%

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

                      \[\leadsto \color{blue}{\sin th} \]
                    4. Step-by-step derivation
                      1. lower-sin.f6422.3

                        \[\leadsto \color{blue}{\sin th} \]
                    5. Applied rewrites22.3%

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

                      \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                    7. Step-by-step derivation
                      1. Applied rewrites11.5%

                        \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                      2. Taylor expanded in th around inf

                        \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                      3. Step-by-step derivation
                        1. Applied rewrites12.3%

                          \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                        2. Step-by-step derivation
                          1. Applied rewrites12.3%

                            \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                          if 0.0 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th))

                          1. Initial program 94.7%

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

                            \[\leadsto \color{blue}{\sin th} \]
                          4. Step-by-step derivation
                            1. lower-sin.f6422.6

                              \[\leadsto \color{blue}{\sin th} \]
                          5. Applied rewrites22.6%

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

                            \[\leadsto th \cdot \color{blue}{\left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right)} \]
                          7. Step-by-step derivation
                            1. Applied rewrites13.9%

                              \[\leadsto \mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot \color{blue}{th} \]
                          8. Recombined 2 regimes into one program.
                          9. Final simplification13.0%

                            \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left(th \cdot th\right) \cdot 0.008333333333333333 - 0.16666666666666666, th \cdot th, 1\right) \cdot th\\ \end{array} \]
                          10. Add Preprocessing

                          Alternative 21: 15.6% accurate, 1.0× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.16666666666666666 \cdot th, th, 1\right) \cdot th\\ \end{array} \end{array} \]
                          (FPCore (kx ky th)
                           :precision binary64
                           (if (<=
                                (*
                                 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))
                                 (sin th))
                                0.0)
                             (* (* (* -0.16666666666666666 th) th) th)
                             (* (fma (* -0.16666666666666666 th) th 1.0) th)))
                          double code(double kx, double ky, double th) {
                          	double tmp;
                          	if (((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th)) <= 0.0) {
                          		tmp = ((-0.16666666666666666 * th) * th) * th;
                          	} else {
                          		tmp = fma((-0.16666666666666666 * th), th, 1.0) * th;
                          	}
                          	return tmp;
                          }
                          
                          function code(kx, ky, th)
                          	tmp = 0.0
                          	if (Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 0.0)
                          		tmp = Float64(Float64(Float64(-0.16666666666666666 * th) * th) * th);
                          	else
                          		tmp = Float64(fma(Float64(-0.16666666666666666 * th), th, 1.0) * th);
                          	end
                          	return tmp
                          end
                          
                          code[kx_, ky_, th_] := If[LessEqual[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], 0.0], N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th + 1.0), $MachinePrecision] * th), $MachinePrecision]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\
                          \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\mathsf{fma}\left(-0.16666666666666666 \cdot th, th, 1\right) \cdot th\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 0.0

                            1. Initial program 96.9%

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

                              \[\leadsto \color{blue}{\sin th} \]
                            4. Step-by-step derivation
                              1. lower-sin.f6422.3

                                \[\leadsto \color{blue}{\sin th} \]
                            5. Applied rewrites22.3%

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

                              \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                            7. Step-by-step derivation
                              1. Applied rewrites11.5%

                                \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                              2. Taylor expanded in th around inf

                                \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                              3. Step-by-step derivation
                                1. Applied rewrites12.3%

                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                2. Step-by-step derivation
                                  1. Applied rewrites12.3%

                                    \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                                  if 0.0 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th))

                                  1. Initial program 94.7%

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

                                    \[\leadsto \color{blue}{\sin th} \]
                                  4. Step-by-step derivation
                                    1. lower-sin.f6422.6

                                      \[\leadsto \color{blue}{\sin th} \]
                                  5. Applied rewrites22.6%

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

                                    \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites14.1%

                                      \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                    2. Step-by-step derivation
                                      1. Applied rewrites14.1%

                                        \[\leadsto \mathsf{fma}\left(-0.16666666666666666 \cdot th, th, 1\right) \cdot th \]
                                    3. Recombined 2 regimes into one program.
                                    4. Final simplification13.1%

                                      \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 0:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.16666666666666666 \cdot th, th, 1\right) \cdot th\\ \end{array} \]
                                    5. Add Preprocessing

                                    Alternative 22: 35.8% accurate, 1.0× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                    (FPCore (kx ky th)
                                     :precision binary64
                                     (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-6)
                                       (* ky (/ th (sin kx)))
                                       (sin th)))
                                    double code(double kx, double ky, double th) {
                                    	double tmp;
                                    	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-6) {
                                    		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) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 5d-6) 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) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 5e-6) {
                                    		tmp = ky * (th / Math.sin(kx));
                                    	} else {
                                    		tmp = Math.sin(th);
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(kx, ky, th):
                                    	tmp = 0
                                    	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 5e-6:
                                    		tmp = ky * (th / math.sin(kx))
                                    	else:
                                    		tmp = math.sin(th)
                                    	return tmp
                                    
                                    function code(kx, ky, th)
                                    	tmp = 0.0
                                    	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-6)
                                    		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) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-6)
                                    		tmp = ky * (th / sin(kx));
                                    	else
                                    		tmp = sin(th);
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[kx_, ky_, th_] := If[LessEqual[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], 5e-6], N[(ky * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-6}:\\
                                    \;\;\;\;ky \cdot \frac{th}{\sin kx}\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\sin th\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 2 regimes
                                    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.00000000000000041e-6

                                      1. Initial program 94.6%

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

                                        \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                      4. Step-by-step derivation
                                        1. lower-*.f64N/A

                                          \[\leadsto \color{blue}{\left(th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                        2. *-commutativeN/A

                                          \[\leadsto \color{blue}{\left(\sin ky \cdot th\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                                        3. lower-*.f64N/A

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

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

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                        6. lower-/.f64N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                        7. unpow2N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \]
                                        8. lower-fma.f64N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
                                        9. lower-sin.f64N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \]
                                        10. lower-sin.f64N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \]
                                        11. lower-pow.f64N/A

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \]
                                        12. lower-sin.f6443.4

                                          \[\leadsto \left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \]
                                      5. Applied rewrites43.4%

                                        \[\leadsto \color{blue}{\left(\sin ky \cdot th\right) \cdot \sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \]
                                      6. Taylor expanded in ky around 0

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

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

                                        if 5.00000000000000041e-6 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                        1. Initial program 98.6%

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

                                          \[\leadsto \color{blue}{\sin th} \]
                                        4. Step-by-step derivation
                                          1. lower-sin.f6462.4

                                            \[\leadsto \color{blue}{\sin th} \]
                                        5. Applied rewrites62.4%

                                          \[\leadsto \color{blue}{\sin th} \]
                                      8. Recombined 2 regimes into one program.
                                      9. Final simplification32.0%

                                        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                      10. Add Preprocessing

                                      Alternative 23: 31.1% accurate, 1.0× speedup?

                                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 6 \cdot 10^{-60}:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                      (FPCore (kx ky th)
                                       :precision binary64
                                       (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 6e-60)
                                         (* (* (* -0.16666666666666666 th) th) th)
                                         (sin th)))
                                      double code(double kx, double ky, double th) {
                                      	double tmp;
                                      	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 6e-60) {
                                      		tmp = ((-0.16666666666666666 * th) * th) * th;
                                      	} else {
                                      		tmp = sin(th);
                                      	}
                                      	return tmp;
                                      }
                                      
                                      real(8) function code(kx, ky, th)
                                          real(8), intent (in) :: kx
                                          real(8), intent (in) :: ky
                                          real(8), intent (in) :: th
                                          real(8) :: tmp
                                          if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 6d-60) then
                                              tmp = (((-0.16666666666666666d0) * th) * th) * th
                                          else
                                              tmp = sin(th)
                                          end if
                                          code = tmp
                                      end function
                                      
                                      public static double code(double kx, double ky, double th) {
                                      	double tmp;
                                      	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 6e-60) {
                                      		tmp = ((-0.16666666666666666 * th) * th) * th;
                                      	} else {
                                      		tmp = Math.sin(th);
                                      	}
                                      	return tmp;
                                      }
                                      
                                      def code(kx, ky, th):
                                      	tmp = 0
                                      	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 6e-60:
                                      		tmp = ((-0.16666666666666666 * th) * th) * th
                                      	else:
                                      		tmp = math.sin(th)
                                      	return tmp
                                      
                                      function code(kx, ky, th)
                                      	tmp = 0.0
                                      	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 6e-60)
                                      		tmp = Float64(Float64(Float64(-0.16666666666666666 * th) * th) * th);
                                      	else
                                      		tmp = sin(th);
                                      	end
                                      	return tmp
                                      end
                                      
                                      function tmp_2 = code(kx, ky, th)
                                      	tmp = 0.0;
                                      	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 6e-60)
                                      		tmp = ((-0.16666666666666666 * th) * th) * th;
                                      	else
                                      		tmp = sin(th);
                                      	end
                                      	tmp_2 = tmp;
                                      end
                                      
                                      code[kx_, ky_, th_] := If[LessEqual[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], 6e-60], N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      \begin{array}{l}
                                      \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 6 \cdot 10^{-60}:\\
                                      \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\sin th\\
                                      
                                      
                                      \end{array}
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 6.00000000000000038e-60

                                        1. Initial program 94.5%

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

                                          \[\leadsto \color{blue}{\sin th} \]
                                        4. Step-by-step derivation
                                          1. lower-sin.f643.4

                                            \[\leadsto \color{blue}{\sin th} \]
                                        5. Applied rewrites3.4%

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

                                          \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites3.2%

                                            \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                          2. Taylor expanded in th around inf

                                            \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites10.9%

                                              \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                            2. Step-by-step derivation
                                              1. Applied rewrites10.9%

                                                \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]

                                              if 6.00000000000000038e-60 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                              1. Initial program 98.6%

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6459.3

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites59.3%

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

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 6 \cdot 10^{-60}:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 24: 51.5% accurate, 1.0× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.15:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin ky) -0.15)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (sin ky) (* (fma -0.16666666666666666 (* kx kx) 1.0) kx)))
                                                (* (fma (* th th) -0.16666666666666666 1.0) th))
                                               (if (<= (sin ky) 2e-147)
                                                 (* (/ (sin th) (sin kx)) (sin ky))
                                                 (if (<= (sin ky) 0.0005)
                                                   (*
                                                    (/
                                                     (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                                                     (sqrt
                                                      (+
                                                       (- 0.5 (* (cos (* 2.0 kx)) 0.5))
                                                       (*
                                                        (fma
                                                         (-
                                                          (*
                                                           (*
                                                            (fma (* ky ky) -0.0031746031746031746 0.044444444444444446)
                                                            ky)
                                                           ky)
                                                          0.3333333333333333)
                                                         (* ky ky)
                                                         1.0)
                                                        (* ky ky)))))
                                                    (sin th))
                                                   (sin th)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(ky) <= -0.15) {
                                            		tmp = (sin(ky) / hypot(sin(ky), (fma(-0.16666666666666666, (kx * kx), 1.0) * kx))) * (fma((th * th), -0.16666666666666666, 1.0) * th);
                                            	} else if (sin(ky) <= 2e-147) {
                                            		tmp = (sin(th) / sin(kx)) * sin(ky);
                                            	} else if (sin(ky) <= 0.0005) {
                                            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (fma((((fma((ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), (ky * ky), 1.0) * (ky * ky))))) * sin(th);
                                            	} else {
                                            		tmp = sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(ky) <= -0.15)
                                            		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), Float64(fma(-0.16666666666666666, Float64(kx * kx), 1.0) * kx))) * Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th));
                                            	elseif (sin(ky) <= 2e-147)
                                            		tmp = Float64(Float64(sin(th) / sin(kx)) * sin(ky));
                                            	elseif (sin(ky) <= 0.0005)
                                            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * kx)) * 0.5)) + Float64(fma(Float64(Float64(Float64(fma(Float64(ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), Float64(ky * ky), 1.0) * Float64(ky * ky))))) * sin(th));
                                            	else
                                            		tmp = sin(th);
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.15], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[(N[(-0.16666666666666666 * N[(kx * kx), $MachinePrecision] + 1.0), $MachinePrecision] * kx), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-147], N[(N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0005], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.0031746031746031746 + 0.044444444444444446), $MachinePrecision] * ky), $MachinePrecision] * ky), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin ky \leq -0.15:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\
                                            
                                            \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-147}:\\
                                            \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\
                                            
                                            \mathbf{elif}\;\sin ky \leq 0.0005:\\
                                            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 4 regimes
                                            2. if (sin.f64 ky) < -0.149999999999999994

                                              1. Initial program 99.6%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th\right)} \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \cdot th\right) \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\left(\color{blue}{{th}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot th\right) \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\color{blue}{\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right)} \cdot th\right) \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(\mathsf{fma}\left(\color{blue}{th \cdot th}, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                                7. lower-*.f6454.1

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx \cdot \left(1 + \frac{-1}{6} \cdot {kx}^{2}\right)}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                              9. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(1 + \frac{-1}{6} \cdot {kx}^{2}\right) \cdot kx}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(1 + \frac{-1}{6} \cdot {kx}^{2}\right) \cdot kx}\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\left(\frac{-1}{6} \cdot {kx}^{2} + 1\right)} \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                                4. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {kx}^{2}, 1\right)} \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
                                                5. unpow2N/A

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

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, \color{blue}{kx \cdot kx}, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]
                                              10. Applied rewrites27.4%

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

                                              if -0.149999999999999994 < (sin.f64 ky) < 1.9999999999999999e-147

                                              1. Initial program 90.1%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6490.1

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\sin kx}} \cdot \sin ky \]
                                              6. Step-by-step derivation
                                                1. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sin kx}} \cdot \sin ky \]
                                                2. lower-sin.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\sin th}}{\sin kx} \cdot \sin ky \]
                                                3. lower-sin.f6444.4

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

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

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                                2. lower-*.f6499.2

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                                                2. pow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                                                4. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                5. sqr-sin-aN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                6. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                7. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                8. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                9. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                10. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                11. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                12. lower-*.f6493.7

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                                              8. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{{ky}^{2} \cdot \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right)}}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                              10. Applied rewrites94.1%

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}}} \cdot \sin th \]
                                              11. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              12. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                7. lower-*.f6494.1

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              13. Applied rewrites94.1%

                                                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6457.0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites57.0%

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

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.15:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \mathsf{fma}\left(-0.16666666666666666, kx \cdot kx, 1\right) \cdot kx\right)} \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 25: 76.3% accurate, 1.1× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{{\left(\frac{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}{2}\right)}^{-1}} \cdot \sin ky\right) \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (*
                                                 (sqrt
                                                  (pow
                                                   (/ (+ (- 1.0 (cos (* 2.0 kx))) (- 1.0 (cos (* -2.0 ky)))) 2.0)
                                                   -1.0))
                                                 (sin ky))
                                                (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = (sqrt(pow((((1.0 - cos((2.0 * kx))) + (1.0 - cos((-2.0 * ky)))) / 2.0), -1.0)) * sin(ky)) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(sqrt((Float64(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) + Float64(1.0 - cos(Float64(-2.0 * ky)))) / 2.0) ^ -1.0)) * sin(ky)) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[Power[N[(N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(\sqrt{{\left(\frac{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}{2}\right)}^{-1}} \cdot \sin ky\right) \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

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

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

                                                  \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

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

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

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

                                                  \[\leadsto \left(\sqrt{\frac{1}{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
                                                6. lower-fma.f64N/A

                                                  \[\leadsto \left(\sqrt{\frac{1}{\color{blue}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}}} \cdot \sin ky\right) \cdot \sin th \]
                                                7. lower-sin.f64N/A

                                                  \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(\color{blue}{\sin kx}, \sin kx, {\sin ky}^{2}\right)}} \cdot \sin ky\right) \cdot \sin th \]
                                                8. lower-sin.f64N/A

                                                  \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \color{blue}{\sin kx}, {\sin ky}^{2}\right)}} \cdot \sin ky\right) \cdot \sin th \]
                                                9. lower-pow.f64N/A

                                                  \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, \color{blue}{{\sin ky}^{2}}\right)}} \cdot \sin ky\right) \cdot \sin th \]
                                                10. lower-sin.f64N/A

                                                  \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\color{blue}{\sin ky}}^{2}\right)}} \cdot \sin ky\right) \cdot \sin th \]
                                                11. lower-sin.f6499.6

                                                  \[\leadsto \left(\sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}} \cdot \color{blue}{\sin ky}\right) \cdot \sin th \]
                                              5. Applied rewrites99.6%

                                                \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\mathsf{fma}\left(\sin kx, \sin kx, {\sin ky}^{2}\right)}} \cdot \sin ky\right)} \cdot \sin th \]
                                              6. Applied rewrites99.2%

                                                \[\leadsto \left(\sqrt{\frac{1}{\frac{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}{2}}} \cdot \sin ky\right) \cdot \sin th \]
                                            3. Recombined 2 regimes into one program.
                                            4. Final simplification76.1%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{{\left(\frac{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}{2}\right)}^{-1}} \cdot \sin ky\right) \cdot \sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 26: 46.9% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin ky) 2e-147)
                                               (* (/ (sin th) (sin kx)) (sin ky))
                                               (if (<= (sin ky) 0.0005)
                                                 (*
                                                  (/
                                                   (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                                                   (sqrt
                                                    (+
                                                     (- 0.5 (* (cos (* 2.0 kx)) 0.5))
                                                     (*
                                                      (fma
                                                       (-
                                                        (*
                                                         (* (fma (* ky ky) -0.0031746031746031746 0.044444444444444446) ky)
                                                         ky)
                                                        0.3333333333333333)
                                                       (* ky ky)
                                                       1.0)
                                                      (* ky ky)))))
                                                  (sin th))
                                                 (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(ky) <= 2e-147) {
                                            		tmp = (sin(th) / sin(kx)) * sin(ky);
                                            	} else if (sin(ky) <= 0.0005) {
                                            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (fma((((fma((ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), (ky * ky), 1.0) * (ky * ky))))) * sin(th);
                                            	} else {
                                            		tmp = sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(ky) <= 2e-147)
                                            		tmp = Float64(Float64(sin(th) / sin(kx)) * sin(ky));
                                            	elseif (sin(ky) <= 0.0005)
                                            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * kx)) * 0.5)) + Float64(fma(Float64(Float64(Float64(fma(Float64(ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), Float64(ky * ky), 1.0) * Float64(ky * ky))))) * sin(th));
                                            	else
                                            		tmp = sin(th);
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-147], N[(N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0005], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.0031746031746031746 + 0.044444444444444446), $MachinePrecision] * ky), $MachinePrecision] * ky), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\
                                            \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\
                                            
                                            \mathbf{elif}\;\sin ky \leq 0.0005:\\
                                            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 ky) < 1.9999999999999999e-147

                                              1. Initial program 93.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6493.4

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\sin kx}} \cdot \sin ky \]
                                              6. Step-by-step derivation
                                                1. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sin kx}} \cdot \sin ky \]
                                                2. lower-sin.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\sin th}}{\sin kx} \cdot \sin ky \]
                                                3. lower-sin.f6431.3

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

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

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                                2. lower-*.f6499.2

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                                                2. pow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                                                4. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                5. sqr-sin-aN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                6. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                7. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                8. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                9. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                10. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                11. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                12. lower-*.f6493.7

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                                              8. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{{ky}^{2} \cdot \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right)}}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                              10. Applied rewrites94.1%

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}}} \cdot \sin th \]
                                              11. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              12. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                7. lower-*.f6494.1

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              13. Applied rewrites94.1%

                                                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6457.0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites57.0%

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

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sin th}{\sin kx} \cdot \sin ky\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 27: 45.7% accurate, 1.2× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= (sin ky) 2e-147)
                                               (* (/ ky (sin kx)) (sin th))
                                               (if (<= (sin ky) 0.0005)
                                                 (*
                                                  (/
                                                   (* (fma (* ky ky) -0.16666666666666666 1.0) ky)
                                                   (sqrt
                                                    (+
                                                     (- 0.5 (* (cos (* 2.0 kx)) 0.5))
                                                     (*
                                                      (fma
                                                       (-
                                                        (*
                                                         (* (fma (* ky ky) -0.0031746031746031746 0.044444444444444446) ky)
                                                         ky)
                                                        0.3333333333333333)
                                                       (* ky ky)
                                                       1.0)
                                                      (* ky ky)))))
                                                  (sin th))
                                                 (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (sin(ky) <= 2e-147) {
                                            		tmp = (ky / sin(kx)) * sin(th);
                                            	} else if (sin(ky) <= 0.0005) {
                                            		tmp = ((fma((ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (fma((((fma((ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), (ky * ky), 1.0) * (ky * ky))))) * sin(th);
                                            	} else {
                                            		tmp = sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (sin(ky) <= 2e-147)
                                            		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                                            	elseif (sin(ky) <= 0.0005)
                                            		tmp = Float64(Float64(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * kx)) * 0.5)) + Float64(fma(Float64(Float64(Float64(fma(Float64(ky * ky), -0.0031746031746031746, 0.044444444444444446) * ky) * ky) - 0.3333333333333333), Float64(ky * ky), 1.0) * Float64(ky * ky))))) * sin(th));
                                            	else
                                            		tmp = sin(th);
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-147], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.0005], N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.0031746031746031746 + 0.044444444444444446), $MachinePrecision] * ky), $MachinePrecision] * ky), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\
                                            \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                                            
                                            \mathbf{elif}\;\sin ky \leq 0.0005:\\
                                            \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if (sin.f64 ky) < 1.9999999999999999e-147

                                              1. Initial program 93.5%

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

                                                \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                                2. lower-sin.f6429.3

                                                  \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                              5. Applied rewrites29.3%

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

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                                2. lower-*.f6499.2

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                                                2. pow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                                                4. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                5. sqr-sin-aN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                6. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                7. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                8. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                9. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                10. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                11. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                12. lower-*.f6493.7

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                                              8. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{{ky}^{2} \cdot \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right)}}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \color{blue}{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot {ky}^{2}}}} \cdot \sin th \]
                                              10. Applied rewrites94.1%

                                                \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}}} \cdot \sin th \]
                                              11. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              12. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \cos \left(2 \cdot kx\right) \cdot \frac{1}{2}\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot ky\right) \cdot ky - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                7. lower-*.f6494.1

                                                  \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                              13. Applied rewrites94.1%

                                                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]

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

                                              1. Initial program 99.7%

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6457.0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites57.0%

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

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-147}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 0.0005:\\ \;\;\;\;\frac{\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + \mathsf{fma}\left(\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot ky\right) \cdot ky - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 28: 76.3% accurate, 1.3× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (/
                                                 (sin ky)
                                                 (/
                                                  (sqrt
                                                   (fma (- 1.0 (cos (* 2.0 ky))) 2.0 (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
                                                  2.0))
                                                (sin th))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0)) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                                                8. lower-hypot.f6499.7

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

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                                              5. Step-by-step derivation
                                                1. lift-hypot.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin th \]
                                                2. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                4. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                5. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin th \]
                                                6. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin th \]
                                                7. sin-multN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin th \]
                                                8. frac-addN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \sin th \]
                                                9. metadata-evalN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \sin th \]
                                                10. metadata-evalN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \sin th \]
                                                11. sqrt-divN/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \cdot \sin th \]
                                                12. metadata-evalN/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \cdot \sin th \]
                                                13. metadata-evalN/A

                                                  \[\leadsto \frac{\sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\color{blue}{2}}} \cdot \sin th \]
                                                14. lower-/.f64N/A

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

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 29: 76.2% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sin ky\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (/
                                                 (* (sin th) (sqrt 2.0))
                                                 (sqrt (+ (- 1.0 (cos (* 2.0 kx))) (- 1.0 (cos (* -2.0 ky))))))
                                                (sin ky))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = ((sin(th) * sqrt(2.0)) / sqrt(((1.0 - cos((2.0 * kx))) + (1.0 - cos((-2.0 * ky)))))) * sin(ky);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(Float64(sin(th) * sqrt(2.0)) / sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) + Float64(1.0 - cos(Float64(-2.0 * ky)))))) * sin(ky));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[th], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sin ky\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6499.6

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                                              5. Step-by-step derivation
                                                1. lift-hypot.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                                                2. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                4. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                5. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                                                6. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                                                7. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                                                8. div-add-revN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                                                9. sqrt-divN/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                10. lower-/.f64N/A

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

                                                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                              7. Step-by-step derivation
                                                1. lift-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                2. lift-/.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                3. associate-/r/N/A

                                                  \[\leadsto \color{blue}{\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}} \cdot \sqrt{2}\right)} \cdot \sin ky \]
                                                4. associate-*l/N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}} \cdot \sin ky \]
                                                5. lower-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}} \cdot \sin ky \]
                                                6. lower-*.f6499.0

                                                  \[\leadsto \frac{\color{blue}{\sin th \cdot \sqrt{2}}}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}} \cdot \sin ky \]
                                                7. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\color{blue}{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}} \cdot \sin ky \]
                                                8. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\color{blue}{\left(1 - \cos \left(-2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin ky \]
                                                9. lower-+.f6499.0

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\color{blue}{\left(1 - \cos \left(-2 \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin ky \]
                                                10. lift-cos.f64N/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \color{blue}{\cos \left(-2 \cdot kx\right)}\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                11. cos-neg-revN/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \color{blue}{\cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                12. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \color{blue}{\cos \left(\mathsf{neg}\left(-2 \cdot kx\right)\right)}\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                13. lift-*.f64N/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(\mathsf{neg}\left(\color{blue}{-2 \cdot kx}\right)\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                14. distribute-lft-neg-inN/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \color{blue}{\left(\left(\mathsf{neg}\left(-2\right)\right) \cdot kx\right)}\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                15. metadata-evalN/A

                                                  \[\leadsto \frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(\color{blue}{2} \cdot kx\right)\right) + \left(1 - \cos \left(2 \cdot ky\right)\right)}} \cdot \sin ky \]
                                                16. lift-*.f6499.0

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

                                                \[\leadsto \color{blue}{\frac{\sin th \cdot \sqrt{2}}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}}} \cdot \sin ky \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 30: 76.2% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot \sin ky}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (/
                                                 (* (sin th) (sin ky))
                                                 (sqrt (+ (- 1.0 (cos (* 2.0 kx))) (- 1.0 (cos (* -2.0 ky))))))
                                                (sqrt 2.0))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = ((sin(th) * sin(ky)) / sqrt(((1.0 - cos((2.0 * kx))) + (1.0 - cos((-2.0 * ky)))))) * sqrt(2.0);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(Float64(sin(th) * sin(ky)) / sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) + Float64(1.0 - cos(Float64(-2.0 * ky)))))) * sqrt(2.0));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[th], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin th \cdot \sin ky}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6499.6

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                                              5. Step-by-step derivation
                                                1. lift-hypot.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                                                2. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                4. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                5. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                                                6. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                                                7. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                                                8. div-add-revN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                                                9. sqrt-divN/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                10. lower-/.f64N/A

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

                                                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                              7. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}} \cdot \sin ky} \]
                                                2. lift-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                3. associate-*l/N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \]
                                                4. lift-/.f64N/A

                                                  \[\leadsto \frac{\sin th \cdot \sin ky}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \]
                                                5. associate-/r/N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}} \cdot \sqrt{2}} \]
                                                6. lower-*.f64N/A

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

                                                \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}} \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 31: 76.2% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}\right) \cdot \sin ky\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (*
                                                 (/ (sin th) (sqrt (+ (- 1.0 (cos (* 2.0 kx))) (- 1.0 (cos (* -2.0 ky))))))
                                                 (sqrt 2.0))
                                                (sin ky))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = ((sin(th) / sqrt(((1.0 - cos((2.0 * kx))) + (1.0 - cos((-2.0 * ky)))))) * sqrt(2.0)) * sin(ky);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(Float64(sin(th) / sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) + Float64(1.0 - cos(Float64(-2.0 * ky)))))) * sqrt(2.0)) * sin(ky));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}\right) \cdot \sin ky\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6499.6

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                                              5. Step-by-step derivation
                                                1. lift-hypot.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                                                2. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                4. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                5. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                                                6. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                                                7. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                                                8. div-add-revN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                                                9. sqrt-divN/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                10. lower-/.f64N/A

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

                                                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                              7. Step-by-step derivation
                                                1. lift-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                2. lift-/.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                3. associate-/r/N/A

                                                  \[\leadsto \color{blue}{\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}} \cdot \sqrt{2}\right)} \cdot \sin ky \]
                                                4. lower-*.f64N/A

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

                                                \[\leadsto \color{blue}{\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}} \cdot \sqrt{2}\right)} \cdot \sin ky \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 32: 76.2% accurate, 1.4× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00245:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\sin ky \cdot \frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}}\right) \cdot \sqrt{2}\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= ky 0.00245)
                                               (*
                                                (/
                                                 (sin ky)
                                                 (hypot (* (fma (* ky ky) -0.16666666666666666 1.0) ky) (sin kx)))
                                                (sin th))
                                               (*
                                                (*
                                                 (sin ky)
                                                 (/
                                                  (sin th)
                                                  (sqrt (+ (- 1.0 (cos (* 2.0 kx))) (- 1.0 (cos (* -2.0 ky)))))))
                                                (sqrt 2.0))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (ky <= 0.00245) {
                                            		tmp = (sin(ky) / hypot((fma((ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th);
                                            	} else {
                                            		tmp = (sin(ky) * (sin(th) / sqrt(((1.0 - cos((2.0 * kx))) + (1.0 - cos((-2.0 * ky))))))) * sqrt(2.0);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (ky <= 0.00245)
                                            		tmp = Float64(Float64(sin(ky) / hypot(Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky), sin(kx))) * sin(th));
                                            	else
                                            		tmp = Float64(Float64(sin(ky) * Float64(sin(th) / sqrt(Float64(Float64(1.0 - cos(Float64(2.0 * kx))) + Float64(1.0 - cos(Float64(-2.0 * ky))))))) * sqrt(2.0));
                                            	end
                                            	return tmp
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[ky, 0.00245], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(1.0 - N[Cos[N[(-2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;ky \leq 0.00245:\\
                                            \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\left(\sin ky \cdot \frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}}\right) \cdot \sqrt{2}\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if ky < 0.0024499999999999999

                                              1. Initial program 94.5%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                2. lift-+.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                4. lift-pow.f64N/A

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                6. lift-pow.f64N/A

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

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

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

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

                                                \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}, \sin kx\right)} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right) \cdot ky}, \sin kx\right)} \cdot \sin th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\left(\color{blue}{{ky}^{2} \cdot \frac{-1}{6}} + 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{-1}{6}, 1\right)} \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                6. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{-1}{6}, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                                7. lower-*.f6467.9

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\mathsf{fma}\left(\color{blue}{ky \cdot ky}, -0.16666666666666666, 1\right) \cdot ky, \sin kx\right)} \cdot \sin th \]
                                              7. Applied rewrites67.9%

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

                                              if 0.0024499999999999999 < ky

                                              1. Initial program 99.8%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                                                5. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                6. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky} \]
                                                7. lower-/.f6499.6

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                8. lift-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                9. lift-+.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin ky \]
                                                10. +-commutativeN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin ky \]
                                                11. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{{\sin ky}^{2}} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                12. unpow2N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin ky \]
                                                13. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{{\sin kx}^{2}}}} \cdot \sin ky \]
                                                14. unpow2N/A

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

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

                                                \[\leadsto \color{blue}{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin ky} \]
                                              5. Step-by-step derivation
                                                1. lift-hypot.f64N/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \cdot \sin ky \]
                                                2. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\sin ky} \cdot \sin ky + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \color{blue}{\sin ky} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                4. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + \sin kx \cdot \sin kx}} \cdot \sin ky \]
                                                5. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\sin kx} \cdot \sin kx}} \cdot \sin ky \]
                                                6. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin ky \]
                                                7. sin-multN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin ky \]
                                                8. div-add-revN/A

                                                  \[\leadsto \frac{\sin th}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2}}}} \cdot \sin ky \]
                                                9. sqrt-divN/A

                                                  \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) + \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                                10. lower-/.f64N/A

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

                                                \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \cdot \sin ky \]
                                              7. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}} \cdot \sin ky} \]
                                                2. *-commutativeN/A

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \]
                                                3. lift-/.f64N/A

                                                  \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \]
                                                4. lift-/.f64N/A

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\frac{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}{\sqrt{2}}}} \]
                                                5. associate-/r/N/A

                                                  \[\leadsto \sin ky \cdot \color{blue}{\left(\frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}} \cdot \sqrt{2}\right)} \]
                                                6. associate-*r*N/A

                                                  \[\leadsto \color{blue}{\left(\sin ky \cdot \frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot ky\right)\right) + \left(1 - \cos \left(-2 \cdot kx\right)\right)}}\right) \cdot \sqrt{2}} \]
                                                7. lower-*.f64N/A

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

                                                \[\leadsto \color{blue}{\left(\sin ky \cdot \frac{\sin th}{\sqrt{\left(1 - \cos \left(2 \cdot kx\right)\right) + \left(1 - \cos \left(-2 \cdot ky\right)\right)}}\right) \cdot \sqrt{2}} \]
                                            3. Recombined 2 regimes into one program.
                                            4. Add Preprocessing

                                            Alternative 33: 39.1% accurate, 1.8× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 7 \cdot 10^{-146}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{ky \cdot ky + kx \cdot kx}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<= kx 7e-146)
                                               (sin th)
                                               (if (<= kx 2e-5)
                                                 (* (sin ky) (/ (sin th) (sqrt (+ (* ky ky) (* kx kx)))))
                                                 (* (/ (sin ky) (sqrt (- 0.5 (* (cos (* -2.0 kx)) 0.5)))) (sin th)))))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (kx <= 7e-146) {
                                            		tmp = sin(th);
                                            	} else if (kx <= 2e-5) {
                                            		tmp = sin(ky) * (sin(th) / sqrt(((ky * ky) + (kx * kx))));
                                            	} else {
                                            		tmp = (sin(ky) / sqrt((0.5 - (cos((-2.0 * kx)) * 0.5)))) * 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 (kx <= 7d-146) then
                                                    tmp = sin(th)
                                                else if (kx <= 2d-5) then
                                                    tmp = sin(ky) * (sin(th) / sqrt(((ky * ky) + (kx * kx))))
                                                else
                                                    tmp = (sin(ky) / sqrt((0.5d0 - (cos(((-2.0d0) * kx)) * 0.5d0)))) * sin(th)
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (kx <= 7e-146) {
                                            		tmp = Math.sin(th);
                                            	} else if (kx <= 2e-5) {
                                            		tmp = Math.sin(ky) * (Math.sin(th) / Math.sqrt(((ky * ky) + (kx * kx))));
                                            	} else {
                                            		tmp = (Math.sin(ky) / Math.sqrt((0.5 - (Math.cos((-2.0 * kx)) * 0.5)))) * Math.sin(th);
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(kx, ky, th):
                                            	tmp = 0
                                            	if kx <= 7e-146:
                                            		tmp = math.sin(th)
                                            	elif kx <= 2e-5:
                                            		tmp = math.sin(ky) * (math.sin(th) / math.sqrt(((ky * ky) + (kx * kx))))
                                            	else:
                                            		tmp = (math.sin(ky) / math.sqrt((0.5 - (math.cos((-2.0 * kx)) * 0.5)))) * math.sin(th)
                                            	return tmp
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (kx <= 7e-146)
                                            		tmp = sin(th);
                                            	elseif (kx <= 2e-5)
                                            		tmp = Float64(sin(ky) * Float64(sin(th) / sqrt(Float64(Float64(ky * ky) + Float64(kx * kx)))));
                                            	else
                                            		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(cos(Float64(-2.0 * kx)) * 0.5)))) * sin(th));
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(kx, ky, th)
                                            	tmp = 0.0;
                                            	if (kx <= 7e-146)
                                            		tmp = sin(th);
                                            	elseif (kx <= 2e-5)
                                            		tmp = sin(ky) * (sin(th) / sqrt(((ky * ky) + (kx * kx))));
                                            	else
                                            		tmp = (sin(ky) / sqrt((0.5 - (cos((-2.0 * kx)) * 0.5)))) * sin(th);
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[kx, 7e-146], N[Sin[th], $MachinePrecision], If[LessEqual[kx, 2e-5], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(N[(ky * ky), $MachinePrecision] + N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[Cos[N[(-2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;kx \leq 7 \cdot 10^{-146}:\\
                                            \;\;\;\;\sin th\\
                                            
                                            \mathbf{elif}\;kx \leq 2 \cdot 10^{-5}:\\
                                            \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{ky \cdot ky + kx \cdot kx}}\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 3 regimes
                                            2. if kx < 7.0000000000000003e-146

                                              1. Initial program 93.6%

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

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lower-sin.f6426.1

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              5. Applied rewrites26.1%

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

                                              if 7.0000000000000003e-146 < kx < 2.00000000000000016e-5

                                              1. Initial program 99.8%

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                                2. lower-*.f6451.8

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                              6. Taylor expanded in kx around 0

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                                              7. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
                                                2. lower-*.f6451.8

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + ky \cdot ky}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. lift-*.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}} \cdot \sin th} \]
                                                2. lift-/.f64N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{kx \cdot kx + ky \cdot ky}}} \cdot \sin th \]
                                                3. associate-*l/N/A

                                                  \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{kx \cdot kx + ky \cdot ky}}} \]
                                                4. associate-/l*N/A

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{kx \cdot kx + ky \cdot ky}}} \]
                                                5. lower-*.f64N/A

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{kx \cdot kx + ky \cdot ky}}} \]
                                                6. lower-/.f6451.8

                                                  \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sqrt{kx \cdot kx + ky \cdot ky}}} \]
                                                7. lift-+.f64N/A

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{kx \cdot kx + ky \cdot ky}}} \]
                                                8. +-commutativeN/A

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{ky \cdot ky + kx \cdot kx}}} \]
                                                9. lower-+.f6451.8

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{ky \cdot ky + kx \cdot kx}}} \]
                                              10. Applied rewrites51.8%

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

                                              if 2.00000000000000016e-5 < kx

                                              1. Initial program 99.6%

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                              4. Step-by-step derivation
                                                1. unpow2N/A

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

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot ky}}} \cdot \sin th \]
                                              6. Step-by-step derivation
                                                1. lift-pow.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + ky \cdot ky}} \cdot \sin th \]
                                                2. pow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                3. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx} \cdot \sin kx + ky \cdot ky}} \cdot \sin th \]
                                                4. lift-sin.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
                                                5. sqr-sin-aN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                6. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + ky \cdot ky}} \cdot \sin th \]
                                                7. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                8. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}\right) + ky \cdot ky}} \cdot \sin th \]
                                                9. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                10. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                11. count-2-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \cos \color{blue}{\left(2 \cdot kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
                                                12. lower-*.f6449.3

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

                                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right)} + ky \cdot ky}} \cdot \sin th \]
                                              8. Taylor expanded in ky around 0

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                              9. Step-by-step derivation
                                                1. lower-sqrt.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                                2. lower--.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                                3. *-commutativeN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \sin th \]
                                                4. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(2 \cdot kx\right) \cdot \frac{1}{2}}}} \cdot \sin th \]
                                                5. cos-neg-revN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                                6. lower-cos.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\cos \left(\mathsf{neg}\left(2 \cdot kx\right)\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                                7. distribute-lft-neg-inN/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                                8. lower-*.f64N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \cos \color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot kx\right)} \cdot \frac{1}{2}}} \cdot \sin th \]
                                                9. metadata-eval56.2

                                                  \[\leadsto \frac{\sin ky}{\sqrt{0.5 - \cos \left(\color{blue}{-2} \cdot kx\right) \cdot 0.5}} \cdot \sin th \]
                                              10. Applied rewrites56.2%

                                                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}}} \cdot \sin th \]
                                            3. Recombined 3 regimes into one program.
                                            4. Final simplification37.0%

                                              \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 7 \cdot 10^{-146}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;kx \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sqrt{ky \cdot ky + kx \cdot kx}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(-2 \cdot kx\right) \cdot 0.5}} \cdot \sin th\\ \end{array} \]
                                            5. Add Preprocessing

                                            Alternative 34: 10.9% accurate, 39.5× speedup?

                                            \[\begin{array}{l} \\ \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (* (* (* -0.16666666666666666 th) th) th))
                                            double code(double kx, double ky, double th) {
                                            	return ((-0.16666666666666666 * th) * th) * th;
                                            }
                                            
                                            real(8) function code(kx, ky, th)
                                                real(8), intent (in) :: kx
                                                real(8), intent (in) :: ky
                                                real(8), intent (in) :: th
                                                code = (((-0.16666666666666666d0) * th) * th) * th
                                            end function
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	return ((-0.16666666666666666 * th) * th) * th;
                                            }
                                            
                                            def code(kx, ky, th):
                                            	return ((-0.16666666666666666 * th) * th) * th
                                            
                                            function code(kx, ky, th)
                                            	return Float64(Float64(Float64(-0.16666666666666666 * th) * th) * th)
                                            end
                                            
                                            function tmp = code(kx, ky, th)
                                            	tmp = ((-0.16666666666666666 * th) * th) * th;
                                            end
                                            
                                            code[kx_, ky_, th_] := N[(N[(N[(-0.16666666666666666 * th), $MachinePrecision] * th), $MachinePrecision] * th), $MachinePrecision]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th
                                            \end{array}
                                            
                                            Derivation
                                            1. Initial program 95.9%

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

                                              \[\leadsto \color{blue}{\sin th} \]
                                            4. Step-by-step derivation
                                              1. lower-sin.f6422.4

                                                \[\leadsto \color{blue}{\sin th} \]
                                            5. Applied rewrites22.4%

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

                                              \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites12.7%

                                                \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                              2. Taylor expanded in th around inf

                                                \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites8.4%

                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites8.4%

                                                    \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]
                                                  2. Final simplification8.4%

                                                    \[\leadsto \left(\left(-0.16666666666666666 \cdot th\right) \cdot th\right) \cdot th \]
                                                  3. Add Preprocessing

                                                  Reproduce

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